Adding tests

This commit is contained in:
Michaela Brydon 2024-04-12 13:20:49 -04:00
parent e3852f2b7b
commit 1e80a0b486
4 changed files with 387 additions and 204 deletions

View file

@ -313,115 +313,6 @@ describe('cart-dropdown component', () => {
});
});
describe('computed', () => {
describe('isUnverified', () => {
test('returns false when no comp', () => {
// Arrange
const storeData = {
order: {
policy: {
isITAC: false,
noCoverage: true
},
currentDeductible: null
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeFalsy();
});
test('returns false when itac', () => {
// Arrange
const storeData = {
order: {
payment: {
insuranceCoverage: {
coverageStatus: coverageStatuses.PENDING
}
},
policy: {
isITAC: true
},
currentDeductible: null
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeFalsy();
});
test('returns false when deductible not null and verified coverage status', () => {
// Arrange
const storeData = {
order: {
payment: {
insuranceCoverage: {
coverageStatus: coverageStatuses.VERIFIED
}
},
policy: {
isITAC: false
},
currentDeductible: 23
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeFalsy();
});
test('returns true when not no comp, not itac, and deductible is null', () => {
// Arrange
const storeData = {
order: {
policy: {
isITAC: false,
noCoverage: false
},
currentDeductible: null
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeTruthy();
});
test('returns true when not no comp, not itac, and coverage status is not verified', () => {
// Arrange
const storeData = {
order: {
payment: {
insuranceCoverage: {
coverageStatus: coverageStatuses.PENDING
}
},
policy: {
isITAC: false
},
currentDeductible: 12
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeTruthy();
});
});
describe('amountDue', () => {
test('returns 0 when showAsPaid is true', () => {
// Arrange
@ -556,15 +447,22 @@ describe('cart-dropdown component', () => {
// Arrange
const storeData = {
order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: {
glassParts: null,
otherParts: null,
supportingItems: null,
vaps: null
},
payment: {
insuranceCoverage: { isVerified: true }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
@ -578,6 +476,8 @@ describe('cart-dropdown component', () => {
// Arrange
const storeData = {
order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: {
glassParts: [
{ partType: 'mock', salesTax: null },
@ -591,7 +491,13 @@ describe('cart-dropdown component', () => {
{ partType: 'mock', salesTax: null },
{ partType: 'mock', salesTax: undefined }
]
},
payment: {
insuranceCoverage: { isVerified: true }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData);
@ -606,6 +512,8 @@ describe('cart-dropdown component', () => {
// Arrange
const storeData = {
order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: {
glassParts: [{ partType: 'mock', salesTax: 10 }],
supportingItems: [
@ -619,10 +527,11 @@ describe('cart-dropdown component', () => {
vaps: []
},
payment: {
insuranceCoverage: {
isVerified: false
}
insuranceCoverage: { isVerified: false }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData);
@ -636,15 +545,25 @@ describe('cart-dropdown component', () => {
test('Returns sum of vaps sales tax when coverage is unverified and order has vaps.', () => {
// Arrange
const storeData = useMainStore().$state;
storeData.order.lineItems.glassParts = [
{ partType: 'mock', salesTax: 10 }
];
storeData.order.lineItems.vaps = [
{ partType: 'mock', salesTax: 1 },
{ partType: 'mock', salesTax: 2 }
];
storeData.order.payment.insuranceCoverage.isVerified = false;
const storeData = {
order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: {
glassParts: [{ partType: 'mock', salesTax: 10 }],
vaps: [
{ partType: 'mock', salesTax: 1 },
{ partType: 'mock', salesTax: 2 }
]
},
payment: {
insuranceCoverage: { isVerified: false }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData);
@ -657,16 +576,30 @@ describe('cart-dropdown component', () => {
test('Returns Recycle Fee tax when coverage is Verified-Deductible, replace service, and no vaps.', () => {
// Arrange
const storeData = useMainStore().$state;
storeData.order.currentDeductible = 250;
storeData.order.lineItems.glassParts = [
{ partType: 'mock', salesTax: 10, sellingPrice: 150 }
];
storeData.order.lineItems.supportingItems = [
{ partNumber: partNumberStrings.RECYCLE_FEE, partType: 'mock', salesTax: 10, sellingPrice: 39.99 }
];
storeData.order.lineItems.vaps = null;
storeData.order.payment.insuranceCoverage.isVerified = true;
const storeData = {
order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: {
glassParts: [{ partType: 'mock', salesTax: 10, sellingPrice: 150 }],
supportingItems: [
{
partNumber: partNumberStrings.RECYCLE_FEE,
partType: 'mock',
salesTax: 10,
sellingPrice: 39.99
}
],
vaps: null
},
payment: {
insuranceCoverage: { isVerified: true }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData);
@ -679,24 +612,30 @@ describe('cart-dropdown component', () => {
test('Returns sum of vaps + recycle fee sales tax when Verified-Deductible, replace service, and has vaps.', () => {
// Arrange
const storeData = useMainStore().$state;
storeData.order.currentDeductible = 250;
storeData.order.lineItems.glassParts = [
{ partType: 'mock', salesTax: 10, sellingPrice: 100 }
];
storeData.order.lineItems.otherParts = [
{ partType: 'mock', salesTax: 10, kitPrice: 100 }
];
storeData.order.lineItems.supportingItems = [
{ partNumber: partNumberStrings.RECYCLE_FEE, partType: 'mock', salesTax: 10, sellingPrice: 39.99 },
{ partType: 'mock', salesTax: 10, kitPrice: 100 }
];
storeData.order.lineItems.vaps = [
{ partType: 'mock', salesTax: 2 },
{ partType: 'mock', salesTax: 3 }
];
storeData.order.payment.insuranceCoverage.isVerified = true;
const storeData = {
order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: {
glassParts: [{ partType: 'mock', salesTax: 10, sellingPrice: 100 }],
otherParts: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
supportingItems: [
{ partNumber: partNumberStrings.RECYCLE_FEE, partType: 'mock', salesTax: 10, sellingPrice: 39.99 },
{ partType: 'mock', salesTax: 10, kitPrice: 100 }
],
vaps: [
{ partType: 'mock', salesTax: 2 },
{ partType: 'mock', salesTax: 3 }
]
},
payment: {
insuranceCoverage: { isVerified: true }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
@ -708,23 +647,27 @@ describe('cart-dropdown component', () => {
test('Returns sum of sales tax when Verified-ITAC.', () => {
// Arrange
const storeData = useMainStore().$state;
storeData.order.currentDeductible = 0;
storeData.order.lineItems.glassParts = [
{ partType: 'mock', salesTax: 10, sellingPrice: 100 }
];
storeData.order.lineItems.otherParts = [
{ partType: 'mock', salesTax: 10, kitPrice: 100 }
];
storeData.order.lineItems.supportingItems = [
{ partType: 'mock', salesTax: 10, kitPrice: 100 }
];
storeData.order.lineItems.vaps = [
{ partType: 'mock', salesTax: 5 }
];
storeData.order.payment.insuranceCoverage.isVerified = true;
storeData.order.policy.isITAC = true;
const storeData = {
order: {
policyLookupSuccessful: true,
currentDeductible: 0,
lineItems: {
glassParts: [{ partType: 'mock', salesTax: 10, sellingPrice: 100 }],
otherParts: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
supportingItems: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
vaps: [{ partType: 'mock', salesTax: 5 }]
},
payment: {
insuranceCoverage: { isVerified: true }
},
policy: {
isITAC: true
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
@ -736,23 +679,28 @@ describe('cart-dropdown component', () => {
test('Returns sum of sales tax when Verified-NoComp.', () => {
// Arrange
const storeData = useMainStore().$state;
storeData.order.currentDeductible = 0;
storeData.order.lineItems.glassParts = [
{ partType: 'mock', salesTax: 10, sellingPrice: 100 }
];
storeData.order.lineItems.otherParts = [
{ partType: 'mock', salesTax: 10, kitPrice: 100 }
];
storeData.order.lineItems.supportingItems = [
{ partType: 'mock', salesTax: 10, kitPrice: 100 }
];
storeData.order.lineItems.vaps = [
{ partType: 'mock', salesTax: 5 }
];
storeData.order.payment.insuranceCoverage.isVerified = true;
storeData.order.policy.noCoverage = true;
const storeData = {
order: {
policyLookupSuccessful: true,
currentDeductible: 0,
lineItems: {
glassParts: [{ partType: 'mock', salesTax: 10, sellingPrice: 100 }],
otherParts: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
supportingItems: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
vaps: [{ partType: 'mock', salesTax: 5 }]
},
payment: {
insuranceCoverage: { isVerified: true }
},
policy: {
noCoverage: true
}
},
issConfig: {
isClaimRegistrationRequired: true,
enableNoCompQuote: true
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
@ -1791,21 +1739,19 @@ describe('cart-dropdown component', () => {
// Arrange
const storeData = {
order: {
payment: {
insuranceCoverage: {
coverageStatus: coverageStatuses.VERIFIED
}
},
policy: {
isITAC: false
isITAC: false,
isNoComp: false
},
currentDeductible: 321
currentDeductible: 321,
policyLookupSuccessful: true
}
};
const { wrapper } = getMountedComponent(storeData);
const amount = 123;
const dollarAmount = '$84.00';
formatAmountInDollars.mockImplementationOnce(() => dollarAmount);
formatAmountInDollars
.mockImplementationOnce((value) => (value === amount ? dollarAmount : 1));
// Act
const result = wrapper.vm.getDisplayed(amount);

View file

@ -3,20 +3,28 @@ import paymentMethod from '@/layouts/payment-method/payment-method.vue';
// Supporting Files
import { shallowMount } from '@vue/test-utils';
import { createTestingPinia } from '@pinia/testing';
import { getMountOptions } from '@/helpers/unit-test-helper.js';
import { useMainStore } from '@/store';
import { useMainStore, getDefaultState } from '@/store';
import issPageValues from '@/router/router-constants/issPage-values';
import { paymentMethods } from '@/constants/payment-method-constants';
import queryStrings from '@/constants/query-strings';
import { experimentSettings } from '@/constants/experiments';
function setupMocks({ customMountOptions = {}, queryString }) {
function setupMocks({ customMountOptions = {}, queryString }, mainInitialState = {}, customMixin = null) {
const mountOptions = getMountOptions({
...customMountOptions,
route: { query: { issPage: issPageValues.PAYMENT_METHOD, ...queryString }, params: {} }
});
const mockMixin = {
const testingPinia = createTestingPinia({
initialState: {
main: mainInitialState
}
});
useMainStore(testingPinia);
const mockMixin = customMixin ?? {
methods: {
getSettingValue: jest.fn((settingName) => {
if (settingName === experimentSettings.ISS_DISPLAY_PAY_IN_ADVANCE) {
@ -28,6 +36,7 @@ function setupMocks({ customMountOptions = {}, queryString }) {
}
};
mountOptions.global.plugins = [testingPinia];
mountOptions.global.mixins = [mockMixin];
const wrapper = shallowMount(paymentMethod, mountOptions);
@ -35,13 +44,28 @@ function setupMocks({ customMountOptions = {}, queryString }) {
return wrapper;
}
beforeEach(() => {
const store = useMainStore();
const defaultState = getDefaultState();
Object.keys(defaultState).forEach((key) => {
store[key] = defaultState[key];
});
});
describe('payment-method.vue', () => {
describe('Payment Method Type', () => {
test('getting payment method when method is pay later', async () => {
// Arrange
const wrapper = setupMocks({});
// Arrange
const payLaterPaymentMethod = paymentMethods.PAY_AT_TIME_OF_SERVICE;
useMainStore().savePaymentMethodChoice(payLaterPaymentMethod);
const store = {
order: {
payment: {
isPayInAdvance: true,
payInAdvanceType: payLaterPaymentMethod
}
}
};
const wrapper = setupMocks({}, store);
// Act
const paymethod = wrapper.vm.getPaymentMethodFromStore();
@ -50,16 +74,22 @@ describe('payment-method.vue', () => {
expect(paymethod).toBe(payLaterPaymentMethod);
});
test('getting payment method when method is pay in advance', async () => {
// Arrange
const wrapper = setupMocks({});
const payInAdvancePaymentMethod = paymentMethods.CREDIT_CARD;
useMainStore().savePaymentMethodChoice(payInAdvancePaymentMethod);
// Arrange
const store = {
order: {
payment: {
isPayInAdvance: false,
payInAdvanceType: null
}
}
};
const wrapper = setupMocks({}, store);
// Act
const paymethod = wrapper.vm.getPaymentMethodFromStore();
// Assert
expect(paymethod).not.toBe(payInAdvancePaymentMethod);
expect(paymethod).toBeNull();
});
});
@ -86,4 +116,138 @@ describe('payment-method.vue', () => {
expect(payInAdvanceErrorAlert.exists()).toBeFalsy();
});
});
describe('isPayInAdvanceDisabled', () => {
let store = {};
let mixin = {
methods: {
getSettingValue: jest.fn((settingName) => {
if (settingName === experimentSettings.ISS_DISPLAY_PAY_IN_ADVANCE) {
return 'true';
}
return 'false';
})
}
};
beforeEach(() => {
store = {
order: {
policy: {
isITAC: false,
noCoverage: false
},
payment: {
insuranceCoverage: {
isVerified: true
}
},
currentDeductible: 123,
policyLookupSuccessful: true
},
issConfig: {
isClaimRegistrationRequired: true,
enableNoCompQuote: true
},
applicationUser: {
experiments: [
{
settings: {
ISSDisplayPIAInsurance_ISS: 'true'
}
}
]
}
};
});
test('returns true when policyLookupSuccessful false', () => {
// Arrange
store.order.policyLookupSuccessful = false;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
test('returns true when no comp and enableNoCompQuote false', () => {
// Arrange
store.order.policy.noCoverage = true;
store.issConfig.enableNoCompQuote = false;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
test('returns true when not no comp and currentDeductible null', () => {
// Arrange
store.order.policy.noCoverage = false;
store.order.currentDeductible = null;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
test('returns true when isClaimRegistrationRequired true and insurance coverage not verified', () => {
// Arrange
store.order.payment.insuranceCoverage.isVerified = false;
store.issConfig.isClaimRegistrationRequired = true;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
test('returns false when no comp, enableNoCompQuote true, and currentDeductible null and pia enabled', () => {
// Arrange
store.order.policy.noCoverage = true;
store.issConfig.enableNoCompQuote = true;
store.order.currentDeductible = null;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeFalsy();
});
test('returns false when not no comp, currentDeductible not null and pia enabled', () => {
// Arrange
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeFalsy();
});
test('returns true when pia not enabled', () => {
// Arrange
mixin = {
methods: {
getSettingValue: jest.fn((settingName) => {
if (settingName === experimentSettings.ISS_DISPLAY_PAY_IN_ADVANCE) {
return 'false';
}
return 'true';
})
}
};
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
});
});

View file

@ -270,7 +270,7 @@ export const useMainStore = defineStore({
isITAC: (state) => !!state.order.policy.isITAC,
isUnverified: (s) => {
const { policyLookupSuccessful, payment, currentDeductible } = s.order;
const registerClaimSuccessful = payment.insuranceCoverage.isVerified;
const registerClaimSuccessful = !!payment.insuranceCoverage.isVerified;
if (!policyLookupSuccessful) {
return true;
}

View file

@ -1438,6 +1438,79 @@ describe('Store', () => {
});
});
describe('isUnverified', () => {
beforeEach(() => {
store.order.policy.isITAC = false;
store.order.policy.noCoverage = false;
store.order.payment.insuranceCoverage.isVerified = true;
store.order.currentDeductible = 123;
store.order.policyLookupSuccessful = true;
store.issConfig.isClaimRegistrationRequired = true;
store.issConfig.enableNoCompQuote = true;
});
it('returns true when policyLookupSuccessful false', () => {
// Arrange
store.order.policyLookupSuccessful = false;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeTruthy();
});
it('returns true when no comp and enableNoCompQuote false', () => {
// Arrange
store.order.policy.noCoverage = true;
store.issConfig.enableNoCompQuote = false;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeTruthy();
});
it('returns true when not no comp and currentDeductible null', () => {
// Arrange
store.order.policy.noCoverage = false;
store.order.currentDeductible = null;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeTruthy();
});
it('returns true when isClaimRegistrationRequired true and insurance coverage not verified', () => {
// Arrange
store.order.payment.insuranceCoverage.isVerified = false;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeTruthy();
});
it('returns false when no comp, enableNoCompQuote true, and currentDeductible null', () => {
// Arrange
store.order.policy.noCoverage = true;
store.order.currentDeductible = null;
store.issConfig.enableNoCompQuote = true;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeFalsy();
});
it('returns false when not no comp, currentDeductible not null', () => {
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeFalsy();
});
});
describe('isMobileAppointment', () => {
it('Should return true for mobile appointments', () => {
// Arrange