Adding new tests for getCoveragePolicyInfo

This commit is contained in:
Michaela Brydon 2023-10-11 23:22:37 -04:00
parent 44a6ac5bca
commit e0d4f577b7
2 changed files with 338 additions and 157 deletions

View file

@ -387,37 +387,38 @@ export const useMainStore = defineStore({
} }
}, },
getCoveragePolicyInfo() { getCoveragePolicyInfo() {
const { policy } = this.order; const { order } = this;
const { policy } = order;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
globalMethods.callHttpClient({ globalMethods.callHttpClient({
method: endpoints.CoveragePolicyInfo.method, method: endpoints.CoveragePolicyInfo.method,
endpoint: endpoints.CoveragePolicyInfo.url, endpoint: endpoints.CoveragePolicyInfo.url,
payload: { payload: {
accountNumber: this.order.accountNumber.toString(), accountNumber: order.accountNumber?.toString(),
policyNumber: policy.policyNumber, policyNumber: policy.policyNumber,
dateOfLoss: policy.dateOfLoss, dateOfLoss: policy.dateOfLoss,
zipCode: policy.policyZipCode, zipCode: policy.policyZipCode,
correlationId: this.order.referralCorrelationId correlationId: order.referralCorrelationId
} }
}).then((r) => { }).then((r) => {
const responsePolicy = r.data.policies?.[0]; const responsePolicy = r?.data?.policies?.[0];
policy.policyLookupSuccessful = !!responsePolicy; policy.policyLookupSuccessful = !!responsePolicy;
if (policy.policyLookupSuccessful) { if (policy.policyLookupSuccessful) {
const insured = responsePolicy?.insureds?.[0]; const insured = responsePolicy.insureds?.[0];
// populate policy holder details from policy lookup // populate policy holder details from policy lookup
this.order.customer.address.streetAddress = insured?.address; order.customer.address.streetAddress = insured?.address;
this.order.customer.address.city = insured?.city; order.customer.address.city = insured?.city;
this.order.customer.address.state = insured?.state; order.customer.address.state = insured?.state;
this.order.customer.address.zipCode = insured?.zipCode; order.customer.address.zipCode = insured?.zipCode;
this.order.customer.firstName = insured?.firstName; order.customer.firstName = insured?.firstName;
this.order.customer.lastName = insured?.lastName; order.customer.lastName = insured?.lastName;
// populate additional fields // populate additional fields
this.order.serviceLocation.zipCode = insured?.zipCode; order.serviceLocation.zipCode = insured?.zipCode;
// populate vehicles // populate vehicles
this.order.policy.vehicles = responsePolicy?.vehicles ?? []; order.policy.vehicles = responsePolicy.vehicles ?? [];
} }
return resolve(r); return resolve(r);
}).catch((error) => { }).catch((error) => {
@ -921,8 +922,8 @@ export const useMainStore = defineStore({
const { vehicle, damage, policy, customer, contactInfo, payment, const { vehicle, damage, policy, customer, contactInfo, payment,
lineItems, serviceLocation, schedule } = this.order; lineItems, serviceLocation, schedule } = this.order;
const newGlassToReplace = convertGlassPieceNamingForApi(damage.glassToReplace); const newGlassToReplace = convertGlassPieceNamingForApi(damage.glassToReplace);
return new Promise((resolve, reject) => {
return globalMethods.callHttpClient({ globalMethods.callHttpClient({
method: endpoints.SaveSession.method, method: endpoints.SaveSession.method,
endpoint: endpoints.SaveSession.url, endpoint: endpoints.SaveSession.url,
payload: { payload: {
@ -1036,6 +1037,7 @@ export const useMainStore = defineStore({
}, },
additionalSuccessEventDataHandler: (response) => additionalSuccessEventDataHandler: (response) =>
`Email provided: ${customer.emailAddress ? 'true' : 'false'}` `Email provided: ${customer.emailAddress ? 'true' : 'false'}`
}).then((response) => resolve(response), (error) => reject(error));
}); });
}, },
@ -1159,7 +1161,6 @@ export const useMainStore = defineStore({
// TODO order.workOrderNumber not set, but this likely is not an issue since WON => will not return // TODO order.workOrderNumber not set, but this likely is not an issue since WON => will not return
return resolve(result); return resolve(result);
}, (error) => { }, (error) => {
console.log(error);
reject(error); reject(error);
}); });
}); });
@ -1987,14 +1988,16 @@ function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {
function convertGlassPieceNamingForApi(glassArray) { function convertGlassPieceNamingForApi(glassArray) {
// check if array already converted. (likely when a session has been saved previously and then reloaded) // check if array already converted. (likely when a session has been saved previously and then reloaded)
if (glassArray == null || glassArray.length === 0) return [];
if (glassArray[0].location !== undefined) { if (glassArray[0].location !== undefined) {
return glassArray; return glassArray;
} }
return glassArray?.map((glass) => new { return glassArray.map((glass) => ({
location: glass.glassLocation, location: glass?.glassLocation,
name: glass.glassName name: glass?.glassName
}()) ?? []; }));
} }
function convertResultsForApi(resultsArray) { function convertResultsForApi(resultsArray) {

View file

@ -10,7 +10,6 @@ describe('Store', () => {
let store; let store;
beforeEach(() => { beforeEach(() => {
console.log('HI');
const pinia = createPinia(); const pinia = createPinia();
setActivePinia(pinia); setActivePinia(pinia);
store = useMainStore(); store = useMainStore();
@ -432,7 +431,7 @@ describe('Store', () => {
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 // Arrange
expect.assertions(5); expect.assertions(5);
const error = 'this is the error'; const error = 'register claim error';
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
// Act // Act
@ -490,12 +489,12 @@ describe('Store', () => {
describe('saveSession method', () => { describe('saveSession method', () => {
describe('successful method call', () => { describe('successful method call', () => {
it('calls save session api endpoint', () => { it('calls save session api endpoint', async () => {
// Arrange // Arrange
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -514,7 +513,7 @@ describe('Store', () => {
// Asserts // Asserts
await expect(result).resolves.toBe(response); await expect(result).resolves.toBe(response);
}); });
it('calls api with expected application user data', () => { it('calls api with expected application user data', async () => {
// Arrange // Arrange
const crmCustomerId = getRandomString(6, 6); const crmCustomerId = getRandomString(6, 6);
const experiments = getRandomString(6, 6); const experiments = getRandomString(6, 6);
@ -529,7 +528,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -544,7 +543,7 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected vehicle', () => { it('calls api with expected vehicle', async () => {
const year = getRandomString(6, 6); const year = getRandomString(6, 6);
const make = getRandomString(6, 6); const make = getRandomString(6, 6);
const model = getRandomString(6, 6); const model = getRandomString(6, 6);
@ -562,7 +561,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -579,7 +578,7 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected damage', () => { it('calls api with expected damage', async () => {
// Arrange // Arrange
const isRepair = getRandomString(6, 6); const isRepair = getRandomString(6, 6);
const numberOfChips = getRandomString(6, 6); const numberOfChips = getRandomString(6, 6);
@ -604,7 +603,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -624,7 +623,7 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected policy', () => { it('calls api with expected policy', async () => {
// Arrange // Arrange
const customerFirstName = getRandomString(6, 6); const customerFirstName = getRandomString(6, 6);
const customerLastName = getRandomString(6, 6); const customerLastName = getRandomString(6, 6);
@ -651,7 +650,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -674,7 +673,7 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected customer', () => { it('calls api with expected customer', async () => {
// Arrange // Arrange
const streetAddress = getRandomString(6, 6); const streetAddress = getRandomString(6, 6);
const streetAddress2 = getRandomString(6, 6); const streetAddress2 = getRandomString(6, 6);
@ -700,7 +699,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -722,7 +721,7 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected lineItems', () => { it('calls api with expected lineItems', async () => {
// Arrange // Arrange
const glassParts = getRandomString(6, 6); const glassParts = getRandomString(6, 6);
const supportingItems = getRandomString(6, 6); const supportingItems = getRandomString(6, 6);
@ -734,7 +733,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -751,7 +750,7 @@ describe('Store', () => {
[coverageStatuses.PENDING], [coverageStatuses.PENDING],
[coverageStatuses.NO_COMP], [coverageStatuses.NO_COMP],
[coverageStatuses.VERIFIED] [coverageStatuses.VERIFIED]
])('calls api with expected payment', (coverageStatus) => { ])('calls api with expected payment', async (coverageStatus) => {
// Arrange // Arrange
const parentAccountNumber = getRandomString(6, 6); const parentAccountNumber = getRandomString(6, 6);
const isInsurance = getRandomBoolean(); const isInsurance = getRandomBoolean();
@ -763,7 +762,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -779,7 +778,7 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected service location', () => { it('calls api with expected service location', async () => {
// Arrange // Arrange
const notesForTechnician = getRandomString(6, 6); const notesForTechnician = getRandomString(6, 6);
const address = getRandomString(6, 6); const address = getRandomString(6, 6);
@ -797,7 +796,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -815,7 +814,7 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected schedule', () => { it('calls api with expected schedule', async () => {
// Arrange // Arrange
const date = getRandomString(6, 6); const date = getRandomString(6, 6);
const startTime = getRandomString(6, 6); const startTime = getRandomString(6, 6);
@ -833,7 +832,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -849,28 +848,28 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected referral date', () => { it('calls api with expected referral date', async () => {
// Arrange // Arrange
const referralDate = getRandomString(6, 6); const referralDate = getRandomString(6, 6);
store.order.referralDate = referralDate; store.order.referralDate = referralDate;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({ referralDate }) payload: expect.objectContaining({ referralDate })
})); }));
}); });
it('calls api with expected referral number', () => { it('calls api with expected referral number', async () => {
// Arrange // Arrange
const referralNumber = getRandomString(6, 6); const referralNumber = getRandomString(6, 6);
store.order.referralNumber = referralNumber; store.order.referralNumber = referralNumber;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
store.saveSession(); await store.saveSession();
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -938,7 +937,7 @@ describe('Store', () => {
}); });
it('api call throws exception', async () => { it('api call throws exception', async () => {
expect.assertions(2); expect.assertions(2);
const error = 'this is the error'; const error = 'save session error';
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
// Act // Act
@ -954,7 +953,7 @@ describe('Store', () => {
}); });
}); });
describe.only('loadSession method', () => { describe('loadSession method', () => {
describe('successful method call', () => { describe('successful method call', () => {
const applicationUser = { const applicationUser = {
crmCustomerId: getRandomString(6, 6), crmCustomerId: getRandomString(6, 6),
@ -1329,7 +1328,7 @@ describe('Store', () => {
}); });
it('api call throws exception', async () => { it('api call throws exception', async () => {
expect.assertions(2); expect.assertions(2);
const error = 'this is the error'; const error = 'load session error';
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
// Act // Act
@ -1347,7 +1346,186 @@ describe('Store', () => {
}); });
describe('getCoveragePolicyInfo method', () => { describe('getCoveragePolicyInfo method', () => {
// TODO add tests 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 correlationId = 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 = correlationId;
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,
correlationId
})
}));
});
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', () => { describe('saveEndorsementQuestionAnswers method', () => {
@ -1404,7 +1582,7 @@ describe('Store', () => {
it('Call to client returns exception => object with error property returned and duplicateReferrals set to []', async () => { it('Call to client returns exception => object with error property returned and duplicateReferrals set to []', async () => {
// Arrange // Arrange
expect.assertions(3); expect.assertions(3);
const error = 'this is the error'; const error = 'get duplicate referrals error';
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
// Act // Act