forked from Shared/esg
92 lines
3.0 KiB
TypeScript
92 lines
3.0 KiB
TypeScript
import {
|
|
getCarPolicyProviderError,
|
|
parseFirstCarPolicy,
|
|
} from '../../src/common/helpers/soap-car-policy.helper';
|
|
import { InquiryType } from '../../src/common/enums/inquiry-type.enum';
|
|
import { CentInsurCarPolicyClient } from '../../src/providers/shared/centinsur-car-policy.client';
|
|
|
|
describe('Parsian car-policy SOAP responses', () => {
|
|
it('maps motor inquiries to CIIWSPolicyMotor with the MotorNo SOAP field', async () => {
|
|
const client = new CentInsurCarPolicyClient();
|
|
const callSoap = jest.spyOn(client as any, 'callSoap').mockResolvedValue({ PlcNo: '123' });
|
|
const config = { enabled: true, timeout: 1000, maxRetries: 0, inquiries: {} };
|
|
|
|
await expect(
|
|
client.inquireByMotor(config, InquiryType.CAR_BY_MOTOR, '147H0403219'),
|
|
).resolves.toEqual({ PlcNo: '123' });
|
|
|
|
expect(callSoap).toHaveBeenCalledWith(
|
|
config,
|
|
InquiryType.CAR_BY_MOTOR,
|
|
InquiryType.POLICY_BY_PLATE,
|
|
'CIIWSPolicyMotor',
|
|
{ MotorNo: '147H0403219' },
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
it('parses policy fields from a CIIWSPolicyMotorResult response', () => {
|
|
const xml = `
|
|
<CIIWSPolicyMotorResult>
|
|
<a:Policy>
|
|
<a:Policy>
|
|
<a:NtnlId>4311402422</a:NtnlId>
|
|
<a:MotorNo>147H0403219</a:MotorNo>
|
|
<a:PlcyNo>987654</a:PlcyNo>
|
|
</a:Policy>
|
|
</a:Policy>
|
|
</CIIWSPolicyMotorResult>`;
|
|
|
|
expect(parseFirstCarPolicy(xml)).toEqual({
|
|
NtnlId: '4311402422',
|
|
MotorNo: '147H0403219',
|
|
PlcyNo: '987654',
|
|
});
|
|
});
|
|
|
|
it('extracts the Persian message from a nested KeyValue error and classifies no-policy', () => {
|
|
const xml = `
|
|
<CIIWSPolicyNationalIdResult>
|
|
<b:Error>
|
|
<b:KeyValueOfstringstring>
|
|
<b:Key>2</b:Key>
|
|
<b:Value> موردی یافت نشد .</b:Value>
|
|
</b:KeyValueOfstringstring>
|
|
</b:Error>
|
|
</CIIWSPolicyNationalIdResult>`;
|
|
|
|
expect(getCarPolicyProviderError(xml, parseFirstCarPolicy(xml))).toEqual({
|
|
message: 'موردی یافت نشد .',
|
|
code: 'CAR_POLICY_NOT_FOUND',
|
|
providerCode: '2',
|
|
});
|
|
});
|
|
|
|
it('does not classify an unrelated provider error as a no-policy result', () => {
|
|
const xml = `
|
|
<CIIWSPolicyNationalIdResult>
|
|
<b:Error>
|
|
<b:KeyValueOfstringstring>
|
|
<b:Key>500</b:Key>
|
|
<b:Value>خطای موقت سرویس</b:Value>
|
|
</b:KeyValueOfstringstring>
|
|
</b:Error>
|
|
</CIIWSPolicyNationalIdResult>`;
|
|
|
|
expect(getCarPolicyProviderError(xml, parseFirstCarPolicy(xml))).toEqual({
|
|
message: 'خطای موقت سرویس',
|
|
code: 'PROVIDER_ERROR',
|
|
providerCode: '500',
|
|
});
|
|
});
|
|
|
|
it('uses the car-policy catalog code when the response has no policy and no explicit error', () => {
|
|
const xml = '<CIIWSPolicyNationalIdResult><b:Error i:nil="true" /></CIIWSPolicyNationalIdResult>';
|
|
|
|
expect(getCarPolicyProviderError(xml, {})).toEqual({
|
|
message: 'No policy record found',
|
|
code: 'CAR_POLICY_NOT_FOUND',
|
|
});
|
|
});
|
|
});
|