UNPKG

tonb-merchant-api-client

Version:

Merchant API client is a library to interact with TONB Merchant API.

90 lines (89 loc) 3.75 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const invoice_1 = require("../models/invoice"); const invoice_manager_1 = require("./invoice-manager"); const providerMock = { createInvoice: jest.fn(), cancelInvoice: jest.fn(), getInvoiceInfo: jest.fn(), getInvoiceStats: jest.fn(), isUpdateValid: jest.fn(), }; describe('InvoiceManager', () => { let invoiceManager; beforeEach(() => { invoiceManager = new invoice_manager_1.InvoiceManager(providerMock); }); afterEach(() => { jest.clearAllMocks(); }); it('should call createInvoice method on provider', () => __awaiter(void 0, void 0, void 0, function* () { const createInvoiceData = { order_id: 1, amount: 1, }; const expectedInvoice = { data: { id: 1, order_id: BigInt(1), amount: BigInt(1), }, isValid: true, }; providerMock.createInvoice.mockResolvedValue(expectedInvoice); const invoice = yield invoiceManager.create(createInvoiceData); expect(providerMock.createInvoice).toHaveBeenCalledWith(createInvoiceData); expect(invoice).toBe(expectedInvoice); })); it('should call cancelInvoice method on provider', () => __awaiter(void 0, void 0, void 0, function* () { const invoiceId = 1; const expectedInvoice = { data: { id: 1, order_id: BigInt(1), amount: BigInt(1), status: invoice_1.InvoiceEnumStatus.canceled, }, isValid: true, }; providerMock.cancelInvoice.mockResolvedValue(expectedInvoice); const invoice = yield invoiceManager.cancel(invoiceId); expect(providerMock.cancelInvoice).toHaveBeenCalledWith(invoiceId); expect(invoice).toBe(expectedInvoice); })); it('should call getInvoiceInfo method on provider', () => __awaiter(void 0, void 0, void 0, function* () { const invoiceId = 1; const expectedInvoice = { data: { id: 1, order_id: BigInt(1), amount: BigInt(1), status: invoice_1.InvoiceEnumStatus.created, }, isValid: true, }; providerMock.getInvoiceInfo.mockResolvedValue(expectedInvoice); const invoice = yield invoiceManager.info(invoiceId); expect(providerMock.getInvoiceInfo).toHaveBeenCalledWith(invoiceId); expect(invoice).toBe(expectedInvoice); })); it('should call getInvoiceStats method on provider', () => __awaiter(void 0, void 0, void 0, function* () { const expectedStats = { count: 1, invoice_sum: 10, }; providerMock.getInvoiceStats.mockResolvedValue(expectedStats); const stats = yield invoiceManager.stats(); expect(providerMock.getInvoiceStats).toHaveBeenCalled(); expect(stats).toBe(expectedStats); })); });