UNPKG

@nicotordev/flowcl-pagos

Version:

SDK en TypeScript para integrar pagos con la API de Flow.cl de manera sencilla y segura.

113 lines 4.98 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); require("dotenv/config"); const flow_customers_1 = __importDefault(require("../clients/flow.customers")); const flowIntegration_1 = require("../test-utils/flowIntegration"); const runAutomaticChargeTests = process.env.FLOW_RUN_CUSTOMER_AUTOMATIC_CHARGE_TESTS === 'true'; (0, flowIntegration_1.describeFlowIntegration)('FlowCustomers API Integration Tests', () => { let flowCustomers; let createdCustomer = null; let registeredCard = null; let lastCharge = null; beforeAll(() => { flowCustomers = new flow_customers_1.default(flowIntegration_1.flowIntegrationConfig.apiKey, flowIntegration_1.flowIntegrationConfig.secretKey, flowIntegration_1.flowIntegrationConfig.baseUrl); }); test('Debe crear un cliente en Flow', async () => { const requestData = { name: 'Nicolas Torres', email: 'nicotordev@gmail.com', externalId: new Date().getTime().toString(), }; const response = await flowCustomers.create(requestData); createdCustomer = response; console.log('Cliente Creado:', response); expect(response.customerId).toBeDefined(); }); test('Debe registrar una tarjeta para el cliente', async () => { if (!runAutomaticChargeTests) { expect(runAutomaticChargeTests).toBe(false); return; } if (!createdCustomer) throw new Error('Cliente no creado en test anterior'); const requestData = { customerId: createdCustomer.customerId, url_return: 'https://example.com/return', }; const response = await flowCustomers.card.register(requestData); registeredCard = response; console.log('Registro de Tarjeta:', response); expect(response.token).toBeDefined(); expect(response.redirectUrl).toContain('https://sandbox.flow.cl'); }); test('Debe verificar el estado del registro de tarjeta', async () => { if (!runAutomaticChargeTests) { expect(runAutomaticChargeTests).toBe(false); return; } if (!registeredCard) throw new Error('Tarjeta no registrada en test anterior'); const response = await flowCustomers.card.status(registeredCard.token); console.log('Estado de la Tarjeta:', response); expect(response.status).toBeDefined(); expect(response.customerId).toBe(createdCustomer.customerId); }); test('Debe eliminar una tarjeta registrada', async () => { if (!runAutomaticChargeTests) { expect(runAutomaticChargeTests).toBe(false); return; } if (!createdCustomer) throw new Error('Cliente no creado en test anterior'); const response = await flowCustomers.card.delete(createdCustomer.customerId); console.log('Tarjeta Eliminada:', response); expect(response.customerId).toBe(createdCustomer.customerId); }); test('Debe enviar un cobro a un cliente', async () => { if (!createdCustomer) throw new Error('Cliente no creado en test anterior'); const requestData = { customerId: createdCustomer.customerId, commerceOrder: 'ORDER-TEST-5678', subject: 'Cobro Test Real', amount: 7000, urlConfirmation: 'https://nicotordev.com/confirm', urlReturn: 'https://nicotordev.com/return', }; const response = await flowCustomers.card.sendCharge(requestData); lastCharge = response; console.log('Cobro Enviado:', response); expect(response.flowOrder).toBeDefined(); expect(response.status).toBe(1); }); test('Debe reversar un cobro', async () => { if (!runAutomaticChargeTests) { expect(runAutomaticChargeTests).toBe(false); return; } if (!lastCharge) throw new Error('No hay un cobro para reversar'); const requestData = { flowOrder: lastCharge.flowOrder, }; const response = await flowCustomers.card.reverseCharge(requestData); console.log('Cobro Reversado:', response); expect(response.status).toBeDefined(); }); test('Debe listar los cobros de un cliente', async () => { if (!createdCustomer) throw new Error('Cliente no creado en test anterior'); const requestData = { customerId: createdCustomer.customerId, start: 0, limit: 5, }; const response = await flowCustomers.card.listCharges(requestData); console.log('Lista de Cobros:', response); expect(response.total).toBeGreaterThanOrEqual(0); }); }); //# sourceMappingURL=flowCustomers.test.js.map