diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index d91b5026..a34d8990 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -145,6 +145,11 @@ const endpoints = Object.freeze({ SaveSession: { url: '/order/api/v1/order/save-session/iss', method: 'POST' + }, + DuplicateSearch: { + // eslint-disable-next-line max-len + url: (accountNumber, policyNumber, phoneNumber) => `/order/api/v1/order/duplicate-check/${accountNumber}/${policyNumber}/${phoneNumber}`, + method: 'GET' } }); diff --git a/src/layouts/duplicate-check/duplicate-check.spec.js b/src/layouts/duplicate-check/duplicate-check.spec.js index 6746e4a9..e0b06650 100644 --- a/src/layouts/duplicate-check/duplicate-check.spec.js +++ b/src/layouts/duplicate-check/duplicate-check.spec.js @@ -137,7 +137,7 @@ describe('duplicateCheck.vue', () => { const mountOptions = getMountOptions({ router: { navigate: jest.fn() } }); - + const mainInitialState = { applicationUser: { duplicateOrders: undefined @@ -159,7 +159,7 @@ describe('duplicateCheck.vue', () => { const mountOptions = getMountOptions({ router: { navigate: jest.fn() } }); - + const mainInitialState = { applicationUser: { duplicateOrders: [] @@ -181,7 +181,7 @@ describe('duplicateCheck.vue', () => { const mountOptions = getMountOptions({ router: { navigate: jest.fn() } }); - + const date = getRandomString(9, 9); const referralNumber = getRandomString(6, 6); const mainInitialState = { @@ -192,7 +192,7 @@ describe('duplicateCheck.vue', () => { vehicleMake: getRandomString(5, 5), vehicleModel: getRandomString(5, 5), dateOfLoss: date, - referralNumber: referralNumber + referralNumber } ] } @@ -211,7 +211,6 @@ describe('duplicateCheck.vue', () => { Text: duplicateOrderText, Name: referralNumber, SubText: date - }); }); test('duplicateOrder in store with null vehicle make => returns order with only date subtext', () => { @@ -354,7 +353,7 @@ describe('duplicateCheck.vue', () => { const mountOptions = getMountOptions({ router: { navigate: jest.fn() } }); - + const mainInitialState = { order: { policy: { diff --git a/src/layouts/duplicate-check/duplicate-check.vue b/src/layouts/duplicate-check/duplicate-check.vue index c98a419e..67e61a11 100644 --- a/src/layouts/duplicate-check/duplicate-check.vue +++ b/src/layouts/duplicate-check/duplicate-check.vue @@ -99,9 +99,10 @@ export default { const vehicle = !!o.vehicleYear && !!o.vehicleMake && !!o.vehicleModel ? `${o.vehicleYear} ${o.vehicleMake} ${o.vehicleModel}` : null; - const subtext = vehicle + + const subtext = vehicle && o.dateOfLoss ? `${vehicle}, ${o.dateOfLoss}` - : o.dateOfLoss; + : (vehicle ?? '').concat(o.dateOfLoss ?? ''); return { Text: duplicateOrderText, diff --git a/src/layouts/welcome-page/welcome-page.vue b/src/layouts/welcome-page/welcome-page.vue index 9b6c18ff..5c512d41 100644 --- a/src/layouts/welcome-page/welcome-page.vue +++ b/src/layouts/welcome-page/welcome-page.vue @@ -298,8 +298,9 @@ export default { }, methods: { async forwardButtonAction() { + console.log("FORWARD MARCH!"); this.mainStore.updatePolicyData(this.welcomePageModel); - const duplicateCheckResponse = useMainStore().getDuplicateReferrals(); + const duplicateCheckResponse = await useMainStore().getDuplicateReferrals(); const duplicatePromiseResultMap = [ { resultKey: 'duplicateCheckResponse', @@ -310,6 +311,7 @@ export default { this.mainStore.applicationUser.duplicateOrders = duplicateResultMap.duplicateCheckResponse ?? []; this.duplicates = duplicateResultMap.duplicateCheckResponse; + console.log(`duplicates: ${this.duplicates}`); // call coverage policy lookup if isCoverageEnabled flag enabled if (this.isCoverageEnabled) { diff --git a/src/store/index.js b/src/store/index.js index 2a6c3cda..8b93a41d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -469,27 +469,24 @@ export const useMainStore = defineStore({ }); }); }, - // TODO when endpoint finished replace dummy data with api call getDuplicateReferrals() { - const apiInputs = [ - this.issConfig.accountNumber, - this.order.policy.policyNumber, - this.order.policy.dateOfLoss - ]; - - return [ - { - referralNumber: '12345', - vehicleYear: '2013', - vehicleMake: 'Honda', - vehicleModel: 'Civic', - dateOfLoss: '09/23/2023' - }, - { - referralNumber: '34210', - dateOfLoss: '08/01/2022' - } - ]; + return new Promise((resolve, reject) => { + globalMethods.callHttpClient({ + method: endpoints.DuplicateSearch.method, + endpoint: endpoints.DuplicateSearch.url( + this.issConfig.accountNumber, + this.order.policy.policyNumber, + this.order.customer.phoneNumber?.replaceAll('-', '') + ) + }).then((r) => { + console.log(r); + this.applicationUser.duplicateOrders = r.data ?? []; + return resolve(r.data); + }).catch((error) => { + this.applicationUser.duplicateOrders = []; + return reject(error); + }); + }); }, async lookupVinByPlate(licensePlate, licenseState) { try { diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 5ee963ab..0cbfbf3d 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -977,4 +977,50 @@ describe('Store', () => { 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 = 'this is the 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); + }); + }); });