INSR-10442: Update client specific logic to use dynamic imports
This prevents the exposure of client name -> parent account number mapping. Probably cleaner overal, as well
This commit is contained in:
parent
d1af95bc15
commit
7f424a1f4f
5 changed files with 68 additions and 66 deletions
|
|
@ -1,5 +0,0 @@
|
|||
const parentAccountNumber = Object.freeze({
|
||||
USAA: 900040
|
||||
});
|
||||
|
||||
export default parentAccountNumber;
|
||||
10
src/helpers/client-mappers/Client900040Coverage.js
Normal file
10
src/helpers/client-mappers/Client900040Coverage.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { useMainStore } from "@/store";
|
||||
|
||||
export function updateClaimRegistrationPayload(payload) {
|
||||
console.log(`updating payload for USAA`)
|
||||
const mainStore = useMainStore();
|
||||
payload.additionalInfo = {
|
||||
offeredItac: mainStore.isITAC ? 'true' : 'false',
|
||||
qualifiedForItac: mainStore.isITAC ? 'true' : 'false'
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,14 @@
|
|||
import parentAccountNumber from "@/constants/parent-account-numbers";
|
||||
import { useMainStore } from "@/store";
|
||||
|
||||
export function updateClientSpecificFieldsForClaimRegistration(payload) {
|
||||
export async function updateClientSpecificFieldsForClaimRegistration(payload) {
|
||||
const mainStore = useMainStore();
|
||||
switch (mainStore.order.parentAccountNumber) {
|
||||
case parentAccountNumber.USAA:
|
||||
payload.additionalInfo = {
|
||||
offeredItac: mainStore.isITAC.toString(),
|
||||
qualifiedForItac: mainStore.isITAC.toString()
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
try {
|
||||
console.log(`Updating client-specific fields for claim registration for parent account number: ${mainStore.order.parentAccountNumber}`);
|
||||
const clientMapper = await import(`@/helpers/client-mappers/Client${mainStore.order.parentAccountNumber}Coverage.js`);
|
||||
console.log(`Loaded client mapper: ${clientMapper}`);
|
||||
clientMapper.updateClaimRegistrationPayload(payload);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error updating client-specific fields for claim registration:', error);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,68 +1,67 @@
|
|||
import { updateClientSpecificFieldsForClaimRegistration } from '@/helpers/coverage-helper';
|
||||
import parentAccountNumber from '@/constants/parent-account-numbers';
|
||||
|
||||
let mockStore;
|
||||
|
||||
jest.mock('@/store', () => ({
|
||||
useMainStore: jest.fn(() => mockStore)
|
||||
useMainStore: jest.fn(() => mockStore)
|
||||
}));
|
||||
|
||||
describe('coverage-helper.js', () => {
|
||||
describe('updateClientSpecificFieldsForClaimRegistration', () => {
|
||||
beforeEach(() => {
|
||||
mockStore = {
|
||||
order: {
|
||||
parentAccountNumber: null
|
||||
},
|
||||
isITAC: false
|
||||
};
|
||||
describe('updateClientSpecificFieldsForClaimRegistration', () => {
|
||||
beforeEach(() => {
|
||||
mockStore = {
|
||||
order: {
|
||||
parentAccountNumber: null
|
||||
},
|
||||
isITAC: false
|
||||
};
|
||||
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('Sets additionalInfo fields when parent account is USAA and isITAC is true', () => {
|
||||
// Arrange
|
||||
const payload = {};
|
||||
mockStore.order.parentAccountNumber = parentAccountNumber.USAA;
|
||||
mockStore.isITAC = true;
|
||||
test('Sets additionalInfo fields when parent account is 900040 and isITAC is true', async () => {
|
||||
// Arrange
|
||||
const payload = {};
|
||||
mockStore.order.parentAccountNumber = 900040;
|
||||
mockStore.isITAC = true;
|
||||
|
||||
// Act
|
||||
updateClientSpecificFieldsForClaimRegistration(payload);
|
||||
// Act
|
||||
await updateClientSpecificFieldsForClaimRegistration(payload);
|
||||
|
||||
// Assert
|
||||
expect(payload.additionalInfo).toEqual({
|
||||
offeredItac: 'true',
|
||||
qualifiedForItac: 'true'
|
||||
});
|
||||
});
|
||||
// Assert
|
||||
expect(payload.additionalInfo).toEqual({
|
||||
offeredItac: 'true',
|
||||
qualifiedForItac: 'true'
|
||||
});
|
||||
});
|
||||
|
||||
test('Sets additionalInfo fields when parent account is USAA and isITAC is false', () => {
|
||||
// Arrange
|
||||
const payload = {};
|
||||
mockStore.order.parentAccountNumber = parentAccountNumber.USAA;
|
||||
mockStore.isITAC = false;
|
||||
test('Sets additionalInfo fields when parent account is 900040 and isITAC is false', async () => {
|
||||
// Arrange
|
||||
const payload = {};
|
||||
mockStore.order.parentAccountNumber = 900040;
|
||||
mockStore.isITAC = false;
|
||||
|
||||
// Act
|
||||
updateClientSpecificFieldsForClaimRegistration(payload);
|
||||
// Act
|
||||
await updateClientSpecificFieldsForClaimRegistration(payload);
|
||||
|
||||
// Assert
|
||||
expect(payload.additionalInfo).toEqual({
|
||||
offeredItac: 'false',
|
||||
qualifiedForItac: 'false'
|
||||
});
|
||||
});
|
||||
// Assert
|
||||
expect(payload.additionalInfo).toEqual({
|
||||
offeredItac: 'false',
|
||||
qualifiedForItac: 'false'
|
||||
});
|
||||
});
|
||||
|
||||
test('Does not set additionalInfo when parent account is not USAA', () => {
|
||||
// Arrange
|
||||
const payload = {};
|
||||
mockStore.order.parentAccountNumber = 123456;
|
||||
mockStore.isITAC = true;
|
||||
test('Does not set additionalInfo when parent account is not 900040', async () => {
|
||||
// Arrange
|
||||
const payload = {};
|
||||
mockStore.order.parentAccountNumber = 123456;
|
||||
mockStore.isITAC = true;
|
||||
|
||||
// Act
|
||||
updateClientSpecificFieldsForClaimRegistration(payload);
|
||||
// Act
|
||||
await updateClientSpecificFieldsForClaimRegistration(payload);
|
||||
|
||||
// Assert
|
||||
expect(payload.additionalInfo).toBeUndefined();
|
||||
});
|
||||
});
|
||||
// Assert
|
||||
expect(payload.additionalInfo).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -714,7 +714,7 @@ export const useMainStore = defineStore({
|
|||
if (this.issConfig.useMemberNumber) {
|
||||
payload.memberNumber = this.order.policy.policyNumber;
|
||||
}
|
||||
updateClientSpecificFieldsForClaimRegistration(payload);
|
||||
await updateClientSpecificFieldsForClaimRegistration(payload);
|
||||
const response = await globalMethods.callHttpClient({
|
||||
method: endpoints.RegisterClaim.method,
|
||||
endpoint: endpoints.RegisterClaim.url,
|
||||
|
|
|
|||
Loading…
Reference in a new issue