Updated unit tests.
This commit is contained in:
parent
086b1726ac
commit
283553fbf4
1 changed files with 62 additions and 12 deletions
|
|
@ -150,11 +150,13 @@ describe('navigation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When zip code check succeeds', () => {
|
describe('When zip code check succeeds', () => {
|
||||||
test('if duplicates found, navigate to duplicate check page', async () => {
|
test('if duplicates found, NOT loaded from cookie, and NOT visited duplicate check page, navigate to duplicate check page', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
useMainStore().getDuplicateReferrals = jest.fn().mockImplementation(() => Promise.resolve({}));
|
useMainStore().getDuplicateReferrals = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||||
useMainStore().applicationUser.duplicateOrders = [{ test: 'a' }];
|
useMainStore().applicationUser.duplicateOrders = [{ test: 'a' }];
|
||||||
|
useMainStore().order.loadedFromCookie = false;
|
||||||
|
useMainStore().order.visitedDuplicateCheckPage = false;
|
||||||
wrapper.vm.mainStore.validateZip = jest.fn().mockImplementation(() => Promise.resolve({
|
wrapper.vm.mainStore.validateZip = jest.fn().mockImplementation(() => Promise.resolve({
|
||||||
data: {
|
data: {
|
||||||
isValid: true
|
isValid: true
|
||||||
|
|
@ -173,6 +175,58 @@ describe('navigation', () => {
|
||||||
{ [routerParams.SKIP_SAVE_SESSION]: true }
|
{ [routerParams.SKIP_SAVE_SESSION]: true }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
test('if duplicates found but loadedFromCookie is true, skip duplicate check and navigate to policy verified path', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
useMainStore().getDuplicateReferrals = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||||
|
useMainStore().applicationUser.duplicateOrders = [{ test: 'a' }];
|
||||||
|
useMainStore().order.loadedFromCookie = true;
|
||||||
|
useMainStore().order.visitedDuplicateCheckPage = false;
|
||||||
|
useMainStore().order.insuranceCoverage.coverageType = coverageType.Deductible;
|
||||||
|
useMainStore().order.policy.vehicles = [{ vin: 'TEST_VIN' }];
|
||||||
|
wrapper.vm.mainStore.validateZip = jest.fn().mockImplementation(() => Promise.resolve({
|
||||||
|
data: {
|
||||||
|
isValid: true
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES,
|
||||||
|
undefined,
|
||||||
|
{},
|
||||||
|
{ [routerParams.SKIP_SAVE_SESSION]: true }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test('if duplicates found but visitedDuplicateCheckPage is true, skip duplicate check and navigate to policy verified path', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
useMainStore().getDuplicateReferrals = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||||
|
useMainStore().applicationUser.duplicateOrders = [{ test: 'a' }];
|
||||||
|
useMainStore().order.loadedFromCookie = false;
|
||||||
|
useMainStore().order.visitedDuplicateCheckPage = true;
|
||||||
|
useMainStore().order.insuranceCoverage.coverageType = coverageType.Deductible;
|
||||||
|
useMainStore().order.policy.vehicles = [{ vin: 'TEST_VIN' }];
|
||||||
|
wrapper.vm.mainStore.validateZip = jest.fn().mockImplementation(() => Promise.resolve({
|
||||||
|
data: {
|
||||||
|
isValid: true
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES,
|
||||||
|
undefined,
|
||||||
|
{},
|
||||||
|
{ [routerParams.SKIP_SAVE_SESSION]: true }
|
||||||
|
);
|
||||||
|
});
|
||||||
test('if policy and vehicles are found but no duplicates, navigate to policy-vehicle page', async () => {
|
test('if policy and vehicles are found but no duplicates, navigate to policy-vehicle page', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
@ -277,26 +331,22 @@ describe('navigation', () => {
|
||||||
{ [routerParams.SKIP_SAVE_SESSION]: true }
|
{ [routerParams.SKIP_SAVE_SESSION]: true }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('getDuplicateReferrals throws rejected promise => navigate called', async () => {
|
test('getDuplicateReferrals throws rejected promise => error propagates', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
const error = 'duplicate referrals error';
|
const error = new Error('duplicate referrals error');
|
||||||
useMainStore().getDuplicateReferrals = jest.fn().mockImplementation(() => Promise.reject(error));
|
useMainStore().getDuplicateReferrals = jest.fn().mockImplementation(() => Promise.reject(error));
|
||||||
|
useMainStore().order.loadedFromCookie = false;
|
||||||
|
useMainStore().order.visitedDuplicateCheckPage = false;
|
||||||
wrapper.vm.mainStore.validateZip = jest.fn().mockImplementation(() => Promise.resolve({
|
wrapper.vm.mainStore.validateZip = jest.fn().mockImplementation(() => Promise.resolve({
|
||||||
data: {
|
data: {
|
||||||
isValid: true
|
isValid: true
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
|
await expect(wrapper.vm.forwardButtonAction()).rejects.toEqual(error);
|
||||||
// Assert
|
expect(wrapper.vm.$router.navigate).not.toHaveBeenCalled();
|
||||||
expect.assertions(1);
|
|
||||||
try {
|
|
||||||
await wrapper.vm.forwardButtonAction();
|
|
||||||
} catch (e) {
|
|
||||||
expect(e).toMatch(error);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue