@eleva-io/erp-sdk
Version:
SDK oficial para el ERP de Eleva
75 lines • 3.21 kB
JavaScript
import { GlobalBankAccountType } from '../bank-account';
import { GlobalCurrency } from '../types';
import { ElevaError, ERROR_CODES } from '../../../errors';
import { validatePaymentMethod } from './payment_method';
describe('validatePaymentMethod', () => {
const aba = {
type: GlobalBankAccountType.ABA,
currency: GlobalCurrency.USD,
country: 'US',
accountNumber: '1234567890',
routingNumber: '021000021',
swiftBic: 'CHASUS33',
};
const clabe = {
type: GlobalBankAccountType.CLABE,
currency: GlobalCurrency.MXN,
country: 'MX',
accountNumber: '002010077777777771',
swiftBic: 'BCMRMXMM',
};
const iban = {
type: GlobalBankAccountType.IBAN,
currency: GlobalCurrency.EUR,
country: 'ES',
accountNumber: 'ES9121000418450200051332',
swiftBic: 'CAIXESBBXXX',
};
const expectValidationError = async (payload) => {
const error = await validatePaymentMethod(payload).catch((e) => e);
expect(error).toBeInstanceOf(ElevaError);
expect(error.code).toBe(ERROR_CODES.VALIDATION);
};
describe('ABA', () => {
it('resolves for a valid payload', async () => {
await expect(validatePaymentMethod(aba)).resolves.toBeUndefined();
});
// eslint-disable-next-line jest/expect-expect
it.each([
['missing routing number', { routingNumber: undefined }],
['invalid account number', { accountNumber: '12345678X' }],
['invalid routing number', { routingNumber: '111111111' }],
['invalid swift bic', { swiftBic: 'CHASUS123' }],
['swift bic from a different country', { swiftBic: 'BCMRMXMM' }],
])('rejects when %s', async (_label, overrides) => {
await expectValidationError({ ...aba, ...overrides });
});
});
describe('CLABE', () => {
it('resolves for a valid payload', async () => {
await expect(validatePaymentMethod(clabe)).resolves.toBeUndefined();
});
// eslint-disable-next-line jest/expect-expect
it.each([
['invalid account number', { accountNumber: '0020100777777777XX' }],
['invalid swift bic', { swiftBic: 'BCMRMXMM3423' }],
['swift bic from a different country', { swiftBic: 'CHASUS33' }],
])('rejects when %s', async (_label, overrides) => {
await expectValidationError({ ...clabe, ...overrides });
});
});
describe('IBAN', () => {
it('resolves for a valid payload', async () => {
await expect(validatePaymentMethod(iban)).resolves.toBeUndefined();
});
// eslint-disable-next-line jest/expect-expect
it.each([
['invalid account number', { accountNumber: 'EX9121000418450200051332' }],
['invalid swift bic', { swiftBic: 'CAIXESBBXXX123' }],
['swift bic from a different country', { swiftBic: 'CHASUS33' }],
])('rejects when %s', async (_label, overrides) => {
await expectValidationError({ ...iban, ...overrides });
});
});
});
//# sourceMappingURL=payment_method.spec.js.map