From dec8f048d6ae5158e702f1f35b9ca3cfe0307aa9 Mon Sep 17 00:00:00 2001 From: hiteshkumar87 Date: Thu, 2 Mar 2023 12:52:51 +0530 Subject: [PATCH] SSR-268 updated endpoint to get prohibited states with single source of truth --- src/constants/endpoints.js | 4 +++ .../vehicle-lookup/vehicle-lookup.spec.js | 28 +++++++++++++++++-- .../vin-lookup-methods/vin-lookup-methods.vue | 23 ++++++++++++++- src/store/index.js | 19 +++++++++++-- 4 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 36d21a69..27cc4df1 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -98,6 +98,10 @@ const endpoints = { url: "/clientauth/api/v1/clientauth/validateClientTag", method: "GET", }, + IsVinbyAddressPermissible:{ + url:"/vehicle/api/v1/vehicle/is-vin-by-address-permissible", + method:"Get", + } }; export { endpoints }; diff --git a/src/layouts/vehicle-lookup/vehicle-lookup.spec.js b/src/layouts/vehicle-lookup/vehicle-lookup.spec.js index 12a84a88..11b7b309 100644 --- a/src/layouts/vehicle-lookup/vehicle-lookup.spec.js +++ b/src/layouts/vehicle-lookup/vehicle-lookup.spec.js @@ -5,6 +5,7 @@ import { issPageValues } from '@/router/router-constants/issPage-values'; import { queryStrings } from '@/constants/query-strings'; import { GaActions } from "@/constants/analytics"; import VehicleLookup from './vehicle-lookup.vue'; +import VIN_LOOKUP_METHODS from '@/constants/vin-lookup-methods'; const vinLookupMethodsMockData = { QuestionText: 'To find the right part, let’s get your VIN. Or we can look it up for you!', @@ -47,6 +48,10 @@ function setupMocks() { const mockRouter = { navigate: jest.fn(), }; + + const mockIsVinbyAddressPermissibleToBeFalse={ + IsVinbyAddressPermissible:false, + }; const wrapper = mount(VehicleLookup, { data() { @@ -95,7 +100,7 @@ function setupMocks() { ], mocks: { $route: mockRoute, - $router: mockRouter, + $router: mockRouter, }, stubs: { SiteHeader: true, @@ -105,10 +110,29 @@ function setupMocks() { }, }); - return { mockRoute, mockRouter, wrapper }; + return { mockRoute, mockRouter, wrapper,mockIsVinbyAddressPermissibleToBeFalse }; } describe('vehicle-lookup.vue', () => { + test('IsVinbyAddressPermissible to be false', () => { + const { wrapper,mockIsVinbyAddressPermissibleToBeFalse } = setupMocks(); + + const vinLookupMethodsWrapper = wrapper.findComponent({ name: 'vin-lookup-methods' }); + // Not using initializeComponent() because it doesn't trigger reactivity in test. + const Answers = JSON.parse(JSON.stringify(vinLookupMethodsMockData.Answers)); + if(!mockIsVinbyAddressPermissibleToBeFalse.IsVinbyAddressPermissible){ + Answers.splice(Answers.indexOf(VIN_LOOKUP_METHODS.homeAddress),1); + } + vinLookupMethodsWrapper.setData({ + questionTextFromCms: vinLookupMethodsMockData.QuestionText, + answersFromCms: Answers, + }); + + const lookupByAddressOptionLabel = wrapper.find('[data-test-id="vin-lookup-methods-button-question"] label[for="VinLookupMethods-HomeAddress"]'); + expect(lookupByAddressOptionLabel.exists()).toBe(false); + + }); + test('"Continue" button is disabled when no VIN Lookup method is selected.', () => { const { wrapper } = setupMocks(); diff --git a/src/layouts/vehicle-lookup/vin-lookup-methods/vin-lookup-methods.vue b/src/layouts/vehicle-lookup/vin-lookup-methods/vin-lookup-methods.vue index e5b8bee2..706ec731 100644 --- a/src/layouts/vehicle-lookup/vin-lookup-methods/vin-lookup-methods.vue +++ b/src/layouts/vehicle-lookup/vin-lookup-methods/vin-lookup-methods.vue @@ -16,6 +16,9 @@ import { defineRule } from 'vee-validate'; import { required } from '@/helpers/validation-rules'; import { errorMessages } from '@/constants/error-messages'; +import { useMainStore } from "@/store"; +import VIN_LOOKUP_METHODS from '@/constants/vin-lookup-methods'; +import { settleAllPromises } from "@/helpers/layout-helper"; // Import Component import ButtonQuestion from '@/digital-components/button-question/button-question.vue'; @@ -38,6 +41,7 @@ export default { required, }, }, + emits: ['update:modelValue'], components: { ButtonQuestion, @@ -53,14 +57,31 @@ export default { }, }, methods: { - initializeComponent() { + async initializeComponent() { + const isVinbyAddressPermissible = await this.getIsVinbyAddressPermissible(); this.questionTextFromCms = this.getCmsContent(this.cmsWidgetName, 'QuestionText'); const answers = this.getCmsContent(this.cmsWidgetName, 'Answers'); if (Array.isArray(answers)) { + if(!isVinbyAddressPermissible){ + answers.splice(answers.indexOf(VIN_LOOKUP_METHODS.homeAddress),1); + } this.answersFromCms = answers; } }, + async getIsVinbyAddressPermissible(){ + const isVinbyAddressPermissibleResponse = useMainStore().getIsVinbyAddressPermissible(); + // Settle promises and get results + const promiseResultMap = [ + { + resultKey: "isVinbyAddressPermissible", + promise: isVinbyAddressPermissibleResponse, + } + ]; + + const resultMap = await settleAllPromises(promiseResultMap); + return resultMap.isVinbyAddressPermissible; + } }, }; diff --git a/src/store/index.js b/src/store/index.js index 19aff5c1..f08af4e8 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -298,7 +298,22 @@ export const useMainStore = defineStore({ payload: {}, }); }, - + getIsVinbyAddressPermissible(){ + try{ + const response = globalMethods.callHttpClient({ + method:endpoints.IsVinbyAddressPermissible.method, + endpoint:`${endpoints.IsVinbyAddressPermissible.url}?state=${this.order.customer.address.state}`, + payload: {}, + }); + return response; + } catch (responseError) { + return { + error: { + status: responseError.status, + }, + }; + } + }, async lookupVinByPlate(licensePlate, licenseState) { try { const response = await globalMethods.callHttpClient({ @@ -1028,7 +1043,7 @@ export const useMainStore = defineStore({ resetPartsAndDependencies() { this.resetGlassPartsState(); this.updateSupportingItems(null); - }, + }, }, persist: true });