UNPKG

asaaas

Version:

Unofficial Asaas Payment Gateway SDK

44 lines (43 loc) 2.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // Preferência no import do index pra garantir que tudo relevante está sendo exportado const index_1 = require("../index"); const webhook_payment_json_1 = __importDefault(require("./fixtures/webhook_payment.json")); const invalid_webhook_json_1 = __importDefault(require("./fixtures/invalid_webhook.json")); jest.mock('axios'); describe('AsaasClient', () => { test('construtor deve inicializar corretamente em modo Sandbox', () => { const apiKey = 'my-api-key'; const options = { sandbox: true }; const client = new index_1.AsaasClient(apiKey, options); expect(client.customers).toBeDefined(); expect(client.payments).toBeDefined(); expect(client.installments).toBeDefined(); expect(client.subscriptions).toBeDefined(); expect(client.webhooks).toBeDefined(); expect(client.pixTransactions).toBeDefined(); expect(client.pixQrCodes).toBeDefined(); expect(client.invoices).toBeDefined(); expect(client.bill).toBeDefined(); expect(client.transfers).toBeDefined(); expect(client.myAccount).toBeDefined(); expect(client.accounts).toBeDefined(); }); }); describe('Webhooks', () => { test('parse de payment webhook', () => { const parsed = (0, index_1.parseWebhookPayload)({ ...webhook_payment_json_1.default }); expect(parsed).not.toBeNull(); // typescript infer no atributo payment expect(parsed && 'payment' in parsed ? parsed.payment.id : null).not.toBeNull(); // typescript infer no atributo invoice expect(parsed && 'invoice' in parsed ? parsed.invoice.id : null).toBeNull(); }); test('parse de webhook não mapeado deve retornar null', () => { const parsed = (0, index_1.parseWebhookPayload)({ ...invalid_webhook_json_1.default }); expect(parsed).toBeNull(); }); });