forked from Shared/esg
database migrated to POSTGRESQL
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { InquiryType } from '../../src/common/enums/inquiry-type.enum';
|
||||
import { TejaratNouProvider } from '../../src/providers/implementations/tejaratnou.provider';
|
||||
|
||||
describe('Tejarat policy by plate', () => {
|
||||
it('posts plate parts and national code to central-insurance-car-inquiry with the Tejarat token', async () => {
|
||||
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',
|
||||
};
|
||||
const provider = new TejaratNouProvider(
|
||||
{ get: () => config } as never,
|
||||
{ getTejaratNouAccessToken } as never,
|
||||
{} as never,
|
||||
);
|
||||
const request = jest.spyOn((provider as unknown as { httpClient: { request: jest.Mock } }).httpClient, 'request').mockResolvedValue({
|
||||
data: {
|
||||
isSuccess: true,
|
||||
data: { PolicyNo: 'P-1', NtnlId: '4311402422' },
|
||||
},
|
||||
});
|
||||
|
||||
const result = await provider.execute(
|
||||
InquiryType.POLICY_BY_PLATE,
|
||||
{
|
||||
nationalCode: '4311402422',
|
||||
plk1: '12',
|
||||
plk2: 'ب',
|
||||
plk3: '345',
|
||||
plksrl: '67',
|
||||
},
|
||||
{ requestId: 'req-1', trackingCode: 'trk-1' },
|
||||
);
|
||||
|
||||
expect(getTejaratNouAccessToken).toHaveBeenCalledWith(config, expect.any(AbortSignal));
|
||||
expect(request).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
url: '/api/central-insurance-car-inquiry',
|
||||
data: {
|
||||
Part1: '12',
|
||||
Part2: 'ب',
|
||||
Part3: '345',
|
||||
Part4: '67',
|
||||
NationalCode: '4311402422',
|
||||
},
|
||||
headers: {
|
||||
Authorization: 'Bearer tejarat-token',
|
||||
Accept: 'text/plain',
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
raw: {
|
||||
nationalCode: '4311402422',
|
||||
plk1: '12',
|
||||
plk2: 'ب',
|
||||
plk3: '345',
|
||||
plksrl: '67',
|
||||
PolicyNo: 'P-1',
|
||||
NtnlId: '4311402422',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user