Merge pull request #1310 from Safelite/feature/humphries/INSR-523
INSR-523: Move claim registration to just before work order submission for USAA
This commit is contained in:
commit
d94bd6ebe0
4 changed files with 183 additions and 11 deletions
|
|
@ -37,6 +37,15 @@ export async function saveSession({ shouldAwaitSaveSessionQueue = false, submitA
|
||||||
export async function submitWorkOrder({ submitType }) {
|
export async function submitWorkOrder({ submitType }) {
|
||||||
const store = useMainStore();
|
const store = useMainStore();
|
||||||
store.resetSubmittedOrder();
|
store.resetSubmittedOrder();
|
||||||
|
const shouldRegisterClaim = store.isPolicyLookupSuccessful
|
||||||
|
&& store.vehicle.policyVehicleId != null
|
||||||
|
&& store.vehicle.policyVehicleId >= 0
|
||||||
|
&& store.isClaimRegistrationRequired
|
||||||
|
&& store.issConfig.callClaimRegistrationAtEnd
|
||||||
|
&& !store.isNoComp;
|
||||||
|
if (shouldRegisterClaim) {
|
||||||
|
await store.registerClaim();
|
||||||
|
}
|
||||||
await saveSession({
|
await saveSession({
|
||||||
shouldAwaitSaveSessionQueue: true,
|
shouldAwaitSaveSessionQueue: true,
|
||||||
submitAfterSave: true,
|
submitAfterSave: true,
|
||||||
|
|
|
||||||
157
src/helpers/order-helper.spec.js
Normal file
157
src/helpers/order-helper.spec.js
Normal file
|
|
@ -0,0 +1,157 @@
|
||||||
|
import coverageType from '@/constants/coverage-type';
|
||||||
|
import { submitWorkOrder } from '@/helpers/order-helper';
|
||||||
|
import { createTestingPinia } from '@pinia/testing';
|
||||||
|
import { getDefaultState, useMainStore } from '@/store';
|
||||||
|
|
||||||
|
let store;
|
||||||
|
|
||||||
|
describe('order-helper.js', () => {
|
||||||
|
describe('submitWorkOrder', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const testingPinia = createTestingPinia({
|
||||||
|
initialState: {
|
||||||
|
main: getDefaultState()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
store = useMainStore(testingPinia);
|
||||||
|
|
||||||
|
store.resetSubmittedOrder = jest.fn();
|
||||||
|
store.createSubmittedOrder = jest.fn(() => Promise.resolve());
|
||||||
|
store.registerClaim = jest.fn(() => Promise.resolve());
|
||||||
|
store.saveSession = jest.fn(() => Promise.resolve({ data: { referralNumber: 'REF-001' } }));
|
||||||
|
store.setSaveSessionInfo = jest.fn();
|
||||||
|
store.setSaveSessionPromise = jest.fn((promise) => {
|
||||||
|
store.applicationUser.saveSessionPromise = promise;
|
||||||
|
});
|
||||||
|
|
||||||
|
store.order.referralNumber = null;
|
||||||
|
store.order.vehicle.policyVehicleId = null;
|
||||||
|
store.order.insuranceCoverage.coverageType = coverageType.NONE;
|
||||||
|
store.issConfig.isClaimRegistrationRequired = false;
|
||||||
|
store.issConfig.callClaimRegistrationAtEnd = false;
|
||||||
|
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Resets order, saves session, and creates submitted order with submit type', async () => {
|
||||||
|
// Arrange
|
||||||
|
const submitType = 'SUBMIT';
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(store.resetSubmittedOrder).toHaveBeenCalledTimes(1);
|
||||||
|
expect(store.saveSession).toHaveBeenCalledTimes(1);
|
||||||
|
expect(store.saveSession).toHaveBeenCalledWith({
|
||||||
|
submitAfterSave: true,
|
||||||
|
createWorkOrderNumberForPIA: false,
|
||||||
|
bailoutOnError: true
|
||||||
|
});
|
||||||
|
expect(store.setSaveSessionPromise).toHaveBeenCalledTimes(1);
|
||||||
|
expect(store.setSaveSessionInfo).toHaveBeenCalledWith({ referralNumber: 'REF-001' });
|
||||||
|
expect(store.createSubmittedOrder).toHaveBeenCalledTimes(1);
|
||||||
|
expect(store.createSubmittedOrder).toHaveBeenCalledWith(submitType);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Registers claim when all claim registration conditions are met', async () => {
|
||||||
|
// Arrange
|
||||||
|
store.order.insuranceCoverage.coverageType = coverageType.Deductible;
|
||||||
|
store.order.vehicle.policyVehicleId = 42;
|
||||||
|
store.issConfig.isClaimRegistrationRequired = true;
|
||||||
|
store.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(store.registerClaim).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when policy lookup is not successful', async () => {
|
||||||
|
// Arrange
|
||||||
|
store.order.insuranceCoverage.coverageType = coverageType.NONE;
|
||||||
|
store.order.vehicle.policyVehicleId = 42;
|
||||||
|
store.issConfig.isClaimRegistrationRequired = true;
|
||||||
|
store.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(store.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when policyVehicleId is null', async () => {
|
||||||
|
// Arrange
|
||||||
|
store.order.insuranceCoverage.coverageType = coverageType.Deductible;
|
||||||
|
store.order.vehicle.policyVehicleId = null;
|
||||||
|
store.issConfig.isClaimRegistrationRequired = true;
|
||||||
|
store.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(store.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when policyVehicleId is negative', async () => {
|
||||||
|
// Arrange
|
||||||
|
store.order.insuranceCoverage.coverageType = coverageType.Deductible;
|
||||||
|
store.order.vehicle.policyVehicleId = -1;
|
||||||
|
store.issConfig.isClaimRegistrationRequired = true;
|
||||||
|
store.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(store.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when claim registration is not required', async () => {
|
||||||
|
// Arrange
|
||||||
|
store.order.insuranceCoverage.coverageType = coverageType.Deductible;
|
||||||
|
store.order.vehicle.policyVehicleId = 42;
|
||||||
|
store.issConfig.isClaimRegistrationRequired = false;
|
||||||
|
store.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(store.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when claim registration is disabled in config', async () => {
|
||||||
|
// Arrange
|
||||||
|
store.order.insuranceCoverage.coverageType = coverageType.Deductible;
|
||||||
|
store.order.vehicle.policyVehicleId = 42;
|
||||||
|
store.issConfig.isClaimRegistrationRequired = true;
|
||||||
|
store.issConfig.callClaimRegistrationAtEnd = false;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(store.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when coverage type is NoComp', async () => {
|
||||||
|
// Arrange
|
||||||
|
store.order.insuranceCoverage.coverageType = coverageType.NO_COMP;
|
||||||
|
store.order.vehicle.policyVehicleId = 42;
|
||||||
|
store.issConfig.isClaimRegistrationRequired = true;
|
||||||
|
store.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(store.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -406,23 +406,26 @@ describe('coverageStatement.vue', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe.each([
|
describe.each([
|
||||||
[false, false, true, true, 0],
|
[false, false, true, true, 0, false],
|
||||||
[false, true, false, true, 0],
|
[false, true, false, true, 0, false],
|
||||||
[false, true, true, false, 0],
|
[false, true, true, false, 0, false],
|
||||||
[false, true, true, true, -1],
|
[false, true, true, true, -1, false],
|
||||||
[false, true, true, true, null],
|
[false, true, true, true, null, false],
|
||||||
[true, true, true, true, 0]
|
[false, true, true, true, 0, true],
|
||||||
|
[true, true, true, true, 0, false]
|
||||||
])('shouldRegisterClaim', (
|
])('shouldRegisterClaim', (
|
||||||
expected,
|
expected,
|
||||||
isClaimRegistrationRequired,
|
isClaimRegistrationRequired,
|
||||||
isPolicyLookupSuccessful,
|
isPolicyLookupSuccessful,
|
||||||
isPendingClaimRegistration,
|
isPendingClaimRegistration,
|
||||||
policyVehicleId
|
policyVehicleId,
|
||||||
|
callClaimRegistrationAtEnd
|
||||||
) => {
|
) => {
|
||||||
test(`returns ${expected} when isClaimRegistrationRequired is ${isClaimRegistrationRequired} `
|
test(`returns ${expected} when isClaimRegistrationRequired is ${isClaimRegistrationRequired} `
|
||||||
+ `and isPolicyLookupSuccessful is ${isPolicyLookupSuccessful} `
|
+ `and isPolicyLookupSuccessful is ${isPolicyLookupSuccessful} `
|
||||||
+ `and isPendingClaimRegistration is ${isPendingClaimRegistration} `
|
+ `and isPendingClaimRegistration is ${isPendingClaimRegistration} `
|
||||||
+ `and policyVehicleId is ${(policyVehicleId == null ? 'NULL' : policyVehicleId)}`, () => {
|
+ `and policyVehicleId is ${(policyVehicleId == null ? 'NULL' : policyVehicleId)} `
|
||||||
|
+ `and callClaimRegistrationAtEnd is ${callClaimRegistrationAtEnd}`, () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const mainInitialState = {
|
const mainInitialState = {
|
||||||
order: {
|
order: {
|
||||||
|
|
@ -435,7 +438,8 @@ describe('coverageStatement.vue', () => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
issConfig: {
|
issConfig: {
|
||||||
isClaimRegistrationRequired
|
isClaimRegistrationRequired,
|
||||||
|
callClaimRegistrationAtEnd
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,8 @@ export default {
|
||||||
vehicle,
|
vehicle,
|
||||||
isClaimRegistrationRequired,
|
isClaimRegistrationRequired,
|
||||||
isPolicyLookupSuccessful,
|
isPolicyLookupSuccessful,
|
||||||
isPendingClaimRegistration
|
isPendingClaimRegistration,
|
||||||
|
issConfig
|
||||||
} = useMainStore();
|
} = useMainStore();
|
||||||
const { policyVehicleId } = vehicle;
|
const { policyVehicleId } = vehicle;
|
||||||
return (
|
return (
|
||||||
|
|
@ -340,6 +341,7 @@ export default {
|
||||||
&& policyVehicleId >= 0
|
&& policyVehicleId >= 0
|
||||||
&& isClaimRegistrationRequired
|
&& isClaimRegistrationRequired
|
||||||
&& isPendingClaimRegistration
|
&& isPendingClaimRegistration
|
||||||
|
&& !issConfig.callClaimRegistrationAtEnd
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
isRepair() {
|
isRepair() {
|
||||||
|
|
@ -453,7 +455,7 @@ export default {
|
||||||
async initializeComponent() {
|
async initializeComponent() {
|
||||||
if (this.shouldRegisterClaim) {
|
if (this.shouldRegisterClaim) {
|
||||||
await this.mainStore.registerClaim();
|
await this.mainStore.registerClaim();
|
||||||
} else if (!this.mainStore.isClaimRegistrationRequired && this.mainStore.order.insuranceCoverage.coverageType !== coverageType.NONE) {
|
} else if ((!this.mainStore.isClaimRegistrationRequired || this.mainStore.issConfig.callClaimRegistrationAtEnd) && this.mainStore.order.insuranceCoverage.coverageType !== coverageType.NONE) {
|
||||||
this.mainStore.updateCoverageStatus(coverageStatuses.VERIFIED);
|
this.mainStore.updateCoverageStatus(coverageStatuses.VERIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue