forked from Shared/esg
Add health check and retry logic and circuit breaker
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
getCarPolicyProviderError,
|
||||
parseFirstCarPolicy,
|
||||
} from '../../src/common/helpers/soap-car-policy.helper';
|
||||
|
||||
describe('Parsian car-policy SOAP responses', () => {
|
||||
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',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user