import { setActivePinia, createPinia } from 'pinia'; import { useMainStore } from '@/store/index.js'; import globalMethods from '@/global-methods.js'; import { getRandomString, getRandomGuid, getRandomInt, getRandomBoolean } from '@/helpers/data-generation.js'; import coverageStatuses from '@/constants/coverage-statuses.js'; import { endpoints } from '@/constants/endpoints'; import { AppointmentTypeStrings } from '@/constants/schedule-constants'; describe('Store', () => { let store; beforeEach(() => { const pinia = createPinia(); setActivePinia(pinia); store = useMainStore(); store.applicationUser.eventBus = []; jest.resetAllMocks(); }); it('Should Store Vehicle Year', () => { const testYear = '2001'; store.updateVehicleYear(testYear); expect(store.order.vehicle.year).toEqual(testYear); }); it('Should add events to the bus', () => { // Arrange const category = getRandomString(1, 25); const subCategory = getRandomString(5, 20); const isDismissible = getRandomBoolean(); const copy = getRandomString(5, 25); const headline = getRandomString(5, 25); const type = getRandomString(5, 15); const event = { category, subCategory, eventValue: { isDismissible, messageCopy: copy, messageHeadline: headline, type } }; // Act store.addEventToBus(event); // Assert expect(store.applicationUser.eventBus[0]).toEqual(event); }); it('Should remove events from the bus', () => { // Arrange const category = getRandomString(1, 25); const subCategory = getRandomString(5, 20); const isDismissible = getRandomBoolean(); const copy = getRandomString(5, 25); const headline = getRandomString(5, 25); const type = getRandomString(5, 15); const event = { category, subCategory, eventValue: { isDismissible, messageCopy: copy, messageHeadline: headline, type } }; store.addEventToBus(event); expect(store.applicationUser.eventBus.length).toBe(1); // Act store.removeEventFromBus({ category: event.category, subCategory: event.subCategory }); // Assert expect(store.applicationUser.eventBus.length).toBe(0); }); it('Should return correct event using the getter function eventBusItem', () => { // Arrange const category = getRandomString(1, 25); const subCategory = getRandomString(5, 20); const isDismissible = getRandomBoolean(); const copy = getRandomString(5, 25); const headline = getRandomString(5, 25); const type = getRandomString(5, 15); const event = { category, subCategory, eventValue: { isDismissible, messageCopy: copy, messageHeadline: headline, type } }; store.addEventToBus(event); // Act const actual = store.eventBusItem(event.category, event.subCategory); // Assert expect(actual).toEqual(event.eventValue); }); it('UpdateVehicle should merge vehicle with response object', () => { // Arrange const carId = getRandomString(10, 14); const category = getRandomString(3, 7); const year = getRandomInt(1960, 2023); const make = getRandomString(4, 10); const model = getRandomString(4, 10); const style = getRandomString(4, 15); const imageUrl = getRandomString(50, 100); const imageVifNumber = getRandomInt(10000, 99999).toString(); const imageColor = getRandomString(4, 10); const providedVehicle = { carId, category, year, make, model, style, imageUrl, imageVifNumber, imageVifColor: imageColor }; const expectedVehicle = { carId, category, year, make, model, style, imageUrl, imageVifNumber, imageColor }; // Act store.updateVehicle(providedVehicle); // Assert expect(store.order.vehicle).toMatchObject(expectedVehicle); }); it('UpdateVehicle should set policy values appropriately with repair waived', () => { // Arrange const noCoverage = getRandomBoolean(); const deductible = getRandomInt(1, 500); const endorsements = [getRandomString(10, 20)]; const vehicle = { noCoverage, deductible, repairWaived: true, endorsements }; const expectedPolicy = { noCoverage, deductible: { replace: deductible, repair: 0 }, endorsements }; // Act store.updateVehicle(vehicle); // Assert expect(store.order.policy).toMatchObject(expectedPolicy); }); it('UpdateVehicle should set policy values appropriately with repair not waived', () => { // Arrange const noCoverage = getRandomBoolean(); const deductible = getRandomInt(1, 500); const endorsements = [getRandomString(10, 20)]; const vehicle = { noCoverage, deductible, repairWaived: false, endorsements }; const expectedPolicy = { noCoverage, deductible: { replace: deductible, repair: deductible }, endorsements }; // Act store.updateVehicle(vehicle); // Assert expect(store.order.policy).toMatchObject(expectedPolicy); }); it.each([ [true, coverageStatuses.NO_COMP], [false, coverageStatuses.PENDING] ])( 'UpdateVehicle should set coverageStatus appropriately based on noCoverage value', (expectedNoCoverage, expectedCoverageStatus) => { // Arrange const vehicle = { noCoverage: expectedNoCoverage }; // Act store.updateVehicle(vehicle); // Assert expect(store.order.policy.noCoverage).toBe(expectedNoCoverage); expect(store.order.payment.insuranceCoverage.coverageStatus).toBe(expectedCoverageStatus); } ); // TODO update test to work also checking store values it('setVehicle should call globalMethods.callHttpClient', () => { // Arrange const carId = getRandomString(10, 14); const category = getRandomString(3, 7); const year = getRandomInt(1960, 2023); const make = getRandomString(4, 10); const model = getRandomString(4, 10); const style = getRandomString(4, 15); const imageUrl = getRandomString(50, 100); const imageVifNumber = getRandomInt(10000, 99999).toString(); const imageColor = getRandomString(4, 10); const response = { data: { carId, category, year, make, model, style, imageUrl, imageVifNumber, imageVifColor: imageColor } }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act const returned = store.setVehicle(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalled(); expect(returned).resolves.toMatchObject(response); }); it('saveVehicleDamage with windshield repair should update damage with number of chips not null', () => { // Arrange const glassName = getRandomString(4, 10); const glassLocation = getRandomString(5, 15); const isWindshieldRepair = true; const selectedGlassToReplace = [{ glassName, glassLocation }]; const chipCount = getRandomInt(0, 3); // Act store.saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, chipCount); // Assert expect(store.order.damage.glassToReplace).toEqual(selectedGlassToReplace); expect(store.order.damage.isRepair).toEqual(isWindshieldRepair); expect(store.order.damage.numberOfChips).toEqual(chipCount); }); it('saveVehicleDamage without windshield repair should update damage with number of chips null', () => { // Arrange const glassName = getRandomString(4, 10); const glassLocation = getRandomString(5, 15); const isWindshieldRepair = false; const selectedGlassToReplace = [{ glassName, glassLocation }]; const chipCount = getRandomInt(0, 3); const expectedChipCount = null; // Act store.saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, chipCount); // Assert expect(store.order.damage.glassToReplace).toEqual(selectedGlassToReplace); expect(store.order.damage.isRepair).toEqual(isWindshieldRepair); expect(store.order.damage.numberOfChips).toEqual(expectedChipCount); }); it('should return registration data if available', () => { // Arrange const streetAddress = getRandomString(5, 15); const city = getRandomString(5, 15); const state = getRandomString(5, 10); const zipCode = getRandomInt(10000, 99999).toString(); const firstName = getRandomString(5, 20); const lastName = getRandomString(5, 20); const expected = { addressQuestions: { streetAddress, city, state, zipCode }, firstName, lastName }; store.order.vehicle.registration = { licensePlate: null, address: streetAddress, city, state, zipCode, firstName, lastName }; // Act const actual = store.customerData; // Assert expect(actual).toEqual(expected); }); it('should return customer data if registration data unavailable', () => { // Arrange const address = getRandomString(1, 25); const city = getRandomString(5, 20); const state = getRandomString(4, 20); const zipCode = getRandomInt(10000, 99999).toString(); const firstName = getRandomString(5, 25); const lastName = getRandomString(5, 25); const expected = { addressQuestions: { streetAddress: address, city, state, zipCode }, firstName, lastName }; store.order.vehicle.registration.address = null; store.order.customer = { address: { streetAddress: address, city, state, zipCode }, firstName, lastName }; // Act const actual = store.customerData; // Assert expect(actual).toMatchObject(expected); }); describe('registerClaim method', () => { it('successful response with no coverage => isVerified true and coverage status no comp', async () => { // Arrange const response = { data: { claimantId: null, claimNumber: getRandomString(9, 9), referralCorrelationId: getRandomGuid(), isSuccess: true, isError: false, successMessage: getRandomString(9, 9), deductible: 0 } }; store.policy.noCoverage = true; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act await store.registerClaim(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalled(); expect(store.payment.insuranceCoverage.isVerified).toBe(true); expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.NO_COMP); expect(store.payment.insuranceCoverage.claimNumber).toBe(null); }); it('successful response with coverage => isVerified true and coverage status verified', async () => { // Arrange const response = { data: { claimantId: null, claimNumber: getRandomString(9, 9), referralCorrelationId: getRandomGuid(), isSuccess: true, isError: false, successMessage: getRandomString(9, 9), deductible: 0 } }; store.policy.noCoverage = false; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act await store.registerClaim(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalled(); expect(store.payment.insuranceCoverage.isVerified).toBe(true); expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.VERIFIED); expect(store.payment.insuranceCoverage.claimNumber).toBe(response.data.claimNumber); }); it('Call to client returns exception, resulting in object with error property being returned', async () => { // Arrange expect.assertions(5); const error = 'register claim error'; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); // Act await store.registerClaim().catch((e) => { expect(e).toEqual(error); }); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalled(); expect(store.payment.insuranceCoverage.isVerified).toBe(false); expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.PENDING); expect(store.payment.insuranceCoverage.claimNumber).toBe(null); }); }); describe('updateContactInfo method', () => { it('UpdateContactInfo updates contact info in store', () => { // Arrange const firstName = getRandomString(4, 10); const lastName = getRandomString(5, 15); const emailAddress = false; const phoneNumber = getRandomInt(1000000000, 9999999999); const requestTextUpdates = getRandomBoolean(); const notesForTechnician = getRandomString(50, 150); // Act store.updateContactInfo({ firstName, lastName, emailAddress, phoneNumber, requestTextUpdates, notesForTechnician }); // Assert expect(store.contactInfo.firstName).toEqual(firstName); expect(store.contactInfo.lastName).toEqual(lastName); expect(store.contactInfo.emailAddress).toEqual(emailAddress); expect(store.contactInfo.phoneNumber).toEqual(phoneNumber); expect(store.contactInfo.requestTextUpdates).toEqual(requestTextUpdates); expect(store.contactInfo.notesForTechnician).toEqual(notesForTechnician); }); it('All null values => contact info set in store to all nulls', () => { // Act store.updateContactInfo({}); // Assert expect(store.contactInfo.firstName).toEqual(''); expect(store.contactInfo.lastName).toEqual(''); expect(store.contactInfo.emailAddress).toEqual(''); expect(store.contactInfo.phoneNumber).toEqual(''); expect(store.contactInfo.requestTextUpdates).toEqual(false); expect(store.contactInfo.notesForTechnician).toEqual(''); }); }); describe('saveSession method', () => { describe('successful method call', () => { it('calls save session api endpoint', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ method: endpoints.SaveSession.method, endpoint: endpoints.SaveSession.url })); }); it('Returns expected response object', async () => { // Arrange const response = { ReferralNumber: getRandomString(6, 6) }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act const result = store.saveSession(); // Asserts await expect(result).resolves.toBe(response); }); it('calls api with expected application user data', async () => { // Arrange const crmCustomerId = getRandomString(6, 6); const experiments = getRandomString(6, 6); const lastPageVisited = getRandomString(6, 6); const pageData = getRandomString(6, 6); const savedSessionId = getRandomString(6, 6); store.applicationUser.crmCustomerId = crmCustomerId; store.applicationUser.experiments = experiments; store.applicationUser.lastPageVisited = lastPageVisited; store.applicationUser.pageData = pageData; store.applicationUser.savedSessionId = savedSessionId; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ applicationUser: expect.objectContaining({ crmCustomerId, experiments, lastPage: lastPageVisited, pageData, savedSessionId }) }) })); }); it('calls api with expected vehicle', async () => { const year = getRandomString(6, 6); const make = getRandomString(6, 6); const model = getRandomString(6, 6); const style = getRandomString(6, 6); const carId = getRandomString(6, 6); const vin = getRandomString(6, 6); const licensePlate = getRandomString(6, 6); store.order.vehicle.year = year; store.order.vehicle.make = make; store.order.vehicle.model = model; store.order.vehicle.style = style; store.order.vehicle.carId = carId; store.order.vehicle.vin = vin; store.order.vehicle.registration.licensePlate = licensePlate; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ vehicle: expect.objectContaining({ year, make, model, style, carId, vin, licensePlateNumber: licensePlate }) }) })); }); it('calls api with expected damage', async () => { // Arrange const isRepair = getRandomString(6, 6); const numberOfChips = getRandomString(6, 6); const partQuestionAnswers = getRandomString(6, 6); const moldingQuestionAnswers = getRandomString(6, 6); const capabilityQuestionAnswers = getRandomString(6, 6); const dateOfLoss = getRandomString(6, 6); const damageCause = getRandomString(6, 6); const damageState = getRandomString(6, 6); const damageCity = getRandomString(6, 6); const isDamageGlassOnly = getRandomString(6, 6); store.order.damage.isRepair = isRepair; store.order.damage.numberOfChips = numberOfChips; store.order.damage.partQuestionAnswers = partQuestionAnswers; store.order.damage.moldingQuestionAnswers = moldingQuestionAnswers; store.order.damage.capabilityQuestionAnswers = capabilityQuestionAnswers; store.order.policy.dateOfLoss = dateOfLoss; store.order.policy.damageCause = damageCause; store.order.policy.damageState = damageState; store.order.policy.damageCity = damageCity; store.order.policy.isDamageGlassOnly = isDamageGlassOnly; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ damage: expect.objectContaining({ numberOfChips, isRepair, partQuestionAnswers, moldingQuestionAnswers, capabilityQuestionAnswers, dateOfLoss, damageCause, damageState, damageCity, isDamageGlassOnly }) }) })); }); it('calls api with expected policy', async () => { // Arrange const customerFirstName = getRandomString(6, 6); const customerLastName = getRandomString(6, 6); const customerEmail = getRandomString(6, 6); const customerPhoneNumber = getRandomString(6, 6); const customerState = getRandomString(2, 2); const policyNumber = getRandomString(6, 6); const policyZipCode = getRandomString(6, 6); const policyLookupSuccessful = getRandomString(6, 6); const noCoverage = getRandomString(6, 6); const originalDeductible = getRandomString(6, 6); const currentDeductible = getRandomString(6, 6); store.order.originalDeductible = originalDeductible; store.order.currentDeductible = currentDeductible; store.order.customer.firstName = customerFirstName; store.order.customer.lastName = customerLastName; store.order.customer.emailAddress = customerEmail; store.order.customer.phoneNumber = customerPhoneNumber; store.order.customer.address.state = customerState; store.order.policy.policyNumber = policyNumber; store.order.policy.policyZipCode = policyZipCode; store.order.policy.policyLookupSuccessful = policyLookupSuccessful; store.order.policy.noCoverage = noCoverage; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ policy: expect.objectContaining({ policyHolder: expect.objectContaining({ policyFirstName: customerFirstName, policyLastName: customerLastName, policyPhoneNumber: customerPhoneNumber, policyEmail: customerEmail, policyState: customerState }), policyNumber, policyZipCode, noCoverage, policyLookupSuccessful, originalDeductible, currentDeductible }) }) })); }); it('calls api with expected customer', async () => { // Arrange const streetAddress = getRandomString(6, 6); const streetAddress2 = getRandomString(6, 6); const city = getRandomString(6, 6); const state = getRandomString(6, 6); const zipCode = getRandomString(6, 6); const contactFirstName = getRandomString(6, 6); const contactLastName = getRandomString(6, 6); const contactEmail = getRandomString(6, 6); const contactPhoneNumber = getRandomString(6, 6); const requestTextUpdates = getRandomBoolean(); store.order.contactInfo.firstName = contactFirstName; store.order.contactInfo.lastName = contactLastName; store.order.contactInfo.emailAddress = contactEmail; store.order.contactInfo.phoneNumber = contactPhoneNumber; store.order.contactInfo.requestTextUpdates = requestTextUpdates; store.order.customer.address.streetAddress = streetAddress; store.order.customer.address.streetAddress2 = streetAddress2; store.order.customer.address.city = city; store.order.customer.address.state = state; store.order.customer.address.zipCode = zipCode; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ customer: expect.objectContaining({ address: expect.objectContaining({ streetAddress, streetAddress2, city, state, zipCode }), emailAddress: contactEmail, firstName: contactFirstName, lastName: contactLastName, phoneNumber: contactPhoneNumber, optInSms: requestTextUpdates }) }) })); }); it('calls api with expected lineItems', async () => { // Arrange const glassParts = getRandomString(6, 6); const supportingItems = getRandomString(6, 6); const vaps = getRandomString(6, 6); store.order.lineItems.glassParts = glassParts; store.order.lineItems.supportingItems = supportingItems; store.order.lineItems.vaps = vaps; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ lineItems: expect.objectContaining({ glassParts, supportingItems, vaps }) }) })); }); it.each([ [coverageStatuses.PENDING], [coverageStatuses.NO_COMP], [coverageStatuses.VERIFIED] ])('calls api with expected payment', async (coverageStatus) => { // Arrange const parentAccountNumber = getRandomString(6, 6); const isVerified = getRandomBoolean(); store.issConfig.parentAccountNumber = parentAccountNumber; store.order.payment.insuranceCoverage.isVerified = isVerified; store.order.payment.insuranceCoverage.coverageStatus = coverageStatus; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ payment: expect.objectContaining({ InsuranceCoverage: expect.objectContaining({ isVerified, coverageStatus }), parentAccountNumber }) }) })); }); it('calls api with expected service location', async () => { // Arrange const notesForTechnician = getRandomString(6, 6); const address = getRandomString(6, 6); const city = getRandomString(6, 6); const state = getRandomString(6, 6); const zipCode = getRandomString(6, 6); const zipCodeCtu = getRandomString(6, 6); store.order.contactInfo.notesForTechnician = notesForTechnician; store.order.serviceLocation.address = address; store.order.serviceLocation.city = city; store.order.serviceLocation.state = state; store.order.serviceLocation.zipCode = zipCode; store.order.serviceLocation.zipCodeCtu = zipCodeCtu; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ serviceLocation: expect.objectContaining({ address: expect.objectContaining({ streetAddress: address, city, state, zipCode, zipCodeCtu }), techNotes: notesForTechnician }) }) })); }); it('calls api with expected schedule', async () => { // Arrange const date = getRandomString(6, 6); const startTime = getRandomString(6, 6); const endTime = getRandomString(6, 6); const routeCode = getRandomString(6, 6); const jobMaxMinutes = getRandomString(6, 6); const jobMinMinutes = getRandomString(6, 6); store.order.schedule.date = date; store.order.schedule.startTime = startTime; store.order.schedule.endTime = endTime; store.order.schedule.routeCode = routeCode; store.order.schedule.jobMaxMinutes = jobMaxMinutes; store.order.schedule.jobMinMinutes = jobMinMinutes; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ schedule: expect.objectContaining({ date, startTime, endTime, routeCode, jobMaxMinutes, jobMinMinutes }) }) })); }); it('calls api with expected referral date', async () => { // Arrange const referralDate = getRandomString(6, 6); store.order.referralDate = referralDate; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ referralDate }) })); }); it('calls api with expected referral number', async () => { // Arrange const referralNumber = getRandomString(6, 6); store.order.referralNumber = referralNumber; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ referralNumber }) })); }); }); it('No glassArray => empty list', async () => { store.damage.glassToReplace = null; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ damage: expect.objectContaining({ glassToReplace: [] }) }) })); }); it('glassArray empty => empty list', async () => { store.damage.glassToReplace = []; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ damage: expect.objectContaining({ glassToReplace: [] }) }) })); }); it('Nonempty glass array => expected glass array sent', async () => { const location1 = getRandomString(5); const location2 = getRandomString(5); const name1 = getRandomString(10); const name2 = getRandomString(10); store.damage.glassToReplace = [ { glassLocation: location1, glassName: name1 }, { glassLocation: location2, glassName: name2 } ]; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.saveSession(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ damage: expect.objectContaining({ glassToReplace: expect.arrayContaining([ { location: location1, name: name1 }, { location: location2, name: name2 } ]) }) }) })); }); it('api call throws exception', async () => { expect.assertions(2); const error = 'save session error'; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); // Act await store.saveSession().catch((e) => { expect(e).toEqual(error); }); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ method: endpoints.SaveSession.method, endpoint: endpoints.SaveSession.url })); }); }); describe('loadSession method', () => { describe('successful method call', () => { const applicationUser = { crmCustomerId: getRandomString(6, 6), experiments: getRandomString(6, 6), lastPage: getRandomString(6, 6), pageData: getRandomString(6, 6), savedSessionId: getRandomString(6, 6), hasSentSaveQuoteEmail: getRandomBoolean() }; const vehicle = { year: getRandomString(6, 6), make: getRandomString(6, 6), model: getRandomString(6, 6), style: getRandomString(6, 6), vin: getRandomString(6, 6), carId: getRandomString(6, 6), category: getRandomString(6, 6), registration: { licensePlateNumber: getRandomString(6, 6) }, imageUrl: getRandomString(6, 6), imageVifNumber: getRandomString(6, 6), imageVifColor: getRandomString(6, 6) }; const damage = { numberOfChips: getRandomString(6, 6), isRepair: getRandomBoolean(), glassToReplace: getRandomString(6, 6), capabilityQuestionAnswers: getRandomString(6, 6), moldingQuestionAnswers: getRandomString(6, 6), partQuestionAnswers: getRandomString(6, 6), dateOfLoss: getRandomString(6, 6), damageCause: getRandomString(6, 6), damageState: getRandomString(6, 6), damageCity: getRandomString(6, 6), isDamageGlassOnly: getRandomBoolean() }; const policy = { policyNumber: getRandomString(6, 6), policyZipCode: getRandomBoolean(), noCoverage: getRandomString(6, 6), policyLookupSuccessful: getRandomBoolean(), policyHolder: { policyFirstName: getRandomString(6, 6), policyLastName: getRandomString(6, 6), policyPhoneNumber: getRandomString(6, 6), policyState: getRandomString(6, 6) }, originalDeductible: getRandomString(6, 6), currentDeductible: getRandomString(6, 6) }; const customer = { firstName: getRandomString(6, 6), lastName: getRandomString(6, 6), emailAddress: getRandomString(6, 6), phoneNumber: getRandomString(6, 6), isSmsOptIn: getRandomString(6, 6), address: { streetAddress: getRandomString(6, 6), streetAddress2: getRandomString(6, 6), city: getRandomString(6, 6), state: getRandomString(6, 6), zipCode: getRandomString(6, 6), zipCodeCtu: getRandomString(6, 6) } }; const provider = { providerNumber: getRandomString(6, 6), address: { streetAddress: getRandomString(6, 6), streetAddress2: getRandomString(6, 6), city: getRandomString(6, 6), state: getRandomString(6, 6), zipCode: getRandomString(6, 6), zipCodeCtu: getRandomString(6, 6) } }; const serviceLocation = { streetAddress: getRandomString(6, 6), streetAddress2: getRandomString(6, 6), city: getRandomString(6, 6), state: getRandomString(6, 6), zipCode: getRandomString(6, 6), zipCodeCtu: getRandomString(6, 6), appointmentType: getRandomString(6, 6), isVehicleProtected: getRandomBoolean(), provider, techNotes: getRandomString(6, 6), phoneNumber: getRandomString(6, 6), isSmsOptIn: getRandomBoolean() }; const lineItems = { glassParts: getRandomString(6, 6), supportingItems: getRandomString(6, 6), vaps: getRandomString(6, 6), serverData: getRandomString(6, 6) }; const payment = { insuranceCoverage: { isVerified: getRandomBoolean(), coverageStatus: getRandomString(6, 6), claimNumber: getRandomString(6, 6) }, parentAccountNumber: getRandomString(6, 6) }; const schedule = { date: getRandomString(6, 6), startTime: getRandomString(6, 6), endTime: getRandomString(6, 6), routeCode: getRandomString(6, 6), jobMaxMinutes: getRandomString(6, 6), jobMinMinutes: getRandomString(6, 6) }; const fullApiResponse = { data: { applicationUser, order: { vehicle, damage, policy, customer, serviceLocation, lineItems, payment, schedule, referralNumber: getRandomString(6, 6), referralDate: getRandomString(6, 6), referralCorrelationId: getRandomString(6, 6), referralSequenceNumber: getRandomString(6, 6), eon: getRandomString(6, 6) } } }; it('calls load session api endpoint', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act store.loadSession(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ method: endpoints.LoadSession.method, endpoint: endpoints.LoadSession.url })); }); it('Returns expected response object', async () => { // Arrange const response = { data: {ReferralNumber: getRandomString(6, 6)} }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act const result = store.loadSession(); // Asserts await expect(result).resolves.toBe(response.data); }); it('sets expected application user data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); const originalSavedSessionTimeout = store.applicationUser.savedSessionTimeout; const originalEventBus = store.applicationUser.eventBus; const originalSaveSessionPromise = store.applicationUser.saveSessionPromise; const originalTriggeredSiteEntry = store.applicationUser.triggeredSiteEntry; const originalDuplicateOrders = store.applicationUser.duplicateOrders; // Act await store.loadSession(); // Asserts expect(store.applicationUser.experiments).toEqual(applicationUser.experiments); expect(store.applicationUser.pageData).toBe(applicationUser.pageData); expect(store.applicationUser.savedSessionId).toBe(applicationUser.savedSessionId); expect(store.applicationUser.crmCustomerId).toBe(applicationUser.crmCustomerId); expect(store.applicationUser.lastPageVisited).toBe(applicationUser.lastPage); expect(store.applicationUser.hasSentSaveQuoteEmail).toBe(applicationUser.hasSentSaveQuoteEmail); expect(store.applicationUser.eventBus).toEqual(originalEventBus); expect(store.applicationUser.savedSessionTimeout).toBe(originalSavedSessionTimeout); expect(store.applicationUser.saveSessionPromise).toBe(originalSaveSessionPromise); expect(store.applicationUser.triggeredSiteEntry).toBe(originalTriggeredSiteEntry); expect(store.applicationUser.duplicateOrders).toEqual(originalDuplicateOrders); }); it('sets expected vehicle data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); const originalRegistrationAddress = store.vehicle.registration.address; const originalRegistrationCity = store.vehicle.registration.city; const originalRegistrationState = store.vehicle.registration.state; const originalRegistrationZipCode = store.vehicle.registration.zipCode; const originalRegistrationFirstName = store.vehicle.registration.firstName; const originalRegistrationLastName = store.vehicle.registration.lastName; // Act await store.loadSession(); // Asserts expect(store.vehicle.year).toBe(vehicle.year); expect(store.vehicle.make).toBe(vehicle.make); expect(store.vehicle.model).toBe(vehicle.model); expect(store.vehicle.style).toBe(vehicle.style); expect(store.vehicle.carId).toBe(vehicle.carId); expect(store.vehicle.category).toBe(vehicle.category); expect(store.vehicle.vin).toBe(vehicle.vin); expect(store.vehicle.imageUrl).toBe(vehicle.imageUrl); expect(store.vehicle.imageVifNumber).toBe(vehicle.imageVifNumber); expect(store.vehicle.imageColor).toBe(vehicle.imageVifColor); expect(store.vehicle.registration.licensePlate).toBe(vehicle.registration.licensePlateNumber); expect(store.vehicle.registration.address).toBe(originalRegistrationAddress); expect(store.vehicle.registration.city).toBe(originalRegistrationCity); expect(store.vehicle.registration.state).toBe(originalRegistrationState); expect(store.vehicle.registration.zipCode).toBe(originalRegistrationZipCode); expect(store.vehicle.registration.firstName).toBe(originalRegistrationFirstName); expect(store.vehicle.registration.lastName).toBe(originalRegistrationLastName); }); it('sets expected damage data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); // Act await store.loadSession(); // Asserts expect(store.damage.isRepair).toBe(damage.isRepair); expect(store.damage.numberOfChips).toBe(damage.numberOfChips); expect(store.damage.glassToReplace).toBe(damage.glassToReplace); expect(store.damage.partQuestionAnswers).toBe(damage.partQuestionAnswers); expect(store.damage.moldingQuestionAnswers).toBe(damage.moldingQuestionAnswers); expect(store.damage.capabilityQuestionAnswers).toBe(damage.capabilityQuestionAnswers); }); it('sets expected policy data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); const originalRepairDeductible = store.policy.deductible.repair; const originalReplaceDeductible = store.policy.deductible.replace; const originalVehicles = store.policy.vehicles; const originalEndorsementQuestionAnswers = store.policy.endorsementQuestionAnswers; // Act await store.loadSession(); // Asserts expect(store.policy.policyNumber).toBe(policy.policyNumber); expect(store.policy.policyZipCode).toBe(policy.policyZipCode); expect(store.policy.dateOfLoss).toBe(damage.dateOfLoss); expect(store.policy.damageCause).toBe(damage.damageCause); expect(store.policy.damageState).toBe(damage.damageState); expect(store.policy.damageCity).toBe(damage.damageCity); expect(store.policy.isDamageGlassOnly).toBe(damage.isDamageGlassOnly); expect(store.policy.policyLookupSuccessful).toBe(policy.policyLookupSuccessful); expect(store.policy.noCoverage).toBe(policy.noCoverage); expect(store.policy.deductible.repair).toBe(originalRepairDeductible); expect(store.policy.deductible.replace).toBe(originalReplaceDeductible); expect(store.policy.vehicles).toEqual(originalVehicles); expect(store.policy.endorsementQuestionAnswers).toBe(originalEndorsementQuestionAnswers); }); it('sets expected customer data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); // Act await store.loadSession(); // Asserts expect(store.order.customer.address.streetAddress).toBe(customer.address.streetAddress); expect(store.order.customer.address.streetAddress2).toBe(customer.address.streetAddress2); expect(store.order.customer.address.city).toBe(customer.address.city); expect(store.order.customer.address.state).toBe(customer.address.state); expect(store.order.customer.address.zipCode).toBe(customer.address.zipCode); expect(store.order.customer.firstName).toBe(policy.policyHolder.policyFirstName); expect(store.order.customer.lastName).toBe(policy.policyHolder.policyLastName); expect(store.order.customer.emailAddress).toBe(customer.emailAddress); expect(store.order.customer.phoneNumber).toBe(policy.policyHolder.policyPhoneNumber); }); it('sets expected serviceLocation data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); // Act await store.loadSession(); // Asserts expect(store.order.serviceLocation.address).toBe(serviceLocation.streetAddress); expect(store.order.serviceLocation.address2).toBe(serviceLocation.streetAddress2); expect(store.order.serviceLocation.city).toBe(serviceLocation.city); expect(store.order.serviceLocation.state).toBe(serviceLocation.state); expect(store.order.serviceLocation.zipCode).toBe(serviceLocation.zipCode); expect(store.order.serviceLocation.zipCodeCtu).toBe(serviceLocation.zipCodeCtu); expect(store.order.serviceLocation.appointmentType).toBe(serviceLocation.appointmentType); expect(store.order.serviceLocation.isVehicleProtected).toBe(serviceLocation.isVehicleProtected); expect(store.order.serviceLocation.provider.providerNumber).toBe(provider.providerNumber); expect(store.order.serviceLocation.provider.address.streetAddress).toBe(provider.address.streetAddress); expect(store.order.serviceLocation.provider.address.city).toBe(provider.address.city); expect(store.order.serviceLocation.provider.address.state).toBe(provider.address.state); expect(store.order.serviceLocation.provider.address.zipCode).toBe(provider.address.zipCode); expect(store.order.serviceLocation.provider.address.zipCodeCtu).toBe(provider.address.zipCodeCtu); }); it('sets expected lineItems data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); const originalOtherParts = store.order.lineItems.otherParts; // Act await store.loadSession(); // Asserts expect(store.order.lineItems.glassParts).toBe(lineItems.glassParts); expect(store.order.lineItems.otherParts).toBe(originalOtherParts); expect(store.order.lineItems.supportingItems).toBe(lineItems.supportingItems); expect(store.order.lineItems.vaps).toBe(lineItems.vaps); }); it('sets expected payment data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); // Act await store.loadSession(); // Asserts expect(store.order.payment.insuranceCoverage.isVerified).toBe(payment.insuranceCoverage.isVerified); expect(store.order.payment.insuranceCoverage.coverageStatus).toBe(payment.insuranceCoverage.coverageStatus); expect(store.order.payment.parentAccountNumber).toBe(payment.parentAccountNumber); expect(store.issConfig.parentAccountNumber).toBe(payment.parentAccountNumber); expect(store.order.payment.insuranceCoverage.claimNumber).toBe(payment.insuranceCoverage.claimNumber); }); it('sets expected contactInfo data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); // Act await store.loadSession(); // Asserts expect(store.order.contactInfo.firstName).toBe(customer.firstName); expect(store.order.contactInfo.lastName).toBe(customer.lastName); expect(store.order.contactInfo.emailAddress).toBe(customer.emailAddress); expect(store.order.contactInfo.phoneNumber).toBe(customer.phoneNumber); expect(store.order.contactInfo.requestTextUpdates).toBe(customer.isSmsOptIn); expect(store.order.contactInfo.notesForTechnician).toBe(serviceLocation.techNotes); }); it('sets expected schedule data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); // Act await store.loadSession(); // Asserts expect(store.order.schedule.date).toBe(schedule.date); expect(store.order.schedule.startTime).toBe(schedule.startTime); expect(store.order.schedule.endTime).toBe(schedule.endTime); expect(store.order.schedule.routeCode).toBe(schedule.routeCode); expect(store.order.schedule.jobMaxMinutes).toBe(schedule.jobMaxMinutes); }); it('sets expected remaining order data', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(fullApiResponse)); const originalWorkOrderNumber = store.order.workOrderNumber; // Act await store.loadSession(); // Asserts expect(store.order.referralNumber).toBe(fullApiResponse.data.order.referralNumber); expect(store.order.referralDate).toBe(fullApiResponse.data.order.referralDate); expect(store.order.referralCorrelationId).toBe(fullApiResponse.data.order.referralCorrelationId); expect(store.order.referralSequenceNumber).toBe(fullApiResponse.data.order.referralSequenceNumber); expect(store.order.eon).toBe(fullApiResponse.data.order.eon); expect(store.order.workOrderNumber).toBe(originalWorkOrderNumber); expect(store.order.originalDeductible).toBe(policy.originalDeductible); expect(store.order.currentDeductible).toBe(policy.currentDeductible); }); }); it('api call throws exception', async () => { expect.assertions(2); const error = 'load session error'; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); // Act await store.loadSession().catch((e) => { expect(e).toEqual(error); }); // Asserts expect(globalMethods.callHttpClient) .toHaveBeenCalledWith(expect.objectContaining({ method: endpoints.LoadSession.method, endpoint: endpoints.LoadSession.url })); }); }); describe('getCoveragePolicyInfo method', () => { describe('successful method call', () => { it('calls getCoveragePolicyInfo api endpoint', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.getCoveragePolicyInfo(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ method: endpoints.CoveragePolicyInfo.method, endpoint: endpoints.CoveragePolicyInfo.url })); }); it('Returns expected response object', async () => { // Arrange const response = { ReferralNumber: getRandomString(6, 6) }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act const result = store.getCoveragePolicyInfo(); // Asserts await expect(result).resolves.toBe(response); }); it('calls api with expected data', async () => { // Arrange const accountNumber = getRandomString(6, 6); const policyNumber = getRandomString(6, 6); const dateOfLoss = getRandomString(6, 6); const zipCode = getRandomString(6, 6); const referralCorrelationId = getRandomString(6, 6); store.order.accountNumber = accountNumber; store.order.policy.policyNumber = policyNumber; store.order.policy.dateOfLoss = dateOfLoss; store.order.policy.policyZipCode = zipCode; store.order.referralCorrelationId = referralCorrelationId; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); // Act await store.getCoveragePolicyInfo(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ payload: expect.objectContaining({ accountNumber, policyNumber, dateOfLoss, zipCode, referralCorrelationId }) })); }); it('null response by api => policyLookupSuccessful false', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(null)); // Act await store.getCoveragePolicyInfo(); // Asserts expect(store.order.policy.policyLookupSuccessful).toBe(false); }); it('no policies returned by api => policyLookupSuccessful false', async () => { // Arrange const responseNoPolicies = { data: { policies: [] } }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(responseNoPolicies)); // Act await store.getCoveragePolicyInfo(); // Asserts expect(store.order.policy.policyLookupSuccessful).toBe(false); }); it('multiple policies returned by api => data set based on first policy returned', async () => { // Arrange const insured = { address: getRandomString(6, 6), firstName: getRandomString(6, 6), lastName: getRandomString(6, 6), city: getRandomString(6, 6), state: getRandomString(6, 6), zipCode: getRandomString(6, 6) }; const vehicles = [ { name: getRandomString(6, 6) }, { name: getRandomString(6, 6) } ]; const policy1 = { insureds: [insured], vehicles }; const responseNoPolicies = { data: { policies: [policy1, {}] } }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(responseNoPolicies)); // Act await store.getCoveragePolicyInfo(); // Asserts expect(store.order.policy.policyLookupSuccessful).toBe(true); expect(store.order.customer.address.streetAddress).toBe(insured.address); expect(store.order.customer.address.city).toBe(insured.city); expect(store.order.customer.address.state).toBe(insured.state); expect(store.order.customer.address.zipCode).toBe(insured.zipCode); expect(store.order.customer.firstName).toBe(insured.firstName); expect(store.order.customer.lastName).toBe(insured.lastName); expect(store.order.serviceLocation.zipCode).toBe(insured.zipCode); expect(store.order.policy.vehicles).toEqual(vehicles); }); it('multiple insureds on first policy returned by api => data set based on first insured in first policy', async () => { // Arrange const insured1 = { address: getRandomString(6, 6), firstName: getRandomString(6, 6), lastName: getRandomString(6, 6), city: getRandomString(6, 6), state: getRandomString(6, 6), zipCode: getRandomString(6, 6) }; const responseNoPolicies = { data: { policies: [{ insureds: [insured1, { address: getRandomString(6, 6) }] }] } }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(responseNoPolicies)); // Act await store.getCoveragePolicyInfo(); // Asserts expect(store.order.policy.policyLookupSuccessful).toBe(true); expect(store.order.customer.address.streetAddress).toBe(insured1.address); }); it('no policy vehicles on first policy => order.policy.vehicles empty list', async () => { // Arrange const responseNoPolicies = { data: { policies: [{ vehicles: [] }] } }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(responseNoPolicies)); // Act await store.getCoveragePolicyInfo(); // Asserts expect(store.order.policy.policyLookupSuccessful).toBe(true); expect(store.order.policy.vehicles).toEqual([]); }); }); it('api call throws exception => policyLookupSuccessful false', async () => { expect.assertions(3); const error = 'get coverage policy info error'; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); // Act await store.getCoveragePolicyInfo().catch((e) => { expect(e).toEqual(error); }); // Asserts expect(globalMethods.callHttpClient) .toHaveBeenCalledWith(expect.objectContaining({ method: endpoints.CoveragePolicyInfo.method, endpoint: endpoints.CoveragePolicyInfo.url })); expect(store.order.policy.policyLookupSuccessful).toBe(false); }); }); describe('saveEndorsementQuestionAnswers method', () => { it('method should update endorsement question data in store', () => { // Arrange const questionNum = getRandomInt(1, 100); const questionText = getRandomString(50, 300); const selectedAnswer = getRandomString(2, 3); const endorsementQuestionAnswersArray = [ { questionNum, questionText, selectedAnswer } ]; // Act store.saveEndorsementQuestionAnswers(endorsementQuestionAnswersArray); // Assert expect(store.order.policy.endorsementQuestionAnswers).toEqual(endorsementQuestionAnswersArray); }); }); describe('duplicateSearch method', () => { it('successful response => duplicateReferrals set to expected', async () => { // Arrange const expected = [ { accountNumber: getRandomString(6, 6), claimNumber: getRandomString(9, 9) }, { accountNumber: getRandomString(6, 6), claimNumber: getRandomString(9, 9) }, { accountNumber: getRandomString(6, 6), claimNumber: getRandomString(9, 9) }]; const response = { data: expected }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act await store.getDuplicateReferrals(); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalled(); expect(store.applicationUser.duplicateOrders).toEqual(expected); }); it('Call to client returns exception => object with error property returned and duplicateReferrals set to []', async () => { // Arrange expect.assertions(3); const error = 'get duplicate referrals error'; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); // Act await store.getDuplicateReferrals().catch((e) => { expect(e).toEqual(error); }); // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalled(); expect(store.applicationUser.duplicateOrders.length).toBe(0); }); }); describe('updatePolicyITACFlag method', () => { it('updatePolicyITACFlag updates policy.isITAC flag in store', () => { // Arrange const moqIsITAC = getRandomBoolean(); // Act store.updatePolicyITACFlag(moqIsITAC); // Assert expect(store.order.policy.isITAC).toEqual(moqIsITAC); }); }); describe('isMobileAppointment', () => { it('Should return true for mobile appointments', () => { // Arrange // Act store.updateServiceLocation({ appointmentType: AppointmentTypeStrings.MOBILE }); // Assert expect(store.isMobileAppointment).toBe(true); }); it('Should return true for mobile-NotITAC-and-NotNoComp appointments', () => { // Arrange // Act store.updateServiceLocation({ appointmentType: AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP }); // Assert expect(store.isMobileAppointment).toBe(true); }); it('Should return false for non-mobile appointments', () => { // Arrange // Act store.updateServiceLocation({ appointmentType: AppointmentTypeStrings.IN_SHOP }); // Assert expect(store.isMobileAppointment).toBe(false); }); it('Should return false for null appointments', () => { // Arrange // Act store.updateServiceLocation({ appointmentType: null }); // Assert expect(store.isMobileAppointment).toBe(false); }); }); describe('isDropoffAppointment', () => { it('Should return true for drop-off appointments', () => { // Arrange // Act store.updateServiceLocation({ appointmentType: AppointmentTypeStrings.DROP_OFF }); // Assert expect(store.isDropOffAppointment).toBe(true); }); it('Should return false for non-drop-off appointments', () => { // Arrange // Act store.updateServiceLocation({ appointmentType: AppointmentTypeStrings.MOBILE }); // Assert expect(store.isDropOffAppointment).toBe(false); }); it('Should return false for null appointments', () => { // Arrange // Act store.updateServiceLocation({ appointmentType: null }); // Assert expect(store.isDropOffAppointment).toBe(false); }); }); describe('getFinalDeductible method', () => { describe('successful method call', () => { it('calls get final deductible api endpoint', () => { // Arrange const response = { data: { deductible: getRandomInt(0, 5000), policyData: getRandomString(100, 200) } }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); store.order.damage.glassToReplace = [getRandomString(10, 15)]; // Act store.getFinalDeductible(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ method: endpoints.FinalDeductible.method, endpoint: endpoints.FinalDeductible.url })); }); it('returns expected response object', async () => { // Arrange const response = { data: { deductible: getRandomInt(0, 5000), policyData: getRandomString(100, 200) } }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); store.order.damage.glassToReplace = [getRandomString(10, 15)]; // Act const result = store.getFinalDeductible(); // Assert await expect(result).resolves.toBe(response); }); it('calls api with expected payload', () => { // Arrange const response = { data: { deductible: getRandomInt(0, 5000), policyData: getRandomString(100, 200) } }; const location = getRandomString(10, 15).toUpperCase(); store.order.damage.glassToReplace = [ { glassLocation: location } ]; const referralCorrelationId = getRandomGuid(); const accountNumber = getRandomString(6, 6); const endorsements = []; const manualGlassNames = [location]; const policyState = getRandomString(2, 2); const status = getRandomString(6, 8); const currentDeductible = getRandomInt(0, 5000); const noCoverage = getRandomBoolean(); const isRepair = getRandomBoolean(); const policyNumber = getRandomString(10, 20); const insuredFirstName = getRandomString(10, 20); const insuredLastName = getRandomString(10, 20); const insuredZipCode = getRandomInt(10000, 99999).toString(); const policyVehicleId = getRandomInt(1, 2).toString(); const vehicleVin = getRandomString(17, 17); const policyData = getRandomString(100, 200); const isItac = getRandomBoolean(); store.order.referralCorrelationId = referralCorrelationId; store.issConfig.parentAccountNumber = accountNumber; store.order.currentDeductible = currentDeductible; store.order.policy.noCoverage = noCoverage; store.order.policy.status = status; store.order.customer.address.state = policyState; store.order.damage.isRepair = isRepair; store.order.policy.policyNumber = policyNumber; store.order.customer.firstName = insuredFirstName; store.order.customer.lastName = insuredLastName; store.order.customer.address.zipCode = insuredZipCode; store.order.vehicle.policyVehicleId = policyVehicleId; store.order.vehicle.vin = vehicleVin; store.order.policy.policyData = policyData; store.updatePolicyITACFlag(isItac); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act store.getFinalDeductible(); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(({ method: endpoints.FinalDeductible.method, endpoint: endpoints.FinalDeductible.url, payload: ({ referralCorrelationId, accountNumber, endorsements, manualGlassNames, policyState, status, currentDeductible, noCoverage, isRepair, policyNumber, insuredFirstName, insuredLastName, insuredZipCode, policyVehicleId, vehicleVin, policyData, isItac }) })); }); it('only "Yes" endorsement answers are added to payload', () => { // Arrange const response = { data: { deductible: getRandomInt(0, 5000), policyData: getRandomString(100, 200) } }; const location = getRandomString(10, 15).toUpperCase(); store.order.damage.glassToReplace = [ { glassLocation: location } ]; const referralCorrelationId = getRandomGuid(); const accountNumber = getRandomString(6, 6); const manualGlassNames = [location]; const policyState = getRandomString(2, 2); const status = getRandomString(6, 8); const currentDeductible = getRandomInt(0, 5000); const noCoverage = getRandomBoolean(); const isRepair = getRandomBoolean(); const endorsementAnswers = [ { questionNum: getRandomInt(1, 10), endorsementName: getRandomString(8, 20), questionText: getRandomString(50, 100), selectedAnswer: 'Yes' }, { questionNum: getRandomInt(1, 10), endorsementName: getRandomString(8, 20), questionText: getRandomString(50, 100), selectedAnswer: 'Yes' }, { questionNum: getRandomInt(1, 10), endorsementName: getRandomString(8, 20), questionText: getRandomString(50, 100), selectedAnswer: 'No' } ]; const policyNumber = getRandomString(10, 20); const insuredFirstName = getRandomString(10, 20); const insuredLastName = getRandomString(10, 20); const insuredZipCode = getRandomInt(10000, 99999).toString(); const policyVehicleId = getRandomInt(1, 2).toString(); const vehicleVin = getRandomString(17, 17); const policyData = getRandomString(100, 200); const isItac = false; store.order.referralCorrelationId = referralCorrelationId; store.issConfig.parentAccountNumber = accountNumber; store.order.currentDeductible = currentDeductible; store.order.policy.noCoverage = noCoverage; store.order.policy.status = status; store.order.customer.address.state = policyState; store.order.policy.endorsementQuestionAnswers = endorsementAnswers; store.order.damage.isRepair = isRepair; store.order.policy.policyNumber = policyNumber; store.order.customer.firstName = insuredFirstName; store.order.customer.lastName = insuredLastName; store.order.customer.address.zipCode = insuredZipCode; store.order.vehicle.policyVehicleId = policyVehicleId; store.order.vehicle.vin = vehicleVin; store.order.policy.policyData = policyData; store.updatePolicyITACFlag(isItac); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); // Act store.getFinalDeductible(); // Assert const expected = [endorsementAnswers[0].endorsementName, endorsementAnswers[1].endorsementName]; expect(globalMethods.callHttpClient).toHaveBeenCalledWith(({ method: endpoints.FinalDeductible.method, endpoint: endpoints.FinalDeductible.url, payload: ({ referralCorrelationId, accountNumber, endorsements: expected, manualGlassNames, policyState, status, currentDeductible, noCoverage, isRepair, policyNumber, insuredFirstName, insuredLastName, insuredZipCode, policyVehicleId, vehicleVin, policyData, isItac }) })); }); }); describe('unsuccessful api call', () => { it('api call throws exception', async () => { // Arrange expect.assertions(2); const error = 'final deductible error'; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); // Act await store.getFinalDeductible().catch((e) => { expect(e).toEqual(error); }); // Assert expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ method: endpoints.FinalDeductible.method, endpoint: endpoints.FinalDeductible.url })); }); }); }); describe('updateDeductible method', () => { it('final deductible is saved as currentDeductible in store', () => { // Arrange const finalDeductible = getRandomInt(0, 5000); // Act store.updateDeductible(finalDeductible); // Assert expect(store.order.currentDeductible).toEqual(finalDeductible); }); it('null final deductible => currentDeductible in store set to null', () => { // Arrange const finalDeductible = null; // Act store.updateDeductible(finalDeductible); // Assert expect(store.order.currentDeductible).toEqual(finalDeductible); }); }); });