fix: fix create application mock

This commit is contained in:
Abdalhameed Ahmad
2025-08-26 19:17:00 +03:00
parent 3df34c0017
commit 88730a2b2b
2 changed files with 190 additions and 750 deletions

View File

@ -1,19 +1,25 @@
function getRandomWithDigits(digits: number): string { import { randomInt, randomUUID } from 'crypto';
const min = Math.pow(10, digits - 1); // e.g. 1000 for 4 digits
const max = Math.pow(10, digits) - 1; // e.g. 9999 for 4 digits
const result = Math.floor(Math.random() * (max - min + 1)) + min; /** Generate a string of `n` random digits (first digit never 0). */
return result.toString(); function randomDigits(n: number): string {
if (n <= 0) return '0';
let s = String(randomInt(1, 10)); // first digit 19
for (let i = 1; i < n; i++) s += String(randomInt(0, 10));
return s;
} }
export const CREATE_APPLICATION_MOCK = { /** Build a fresh mock object every time it's called */
export function buildCreateApplicationMock() {
const now = new Date().toISOString();
return {
ResponseHeader: { ResponseHeader: {
Version: '1.0.0', Version: '1.0.0',
MsgUid: 'adaa1893-9f95-48a8-b7a1-0422bcf629b5', MsgUid: randomUUID(),
Source: 'ZOD', Source: 'ZOD',
ServiceId: 'CreateNewApplication', ServiceId: 'CreateNewApplication',
ReqDateTime: '2025-06-03T07:32:16.304Z', ReqDateTime: now,
RspDateTime: '2025-06-03T08:21:15.662', RspDateTime: now,
ResponseCode: '000', ResponseCode: '000',
ResponseType: 'Success', ResponseType: 'Success',
ProcessingTime: 1665, ProcessingTime: 1665,
@ -81,26 +87,11 @@ export const CREATE_APPLICATION_MOCK = {
EmployerName: 'N/A', EmployerName: 'N/A',
EmploymentYears: 0, EmploymentYears: 0,
EmploymentMonths: 0, EmploymentMonths: 0,
EmployerPhoneArea: null,
EmployerPhoneNumber: null,
EmployerPhoneExtension: null,
EmployerMobile: null,
EmployerFaxArea: null,
EmployerFax: null,
EmployerCity: null,
EmployerAddress: null,
EmploymentActivity: null,
EmploymentStatus: null,
CIF: null, CIF: null,
BankAccountNumber: ' ', BankAccountNumber: ' ',
Currency: { Currency: { CurrCode: '682', AlphaCode: 'SAR' },
CurrCode: '682',
AlphaCode: 'SAR',
},
RequestedCurrencyList: null,
CreditAccountNumber: '6000000000000000', CreditAccountNumber: '6000000000000000',
AccountType: '30', AccountType: '30',
OpenDate: null,
Income: 0, Income: 0,
AdditionalIncome: 0, AdditionalIncome: 0,
TotalIncome: 0, TotalIncome: 0,
@ -115,551 +106,28 @@ export const CREATE_APPLICATION_MOCK = {
AutoDebit: 'N', AutoDebit: 'N',
PaymentMethod: '2', PaymentMethod: '2',
BillingCycle: 'C1', BillingCycle: 'C1',
OldIssueDate: null,
OtherPaymentsDate: null,
MaximumDelinquency: null, MaximumDelinquency: null,
CreditBureauDecision: null, CreditBureauDecision: null,
CreditBureauUserData: null,
ECommerce: 'N', ECommerce: 'N',
NumberOfCards: 0, NumberOfCards: 0,
OtherBank: null,
OtherBankDescription: null,
InsuranceProduct: null,
SocialCode: '000', SocialCode: '000',
JobGrade: 0, JobGrade: 0,
Flags: [ Flags: Array.from({ length: 64 }, (_, i) => ({
{ Position: i + 1,
Position: 1,
Value: '0', Value: '0',
}, })),
{ CheckFlags: Array.from({ length: 64 }, (_, i) => ({
Position: 2, Position: i + 1,
Value: '0',
},
{
Position: 3,
Value: '0',
},
{
Position: 4,
Value: '0',
},
{
Position: 5,
Value: '0',
},
{
Position: 6,
Value: '0',
},
{
Position: 7,
Value: '0',
},
{
Position: 8,
Value: '0',
},
{
Position: 9,
Value: '0',
},
{
Position: 10,
Value: '0',
},
{
Position: 11,
Value: '0',
},
{
Position: 12,
Value: '0',
},
{
Position: 13,
Value: '0',
},
{
Position: 14,
Value: '0',
},
{
Position: 15,
Value: '0',
},
{
Position: 16,
Value: '0',
},
{
Position: 17,
Value: '0',
},
{
Position: 18,
Value: '0',
},
{
Position: 19,
Value: '0',
},
{
Position: 20,
Value: '0',
},
{
Position: 21,
Value: '0',
},
{
Position: 22,
Value: '0',
},
{
Position: 23,
Value: '0',
},
{
Position: 24,
Value: '0',
},
{
Position: 25,
Value: '0',
},
{
Position: 26,
Value: '0',
},
{
Position: 27,
Value: '0',
},
{
Position: 28,
Value: '0',
},
{
Position: 29,
Value: '0',
},
{
Position: 30,
Value: '0',
},
{
Position: 31,
Value: '0',
},
{
Position: 32,
Value: '0',
},
{
Position: 33,
Value: '0',
},
{
Position: 34,
Value: '0',
},
{
Position: 35,
Value: '0',
},
{
Position: 36,
Value: '0',
},
{
Position: 37,
Value: '0',
},
{
Position: 38,
Value: '0',
},
{
Position: 39,
Value: '0',
},
{
Position: 40,
Value: '0',
},
{
Position: 41,
Value: '0',
},
{
Position: 42,
Value: '0',
},
{
Position: 43,
Value: '0',
},
{
Position: 44,
Value: '0',
},
{
Position: 45,
Value: '0',
},
{
Position: 46,
Value: '0',
},
{
Position: 47,
Value: '0',
},
{
Position: 48,
Value: '0',
},
{
Position: 49,
Value: '0',
},
{
Position: 50,
Value: '0',
},
{
Position: 51,
Value: '0',
},
{
Position: 52,
Value: '0',
},
{
Position: 53,
Value: '0',
},
{
Position: 54,
Value: '0',
},
{
Position: 55,
Value: '0',
},
{
Position: 56,
Value: '0',
},
{
Position: 57,
Value: '0',
},
{
Position: 58,
Value: '0',
},
{
Position: 59,
Value: '0',
},
{
Position: 60,
Value: '0',
},
{
Position: 61,
Value: '0',
},
{
Position: 62,
Value: '0',
},
{
Position: 63,
Value: '0',
},
{
Position: 64,
Value: '0',
},
],
CheckFlags: [
{
Position: 1,
Value: '0', Value: '0',
})),
}, },
{
Position: 2,
Value: '0',
},
{
Position: 3,
Value: '0',
},
{
Position: 4,
Value: '0',
},
{
Position: 5,
Value: '0',
},
{
Position: 6,
Value: '0',
},
{
Position: 7,
Value: '0',
},
{
Position: 8,
Value: '0',
},
{
Position: 9,
Value: '0',
},
{
Position: 10,
Value: '0',
},
{
Position: 11,
Value: '0',
},
{
Position: 12,
Value: '0',
},
{
Position: 13,
Value: '0',
},
{
Position: 14,
Value: '0',
},
{
Position: 15,
Value: '0',
},
{
Position: 16,
Value: '0',
},
{
Position: 17,
Value: '0',
},
{
Position: 18,
Value: '0',
},
{
Position: 19,
Value: '0',
},
{
Position: 20,
Value: '0',
},
{
Position: 21,
Value: '0',
},
{
Position: 22,
Value: '0',
},
{
Position: 23,
Value: '0',
},
{
Position: 24,
Value: '0',
},
{
Position: 25,
Value: '0',
},
{
Position: 26,
Value: '0',
},
{
Position: 27,
Value: '0',
},
{
Position: 28,
Value: '0',
},
{
Position: 29,
Value: '0',
},
{
Position: 30,
Value: '0',
},
{
Position: 31,
Value: '0',
},
{
Position: 32,
Value: '0',
},
{
Position: 33,
Value: '0',
},
{
Position: 34,
Value: '0',
},
{
Position: 35,
Value: '0',
},
{
Position: 36,
Value: '0',
},
{
Position: 37,
Value: '0',
},
{
Position: 38,
Value: '0',
},
{
Position: 39,
Value: '0',
},
{
Position: 40,
Value: '0',
},
{
Position: 41,
Value: '0',
},
{
Position: 42,
Value: '0',
},
{
Position: 43,
Value: '0',
},
{
Position: 44,
Value: '0',
},
{
Position: 45,
Value: '0',
},
{
Position: 46,
Value: '0',
},
{
Position: 47,
Value: '0',
},
{
Position: 48,
Value: '0',
},
{
Position: 49,
Value: '0',
},
{
Position: 50,
Value: '0',
},
{
Position: 51,
Value: '0',
},
{
Position: 52,
Value: '0',
},
{
Position: 53,
Value: '0',
},
{
Position: 54,
Value: '0',
},
{
Position: 55,
Value: '0',
},
{
Position: 56,
Value: '0',
},
{
Position: 57,
Value: '0',
},
{
Position: 58,
Value: '0',
},
{
Position: 59,
Value: '0',
},
{
Position: 60,
Value: '0',
},
{
Position: 61,
Value: '0',
},
{
Position: 62,
Value: '0',
},
{
Position: 63,
Value: '0',
},
{
Position: 64,
Value: '0',
},
],
Maker: null,
Checker: null,
ReferredTo: null,
ReferralReason: null,
UserData1: null,
UserData2: null,
UserData3: null,
UserData4: null,
UserData5: null,
AdditionalFields: [],
},
ApplicationStatusDetails: { ApplicationStatusDetails: {
StatusCode: '04', StatusCode: '04',
Description: 'Approved', Description: 'Approved',
Canceled: false, Canceled: false,
}, },
CorporateDetails: null,
CustomerDetails: { CustomerDetails: {
Id: 115158, Id: 115158,
CustomerCode: '100000024619', CustomerCode: '100000024619',
@ -668,8 +136,8 @@ export const CREATE_APPLICATION_MOCK = {
PreferredLanguage: 'EN', PreferredLanguage: 'EN',
ExternalCustomerCode: null, ExternalCustomerCode: null,
Title: ' ', Title: ' ',
FirstName: ' ', FirstName: ' ',
LastName: ' ', LastName: ' ',
DateOfBirth: null, DateOfBirth: null,
UserData1: '2031-09-17', UserData1: '2031-09-17',
UserData2: '01', UserData2: '01',
@ -679,75 +147,46 @@ export const CREATE_APPLICATION_MOCK = {
Gender: 'U', Gender: 'U',
Married: 'U', Married: 'U',
}, },
AccountDetailsList: [ AccountDetailsList: [
{ {
Id: getRandomWithDigits(5), Id: randomDigits(5),
InstitutionCode: '1100', InstitutionCode: '1100',
AccountNumber: getRandomWithDigits(16), AccountNumber: randomDigits(16),
Currency: { Currency: { CurrCode: '682', AlphaCode: 'SAR' },
CurrCode: '682',
AlphaCode: 'SAR',
},
AccountTypeCode: '30', AccountTypeCode: '30',
ClassId: '2', ClassId: '2',
AccountStatus: '00', AccountStatus: '00',
VipFlag: '0', VipFlag: '0',
BlockedAmount: 0, BlockedAmount: 0,
EquivalentBlockedAmount: null,
UnclearCredit: 0,
EquivalentUnclearCredit: null,
AvailableBalance: 0, AvailableBalance: 0,
EquivalentAvailableBalance: null,
AvailableBalanceToSpend: 0,
CreditLimit: 0,
RemainingCashLimit: null,
UserData1: 'D36407C9AE4C28D2185', UserData1: 'D36407C9AE4C28D2185',
UserData2: null,
UserData3: 'D36407C9AE4C28D2185', UserData3: 'D36407C9AE4C28D2185',
UserData4: null, UserData5: `SA${randomDigits(22)}`,
UserData5: `SA${getRandomWithDigits(22)}`,
}, },
], ],
CardDetailsList: [ CardDetailsList: [
{ {
pvv: null, pvv: null,
ResponseCardIdentifier: { ResponseCardIdentifier: {
Id: getRandomWithDigits(5), Id: randomDigits(5),
Pan: 'DDDDDDDDDDDDDDDDDDD', Pan: 'DDDDDDDDDDDDDDDDDDD',
MaskedPan: '999999_9999', MaskedPan: '999999_9999',
VPan: getRandomWithDigits(16), VPan: randomDigits(16),
Seqno: 0, Seqno: 0,
}, },
ExpiryDate: '2031-09-30', ExpiryDate: '2031-09-30',
EffectiveDate: '2025-06-02', EffectiveDate: '2025-06-02',
CardStatus: '30', CardStatus: '30',
OldPlasticExpiryDate: null,
OldPlasticCardStatus: null,
EmbossingName: 'ABDALHAMID AHMAD', EmbossingName: 'ABDALHAMID AHMAD',
Title: 'Mr.', Title: 'Mr.',
FirstName: 'Abdalhamid', FirstName: 'Abdalhamid',
LastName: ' Ahmad', LastName: ' Ahmad',
Additional: false,
BatchNumber: 8849, BatchNumber: 8849,
ServiceCode: '226', ServiceCode: '226',
Kinship: null,
DateOfBirth: '1999-01-07', DateOfBirth: '1999-01-07',
LastActivity: null,
LastStatusChangeDate: '2025-06-03', LastStatusChangeDate: '2025-06-03',
ActivationDate: null,
DateLastIssued: null,
PVV: null,
UserData: '4',
UserData1: '3',
UserData2: null,
UserData3: null,
UserData4: null,
UserData5: null,
Memo: null,
CardAuthorizationParameters: null,
L10NTitle: null,
L10NFirstName: null,
L10NLastName: null,
PinStatus: '40', PinStatus: '40',
OldPinStatus: '0', OldPinStatus: '0',
CustomerIdNumber: '1089055972', CustomerIdNumber: '1089055972',
@ -755,4 +194,5 @@ export const CREATE_APPLICATION_MOCK = {
}, },
], ],
}, },
}; };
}

View File

@ -10,8 +10,8 @@ import { InitiateKycRequestDto } from '~/customer/dtos/request';
import { Customer } from '~/customer/entities'; import { Customer } from '~/customer/entities';
import { Gender } from '~/customer/enums'; import { Gender } from '~/customer/enums';
import { import {
buildCreateApplicationMock,
CARD_EMBOSSING_DETAILS_MOCK, CARD_EMBOSSING_DETAILS_MOCK,
CREATE_APPLICATION_MOCK,
INITIATE_KYC_MOCK, INITIATE_KYC_MOCK,
INQUIRE_APPLICATION_MOCK, INQUIRE_APPLICATION_MOCK,
} from '../__mocks__/'; } from '../__mocks__/';
@ -95,7 +95,7 @@ export class NeoLeapService {
const responseKey = 'CreateNewApplicationResponseDetails'; const responseKey = 'CreateNewApplicationResponseDetails';
if (!this.useGateway) { if (!this.useGateway) {
return plainToInstance(CreateApplicationResponse, CREATE_APPLICATION_MOCK[responseKey], { return plainToInstance(CreateApplicationResponse, buildCreateApplicationMock()[responseKey], {
excludeExtraneousValues: true, excludeExtraneousValues: true,
}); });
} }
@ -169,7 +169,7 @@ export class NeoLeapService {
const responseKey = 'CreateNewApplicationResponseDetails'; const responseKey = 'CreateNewApplicationResponseDetails';
if (!this.useGateway) { if (!this.useGateway) {
return plainToInstance(CreateApplicationResponse, CREATE_APPLICATION_MOCK[responseKey], { return plainToInstance(CreateApplicationResponse, buildCreateApplicationMock()[responseKey], {
excludeExtraneousValues: true, excludeExtraneousValues: true,
}); });
} }