diff --git a/src/store/index.js b/src/store/index.js index 8006f9f5..2204a474 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -393,7 +393,7 @@ export const useMainStore = defineStore({ country: 'US' // TODO set from store }, homePhone: { - number: this.order.customer.phoneNumber.replaceAll(nonNumberCharRegex, '') + number: this.order.customer.phoneNumber?.replaceAll(nonNumberCharRegex, '') ?? '' } }, caller: { diff --git a/src/store/store.spec.js b/src/store/store.spec.js index da26b1ac..57a24367 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1,34 +1,27 @@ import { useMainStore } from '@/store'; -import { createApp } from 'vue'; -import { setActivePinia, createPinia } from "pinia"; -import globalMethods from "@/global-methods"; -import App from '@/App'; +import { setActivePinia, createPinia } from 'pinia'; +import globalMethods from '@/global-methods'; import { getRandomString, getRandomGuid, getRandomInt, getRandomBoolean } from '@/helpers/data-generation'; -import { coverageStatuses } from "@/constants/coverage-statuses.js"; - -describe("Store", () => { +import { coverageStatuses } from '@/constants/coverage-statuses.js'; +describe('Store', () => { let store; - const vueApp = createApp(App); - beforeEach(() => { const pinia = createPinia(); setActivePinia(pinia); - vueApp.use(pinia); store = useMainStore(); store.applicationUser.eventBus = []; jest.resetAllMocks(); }); - - - it("Should Store Vehicle Year", () => { - let testYear = "2001"; + + 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", () => { + it('Should add events to the bus', () => { // Arrange const category = getRandomString(1, 25); const subCategory = getRandomString(5, 20); @@ -54,7 +47,7 @@ describe("Store", () => { expect(store.applicationUser.eventBus[0]).toEqual(event); }); - it("Should remove events from the bus", () => { + it('Should remove events from the bus', () => { // Arrange const category = getRandomString(1, 25); const subCategory = getRandomString(5, 20); @@ -84,7 +77,7 @@ describe("Store", () => { expect(store.applicationUser.eventBus.length).toBe(0); }); - it("Should return correct event using the getter function eventBusItem", () => { + it('Should return correct event using the getter function eventBusItem', () => { // Arrange const category = getRandomString(1, 25); const subCategory = getRandomString(5, 20); @@ -112,7 +105,7 @@ describe("Store", () => { expect(actual).toEqual(event.eventValue); }); - it("UpdateVehicle should merge vehicle with response object", () => { + it('UpdateVehicle should merge vehicle with response object', () => { // Arrange const carId = getRandomString(10,14); const category = getRandomString(3,7); @@ -154,7 +147,7 @@ describe("Store", () => { expect(store.order.vehicle).toMatchObject(expectedVehicle); }); - it("UpdateVehicle should set policy values appropriately with repair waived", () => { + it('UpdateVehicle should set policy values appropriately with repair waived', () => { // Arrange const noCompensation = getRandomBoolean(); const deductible = getRandomInt(1,500); @@ -179,7 +172,7 @@ describe("Store", () => { expect(store.order.policy).toMatchObject(expectedPolicy); }); - it("UpdateVehicle should set policy values appropriately with repair not waived", () => { + it('UpdateVehicle should set policy values appropriately with repair not waived', () => { // Arrange const noCompensation = getRandomBoolean(); const deductible = getRandomInt(1,500); @@ -205,7 +198,7 @@ describe("Store", () => { }); // TODO update test to work also checking store values - it("setVehicle should call globalMethods.callHttpClient", () => { + it('setVehicle should call globalMethods.callHttpClient', () => { // Arrange const carId = getRandomString(10,14); const category = getRandomString(3,7); @@ -240,7 +233,7 @@ describe("Store", () => { expect(returned).resolves.toMatchObject(response); }); - it("saveVehicleDamage with windshield repair should update damage with number of chips not null", () => { + 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); @@ -260,7 +253,7 @@ describe("Store", () => { expect(store.order.damage.numberOfChips).toEqual(chipCount); }); - it("saveVehicleDamage without windshield repair should update damage with number of chips null", () => { + it('saveVehicleDamage without windshield repair should update damage with number of chips null', () => { // Arrange const glassName = getRandomString(4,10); const glassLocation = getRandomString(5,15); @@ -282,7 +275,7 @@ describe("Store", () => { expect(store.order.damage.numberOfChips).toEqual(expectedChipCount); }); - it("should return registration data if available", () => { + it('should return registration data if available', () => { //Arrange const streetAddress = getRandomString(5,15); const city = getRandomString(5,15); @@ -318,7 +311,7 @@ describe("Store", () => { expect(actual).toEqual(expected); }); - it("should return customer data if registration data unavailable", () => { + it('should return customer data if registration data unavailable', () => { //Arrange const address = getRandomString(1,25); const city = getRandomString(5,20); @@ -357,8 +350,8 @@ describe("Store", () => { expect(actual).toMatchObject(expected); }); - describe("registerClaim method", () => { - it("successful response with no coverage => isVerified true and coverage status no comp", async () => { + describe('registerClaim method', () => { + it('successful response with no coverage => isVerified true and coverage status no comp', async () => { // Arrange const response = { data: { @@ -384,7 +377,7 @@ describe("Store", () => { expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.NO_COMP); }); - it("successful response with coverage => isVerified true and coverage status verified", async () => { + it('successful response with coverage => isVerified true and coverage status verified', async () => { // Arrange const response = { data: { @@ -408,9 +401,9 @@ describe("Store", () => { expect(globalMethods.callHttpClient).toHaveBeenCalled(); expect(store.payment.insuranceCoverage.isVerified).toBe(true); expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.VERIFIED); - }) + }); - it("Call to client returns exception, resulting in object with error property being returned", async () => { + it('Call to client returns exception, resulting in object with error property being returned', async () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject());