forked from Shared/esg
104 lines
3.2 KiB
TypeScript
104 lines
3.2 KiB
TypeScript
import { InquiryType } from '../../src/common/enums/inquiry-type.enum';
|
|
import { TejaratNouProvider } from '../../src/providers/implementations/tejaratnou.provider';
|
|
|
|
function createProvider(inquiries?: Record<string, { url: string }>) {
|
|
const getTejaratNouAccessToken = jest.fn().mockResolvedValue('tejarat-token');
|
|
const config = {
|
|
enabled: true,
|
|
timeout: 15000,
|
|
maxRetries: 1,
|
|
baseUrl: 'https://accounts.tejaratnoins.ir',
|
|
inquiryBaseUrl: 'https://gateway.tejaratnoins.ir',
|
|
clientId: 'api-gateway',
|
|
clientSecret: 'secret',
|
|
username: 'user',
|
|
password: 'pass',
|
|
inquiries,
|
|
};
|
|
const provider = new TejaratNouProvider(
|
|
{ get: () => config } as never,
|
|
{ getTejaratNouAccessToken } as never,
|
|
{
|
|
findPersonInquiry: jest.fn().mockResolvedValue(null),
|
|
savePersonInquiry: jest.fn().mockResolvedValue(undefined),
|
|
} as never,
|
|
);
|
|
const request = jest
|
|
.spyOn((provider as unknown as { httpClient: { request: jest.Mock } }).httpClient, 'request')
|
|
.mockResolvedValue({
|
|
data: {
|
|
isSuccess: true,
|
|
data: { name: 'Ali', family: 'Ahmadi', nationalCodeString: '0820270725', ReturnValue: true },
|
|
},
|
|
});
|
|
|
|
return { provider, request };
|
|
}
|
|
|
|
describe('Tejarat identity, shahkar, real estate, and sheba', () => {
|
|
it('posts a Jalali birth year to birthdate-year', async () => {
|
|
const { provider, request } = createProvider();
|
|
|
|
await provider.execute(
|
|
InquiryType.PERSON,
|
|
{ nationalCode: '4311402422', birthDate: '1378' },
|
|
{ requestId: 'req-year', trackingCode: 'trk-year' },
|
|
);
|
|
|
|
expect(request).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
method: 'POST',
|
|
url: '/api/identity-inquiry/national-code/4311402422/birthdate-year/1378',
|
|
headers: expect.objectContaining({ Authorization: 'Bearer tejarat-token', Accept: 'text/plain' }),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('gets a full Jalali birth date as a Gregorian birthdate', async () => {
|
|
const { provider, request } = createProvider();
|
|
|
|
await provider.execute(
|
|
InquiryType.PERSON,
|
|
{ nationalCode: '0820270725', birthDate: '1373-10-12' },
|
|
{ requestId: 'req-date', trackingCode: 'trk-date' },
|
|
);
|
|
|
|
expect(request).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
method: 'GET',
|
|
url: '/api/identity-inquiry/national-code/0820270725/birthdate/1995-01-02',
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('posts sheba with the Tejarat account, national id, and sheba fields', async () => {
|
|
const { provider, request } = createProvider({
|
|
[InquiryType.SHEBA]: {
|
|
url: 'https://gateway.tejaratnoins.ir/api/central-insurance-sheba-inquiry',
|
|
},
|
|
});
|
|
|
|
await provider.execute(
|
|
InquiryType.SHEBA,
|
|
{
|
|
nationalCode: '0012345678',
|
|
sheba: 'IR090540202620101368196602',
|
|
accountOwnerType: '1',
|
|
},
|
|
{ requestId: 'req-sheba', trackingCode: 'trk-sheba' },
|
|
);
|
|
|
|
expect(request).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
method: 'POST',
|
|
url: 'https://gateway.tejaratnoins.ir/api/central-insurance-sheba-inquiry',
|
|
data: {
|
|
AccountOwnerType: 1,
|
|
NationalId: '0012345678',
|
|
ShebaId: 'IR090540202620101368196602',
|
|
},
|
|
}),
|
|
);
|
|
});
|
|
});
|