INSR-523: Fix some unit test issues caught by copilot
- Add space to a test name - Add unit tests for change to submitWorkOrder
This commit is contained in:
parent
ec67c21b40
commit
658efb063a
2 changed files with 145 additions and 1 deletions
144
src/helpers/order-helper.spec.js
Normal file
144
src/helpers/order-helper.spec.js
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
import { submitWorkOrder } from '@/helpers/order-helper';
|
||||||
|
|
||||||
|
let mockStore;
|
||||||
|
|
||||||
|
jest.mock('@/store', () => ({
|
||||||
|
useMainStore: jest.fn(() => mockStore)
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('order-helper.js', () => {
|
||||||
|
describe('submitWorkOrder', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockStore = {
|
||||||
|
resetSubmittedOrder: jest.fn(),
|
||||||
|
createSubmittedOrder: jest.fn(() => Promise.resolve()),
|
||||||
|
registerClaim: jest.fn(() => Promise.resolve()),
|
||||||
|
isPolicyLookupSuccessful: false,
|
||||||
|
vehicle: {
|
||||||
|
policyVehicleId: null
|
||||||
|
},
|
||||||
|
isClaimRegistrationRequired: false,
|
||||||
|
issConfig: {
|
||||||
|
callClaimRegistrationAtEnd: false
|
||||||
|
},
|
||||||
|
applicationUser: {
|
||||||
|
saveSessionPromise: null
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
referralNumber: null
|
||||||
|
},
|
||||||
|
saveSession: jest.fn(() => Promise.resolve({ data: { referralNumber: 'REF-001' } })),
|
||||||
|
setSaveSessionInfo: jest.fn(),
|
||||||
|
setSaveSessionPromise: jest.fn()
|
||||||
|
};
|
||||||
|
|
||||||
|
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(mockStore.resetSubmittedOrder).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockStore.saveSession).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockStore.saveSession).toHaveBeenCalledWith({
|
||||||
|
submitAfterSave: true,
|
||||||
|
createWorkOrderNumberForPIA: false,
|
||||||
|
bailoutOnError: true
|
||||||
|
});
|
||||||
|
expect(mockStore.setSaveSessionPromise).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockStore.setSaveSessionInfo).toHaveBeenCalledWith({ referralNumber: 'REF-001' });
|
||||||
|
expect(mockStore.createSubmittedOrder).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockStore.createSubmittedOrder).toHaveBeenCalledWith(submitType);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Registers claim when all claim registration conditions are met', async () => {
|
||||||
|
// Arrange
|
||||||
|
mockStore.isPolicyLookupSuccessful = true;
|
||||||
|
mockStore.vehicle.policyVehicleId = 42;
|
||||||
|
mockStore.isClaimRegistrationRequired = true;
|
||||||
|
mockStore.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(mockStore.registerClaim).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when policy lookup is not successful', async () => {
|
||||||
|
// Arrange
|
||||||
|
mockStore.isPolicyLookupSuccessful = false;
|
||||||
|
mockStore.vehicle.policyVehicleId = 42;
|
||||||
|
mockStore.isClaimRegistrationRequired = true;
|
||||||
|
mockStore.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(mockStore.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when policyVehicleId is null', async () => {
|
||||||
|
// Arrange
|
||||||
|
mockStore.isPolicyLookupSuccessful = true;
|
||||||
|
mockStore.vehicle.policyVehicleId = null;
|
||||||
|
mockStore.isClaimRegistrationRequired = true;
|
||||||
|
mockStore.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(mockStore.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when policyVehicleId is negative', async () => {
|
||||||
|
// Arrange
|
||||||
|
mockStore.isPolicyLookupSuccessful = true;
|
||||||
|
mockStore.vehicle.policyVehicleId = -1;
|
||||||
|
mockStore.isClaimRegistrationRequired = true;
|
||||||
|
mockStore.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(mockStore.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when claim registration is not required', async () => {
|
||||||
|
// Arrange
|
||||||
|
mockStore.isPolicyLookupSuccessful = true;
|
||||||
|
mockStore.vehicle.policyVehicleId = 42;
|
||||||
|
mockStore.isClaimRegistrationRequired = false;
|
||||||
|
mockStore.issConfig.callClaimRegistrationAtEnd = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(mockStore.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not register claim when claim registration is disabled in config', async () => {
|
||||||
|
// Arrange
|
||||||
|
mockStore.isPolicyLookupSuccessful = true;
|
||||||
|
mockStore.vehicle.policyVehicleId = 42;
|
||||||
|
mockStore.isClaimRegistrationRequired = true;
|
||||||
|
mockStore.issConfig.callClaimRegistrationAtEnd = false;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await submitWorkOrder({ submitType: 'SUBMIT' });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(mockStore.registerClaim).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -424,7 +424,7 @@ describe('coverageStatement.vue', () => {
|
||||||
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}`, () => {
|
+ `and callClaimRegistrationAtEnd is ${callClaimRegistrationAtEnd}`, () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const mainInitialState = {
|
const mainInitialState = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue