@vulog/aima-payment
Version:
Payment management module for the AIMA platform. This module provides functionality to handle payments, setup intents, payment methods, and trip payments.
254 lines (239 loc) • 11.3 kB
text/typescript
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
import { Client } from '@vulog/aima-client';
import { getPaymentMethodDetailsForUser } from './getPaymentMethodDetailsForUser';
import { randomUUID } from 'crypto';
describe('getPaymentMethodDetailsForUser', () => {
const userId = randomUUID();
const getMock = vi.fn();
const client = {
get: getMock,
clientOptions: {
fleetId: 'FLEET_ID',
},
} as unknown as Client;
beforeEach(() => {
getMock.mockReset();
vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
});
afterEach(() => {
vi.useRealTimers();
});
test('call OK visa', async () => {
const mockData = {
token: 'pm_1RqA47HGgb8lFOFDpTeFe16C',
holderName: 'John Doe',
fleetId: client.clientOptions.fleetId,
entityId: '2f16423b-2b75-4a6e-a82e-5087f98a4df8',
pspName: 'STRIPE',
customerPspReference: 'cus_ScgfSAgJ6rmaNo',
entityStatus: 'APPROVED',
profileId: '7ca3b51c-3ada-4fe0-8e36-0030940dfde1',
profileName: 'default',
profileType: 'Single',
paymentMethod: 'CREDIT_CARD',
mopStatus: 'MOP_VALID',
cardSummary: '0817',
cardType: 'visa',
cardFunding: 'credit',
expiryDate: 1856563200000,
expiryMonth: '10',
expiryYear: '2028',
paymentType: 'CARD',
};
getMock.mockResolvedValueOnce({ data: [
mockData,
]});
const result = await getPaymentMethodDetailsForUser(client, userId);
expect(getMock).toBeCalled();
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
expect(result).toBeTruthy();
expect(result?.token).toEqual(mockData.token);
expect(result?.holderName).toEqual(mockData.holderName);
expect(result?.fleetId).toEqual(mockData.fleetId);
expect(result?.entityId).toEqual(mockData.entityId);
expect(result?.pspName).toEqual(mockData.pspName);
expect(result?.customerPspReference).toEqual(mockData.customerPspReference);
expect(result?.entityStatus).toEqual(mockData.entityStatus);
expect(result?.profileId).toEqual(mockData.profileId);
expect(result?.profileName).toEqual(mockData.profileName);
expect(result?.profileType).toEqual(mockData.profileType);
expect(result?.paymentMethod).toEqual(mockData.paymentMethod);
expect(result?.mopStatus).toEqual(mockData.mopStatus);
expect(result?.paymentCurrency).toBeUndefined();
expect(result?.paymentType).toEqual(mockData.paymentType);
expect(result?.cardFunding).toEqual(mockData.cardFunding);
expect(result?.paymentType).toEqual('CARD');
if (result?.paymentType === 'CARD') {
expect(result?.cardSummary).toEqual(mockData.cardSummary);
expect(result?.cardType).toEqual(mockData.cardType);
expect(result?.expiryDate).toEqual(mockData.expiryDate);
expect(result?.expiryMonth).toEqual(mockData.expiryMonth);
expect(result?.expiryYear).toEqual(mockData.expiryYear);
}
});
test('call OK SEPA', async () => {
const mockData = {
token: 'pm_1Kb5WdCOd50lRjiu9tPH3r5i',
holderName: 'Thomas Durant',
fleetId: client.clientOptions.fleetId,
entityId: '2330f5d0-91a3-49fb-8f85-4133384bc02c',
pspName: 'STRIPE',
customerPspReference: 'cus_LHcyYpiF7A2he3',
entityStatus: 'PENDING',
profileId: 'ec94adb1-98e8-48ec-952a-dddc6cba8464',
profileName: 'default',
profileType: 'Single',
paymentMethod: 'SEPA',
mopStatus: 'MOP_INVALID',
bankCode: '20041',
branchCode: '01005',
country: 'FR',
fingerprint: 'SPFArCDNSB9TvZuS',
last4: '2606',
paymentType: 'SEPA',
};
getMock.mockResolvedValueOnce({ data: [
mockData,
]});
const result = await getPaymentMethodDetailsForUser(client, userId);
expect(getMock).toBeCalled();
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
expect(result).toBeTruthy();
expect(result?.token).toEqual(mockData.token);
expect(result?.holderName).toEqual(mockData.holderName);
expect(result?.fleetId).toEqual(mockData.fleetId);
expect(result?.entityId).toEqual(mockData.entityId);
expect(result?.pspName).toEqual(mockData.pspName);
expect(result?.customerPspReference).toEqual(mockData.customerPspReference);
expect(result?.entityStatus).toEqual(mockData.entityStatus);
expect(result?.profileId).toEqual(mockData.profileId);
expect(result?.profileName).toEqual(mockData.profileName);
expect(result?.profileType).toEqual(mockData.profileType);
expect(result?.paymentMethod).toEqual(mockData.paymentMethod);
expect(result?.mopStatus).toEqual(mockData.mopStatus);
expect(result?.paymentCurrency).toBeUndefined();
expect(result?.paymentType).toEqual(mockData.paymentType);
expect(result?.cardFunding).toBeUndefined;
expect(result?.paymentType).toEqual('SEPA');
if (result?.paymentType === 'SEPA') {
expect(result?.bankCode).toEqual(mockData.bankCode);
expect(result?.branchCode).toEqual(mockData.branchCode);
expect(result?.country).toEqual(mockData.country);
expect(result?.fingerprint).toEqual(mockData.fingerprint);
expect(result?.last4).toEqual(mockData.last4);
}
});
test('call OK BANK', async () => {
const mockData = {
token: '8416227869543125',
holderName: 'Jack Dalton',
fleetId: client.clientOptions.fleetId,
entityId: '2330f5d0-91a3-49fb-8f85-4133384bc02d',
pspName: null,
customerPspReference: null,
entityStatus: 'APPROVED',
profileId: 'ec94adb1-98e8-48ec-952a-dddc6cba8465',
profileName: 'default',
profileType: 'Single',
paymentMethod: 'IDEAL',
mopStatus: 'MOP_INVALID',
paymentCurrency: null,
bankName: 'Test Issuer',
bankAccountNumber: '951',
iban: 'NL13TEST0123456789',
bic: 'TESTNL01',
paymentType: 'BANK',
};
getMock.mockResolvedValueOnce({ data: [
mockData,
]});
const result = await getPaymentMethodDetailsForUser(client, userId);
expect(getMock).toBeCalled();
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
expect(result).toBeTruthy();
expect(result?.token).toEqual(mockData.token);
expect(result?.holderName).toEqual(mockData.holderName);
expect(result?.fleetId).toEqual(mockData.fleetId);
expect(result?.entityId).toEqual(mockData.entityId);
expect(result?.pspName).toEqual(mockData.pspName);
expect(result?.customerPspReference).toEqual(mockData.customerPspReference);
expect(result?.entityStatus).toEqual(mockData.entityStatus);
expect(result?.profileId).toEqual(mockData.profileId);
expect(result?.profileName).toEqual(mockData.profileName);
expect(result?.profileType).toEqual(mockData.profileType);
expect(result?.paymentMethod).toEqual(mockData.paymentMethod);
expect(result?.mopStatus).toEqual(mockData.mopStatus);
expect(result?.paymentCurrency).toBeFalsy();
expect(result?.paymentType).toEqual(mockData.paymentType);
expect(result?.cardFunding).toBeUndefined;
expect(result?.paymentType).toEqual('BANK');
if (result?.paymentType === 'BANK') {
expect(result?.bankName).toEqual(mockData.bankName);
expect(result?.bankAccountNumber).toEqual(mockData.bankAccountNumber);
expect(result?.iban).toEqual(mockData.iban);
expect(result?.bic).toEqual(mockData.bic);
}
});
test('call OK missing + business', async () => {
const mockData = [
{
token: null,
holderName: null,
fleetId: 'KINTOEU-ESSHARE',
entityId: 'cc42a4ca-2881-4ea3-af0e-1d8b15599243',
pspName: null,
customerPspReference: null,
entityStatus: 'APPROVED',
profileId: '2dfd07c3-cb97-4df0-a496-48a1c6c7eed4',
profileName: 'default',
profileType: 'Business',
paymentMethod: 'WIRE_TRANSFER',
mopStatus: 'MOP_VALID',
paymentCurrency: null,
bankName: null,
bankAccountNumber: null,
iban: 'FR0000000000000000',
bic: null,
paymentType: 'BANK',
},
{
entityStatus: 'APPROVED',
profileId: 'd392469a-484e-4b86-b9f7-498c2e27e3e0',
profileName: 'default',
profileType: 'Single',
paymentMethod: 'CREDIT_CARD',
mopStatus: 'MOP_MISSING',
paymentType: 'CARD',
}
];
getMock.mockResolvedValueOnce({ data: mockData });
const result = await getPaymentMethodDetailsForUser(client, userId);
expect(getMock).toBeCalled();
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
expect(result).toBeTruthy();
expect(result?.token).toBeUndefined();
expect(result?.holderName).toBeUndefined();
expect(result?.fleetId).toBeUndefined();
expect(result?.entityId).toBeUndefined();
expect(result?.pspName).toBeUndefined();
expect(result?.customerPspReference).toBeUndefined();
expect(result?.entityStatus).toEqual(mockData[1].entityStatus);
expect(result?.profileId).toEqual(mockData[1].profileId);
expect(result?.profileName).toEqual(mockData[1].profileName);
expect(result?.profileType).toEqual(mockData[1].profileType);
expect(result?.paymentMethod).toEqual(mockData[1].paymentMethod);
expect(result?.mopStatus).toEqual(mockData[1].mopStatus);
expect(result?.paymentCurrency).toBeUndefined();
expect(result?.paymentType).toEqual(mockData[1].paymentType);
expect(result?.cardFunding).toBeUndefined;
expect(result?.paymentType).toEqual('CARD');
expect(result?.mopStatus).toEqual('MOP_MISSING');
if (result?.paymentType === 'CARD') {
expect(result?.cardSummary).toBeUndefined();
expect(result?.cardType).toBeUndefined();
expect(result?.expiryDate).toBeUndefined();
expect(result?.expiryMonth).toBeUndefined();
expect(result?.expiryYear).toBeUndefined();
}
});
});