Wiring up duplicate search

This commit is contained in:
brydon1 2023-09-28 16:54:48 -04:00
parent f616433fe3
commit b06057576c
6 changed files with 79 additions and 29 deletions

View file

@ -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'
}
});

View file

@ -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: {

View file

@ -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,

View file

@ -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) {

View file

@ -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 {

View file

@ -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);
});
});
});