Adding new tests for getCoveragePolicyInfo
This commit is contained in:
parent
44a6ac5bca
commit
e0d4f577b7
2 changed files with 338 additions and 157 deletions
|
|
@ -387,37 +387,38 @@ export const useMainStore = defineStore({
|
|||
}
|
||||
},
|
||||
getCoveragePolicyInfo() {
|
||||
const { policy } = this.order;
|
||||
const { order } = this;
|
||||
const { policy } = order;
|
||||
return new Promise((resolve, reject) => {
|
||||
globalMethods.callHttpClient({
|
||||
method: endpoints.CoveragePolicyInfo.method,
|
||||
endpoint: endpoints.CoveragePolicyInfo.url,
|
||||
payload: {
|
||||
accountNumber: this.order.accountNumber.toString(),
|
||||
accountNumber: order.accountNumber?.toString(),
|
||||
policyNumber: policy.policyNumber,
|
||||
dateOfLoss: policy.dateOfLoss,
|
||||
zipCode: policy.policyZipCode,
|
||||
correlationId: this.order.referralCorrelationId
|
||||
correlationId: order.referralCorrelationId
|
||||
}
|
||||
}).then((r) => {
|
||||
const responsePolicy = r.data.policies?.[0];
|
||||
const responsePolicy = r?.data?.policies?.[0];
|
||||
policy.policyLookupSuccessful = !!responsePolicy;
|
||||
if (policy.policyLookupSuccessful) {
|
||||
const insured = responsePolicy?.insureds?.[0];
|
||||
const insured = responsePolicy.insureds?.[0];
|
||||
|
||||
// populate policy holder details from policy lookup
|
||||
this.order.customer.address.streetAddress = insured?.address;
|
||||
this.order.customer.address.city = insured?.city;
|
||||
this.order.customer.address.state = insured?.state;
|
||||
this.order.customer.address.zipCode = insured?.zipCode;
|
||||
this.order.customer.firstName = insured?.firstName;
|
||||
this.order.customer.lastName = insured?.lastName;
|
||||
order.customer.address.streetAddress = insured?.address;
|
||||
order.customer.address.city = insured?.city;
|
||||
order.customer.address.state = insured?.state;
|
||||
order.customer.address.zipCode = insured?.zipCode;
|
||||
order.customer.firstName = insured?.firstName;
|
||||
order.customer.lastName = insured?.lastName;
|
||||
|
||||
// populate additional fields
|
||||
this.order.serviceLocation.zipCode = insured?.zipCode;
|
||||
order.serviceLocation.zipCode = insured?.zipCode;
|
||||
|
||||
// populate vehicles
|
||||
this.order.policy.vehicles = responsePolicy?.vehicles ?? [];
|
||||
order.policy.vehicles = responsePolicy.vehicles ?? [];
|
||||
}
|
||||
return resolve(r);
|
||||
}).catch((error) => {
|
||||
|
|
@ -921,121 +922,122 @@ export const useMainStore = defineStore({
|
|||
const { vehicle, damage, policy, customer, contactInfo, payment,
|
||||
lineItems, serviceLocation, schedule } = this.order;
|
||||
const newGlassToReplace = convertGlassPieceNamingForApi(damage.glassToReplace);
|
||||
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.SaveSession.method,
|
||||
endpoint: endpoints.SaveSession.url,
|
||||
payload: {
|
||||
applicationUser: {
|
||||
crmCustomerId: this.applicationUser.crmCustomerId,
|
||||
experiments: this.applicationUser.experiments,
|
||||
lastPage: this.applicationUser.lastPageVisited,
|
||||
pageData: this.applicationUser.pageData,
|
||||
savedSessionId: this.applicationUser.savedSessionId
|
||||
},
|
||||
vehicle: {
|
||||
year: vehicle.year,
|
||||
make: vehicle.make,
|
||||
model: vehicle.model,
|
||||
style: vehicle.style,
|
||||
vin: vehicle.vin,
|
||||
carId: vehicle.carId,
|
||||
licensePlateNumber: vehicle.registration?.licensePlate
|
||||
},
|
||||
damage: {
|
||||
numberOfChips: damage.numberOfChips,
|
||||
glassToReplace: newGlassToReplace,
|
||||
isRepair: damage.isRepair,
|
||||
partQuestionAnswers: damage.partQuestionAnswers,
|
||||
moldingQuestionAnswers: damage.moldingQuestionAnswers,
|
||||
capabilityQuestionAnswers: damage.capabilityQuestionAnswers,
|
||||
dateOfLoss: policy.dateOfLoss,
|
||||
damageCause: policy.damageCause,
|
||||
damageState: policy.damageState,
|
||||
damageCity: policy.damageCity,
|
||||
isDamageGlassOnly: policy.isDamageGlassOnly
|
||||
},
|
||||
policy: {
|
||||
policyHolder: {
|
||||
policyFirstName: customer.firstName,
|
||||
policyLastName: customer.lastName,
|
||||
policyPhoneNumber: customer.phoneNumber,
|
||||
policyEmail: customer.emailAddress,
|
||||
policyState: customer.address.state
|
||||
return new Promise((resolve, reject) => {
|
||||
globalMethods.callHttpClient({
|
||||
method: endpoints.SaveSession.method,
|
||||
endpoint: endpoints.SaveSession.url,
|
||||
payload: {
|
||||
applicationUser: {
|
||||
crmCustomerId: this.applicationUser.crmCustomerId,
|
||||
experiments: this.applicationUser.experiments,
|
||||
lastPage: this.applicationUser.lastPageVisited,
|
||||
pageData: this.applicationUser.pageData,
|
||||
savedSessionId: this.applicationUser.savedSessionId
|
||||
},
|
||||
policyNumber: policy.policyNumber,
|
||||
policyZipCode: policy.policyZipCode,
|
||||
noCoverage: policy.noCoverage,
|
||||
policyLookupSuccessful: policy.policyLookupSuccessful,
|
||||
originalDeductible: this.order.originalDeductible,
|
||||
currentDeductible: this.order.currentDeductible
|
||||
},
|
||||
customer: {
|
||||
address: {
|
||||
streetAddress: customer.address?.streetAddress,
|
||||
streetAddress2: customer.address?.streetAddress2,
|
||||
city: customer.address?.city,
|
||||
state: customer.address?.state,
|
||||
zipCode: customer.address?.zipCode
|
||||
vehicle: {
|
||||
year: vehicle.year,
|
||||
make: vehicle.make,
|
||||
model: vehicle.model,
|
||||
style: vehicle.style,
|
||||
vin: vehicle.vin,
|
||||
carId: vehicle.carId,
|
||||
licensePlateNumber: vehicle.registration?.licensePlate
|
||||
},
|
||||
emailAddress: contactInfo.emailAddress,
|
||||
firstName: contactInfo.firstName || customer.firstName,
|
||||
lastName: contactInfo.lastName || customer.lastName,
|
||||
phoneNumber: contactInfo.phoneNumber,
|
||||
optInSms: contactInfo.requestTextUpdates ?? false
|
||||
},
|
||||
lineItems: {
|
||||
glassParts: lineItems.glassParts,
|
||||
supportingItems: lineItems.supportingItems,
|
||||
vaps: lineItems.vaps
|
||||
},
|
||||
payment: {
|
||||
InsuranceCoverage: {
|
||||
isVerified: payment.insuranceCoverage?.isVerified ?? false,
|
||||
coverageStatus: payment.insuranceCoverage?.coverageStatus,
|
||||
claimNumber: payment.insuranceCoverage?.claimNumber
|
||||
damage: {
|
||||
numberOfChips: damage.numberOfChips,
|
||||
glassToReplace: newGlassToReplace,
|
||||
isRepair: damage.isRepair,
|
||||
partQuestionAnswers: damage.partQuestionAnswers,
|
||||
moldingQuestionAnswers: damage.moldingQuestionAnswers,
|
||||
capabilityQuestionAnswers: damage.capabilityQuestionAnswers,
|
||||
dateOfLoss: policy.dateOfLoss,
|
||||
damageCause: policy.damageCause,
|
||||
damageState: policy.damageState,
|
||||
damageCity: policy.damageCity,
|
||||
isDamageGlassOnly: policy.isDamageGlassOnly
|
||||
},
|
||||
isInsurance: payment.isInsurance ?? true,
|
||||
parentAccountNumber: this.issConfig.parentAccountNumber
|
||||
},
|
||||
serviceLocation: {
|
||||
address: {
|
||||
streetAddress: serviceLocation.address,
|
||||
city: serviceLocation.city,
|
||||
state: serviceLocation.state,
|
||||
zipCode: serviceLocation.zipCode,
|
||||
zipCodeCtu: serviceLocation.zipCodeCtu
|
||||
policy: {
|
||||
policyHolder: {
|
||||
policyFirstName: customer.firstName,
|
||||
policyLastName: customer.lastName,
|
||||
policyPhoneNumber: customer.phoneNumber,
|
||||
policyEmail: customer.emailAddress,
|
||||
policyState: customer.address.state
|
||||
},
|
||||
policyNumber: policy.policyNumber,
|
||||
policyZipCode: policy.policyZipCode,
|
||||
noCoverage: policy.noCoverage,
|
||||
policyLookupSuccessful: policy.policyLookupSuccessful,
|
||||
originalDeductible: this.order.originalDeductible,
|
||||
currentDeductible: this.order.currentDeductible
|
||||
},
|
||||
appointmentType: serviceLocation.appointmentType,
|
||||
isVehicleProtected: serviceLocation.isVehicleProtected,
|
||||
provider: {
|
||||
providerNumber: serviceLocation.provider?.providerNumber,
|
||||
customer: {
|
||||
address: {
|
||||
streetAddress: serviceLocation.provider?.address?.streetAddress,
|
||||
city: serviceLocation.provider?.address?.city,
|
||||
state: serviceLocation.provider?.address?.state,
|
||||
zipCode: serviceLocation.provider?.address?.zipCode,
|
||||
zipCodeCtu: serviceLocation.provider?.address?.zipCodeCtu
|
||||
}
|
||||
streetAddress: customer.address?.streetAddress,
|
||||
streetAddress2: customer.address?.streetAddress2,
|
||||
city: customer.address?.city,
|
||||
state: customer.address?.state,
|
||||
zipCode: customer.address?.zipCode
|
||||
},
|
||||
emailAddress: contactInfo.emailAddress,
|
||||
firstName: contactInfo.firstName || customer.firstName,
|
||||
lastName: contactInfo.lastName || customer.lastName,
|
||||
phoneNumber: contactInfo.phoneNumber,
|
||||
optInSms: contactInfo.requestTextUpdates ?? false
|
||||
},
|
||||
techNotes: contactInfo.notesForTechnician
|
||||
lineItems: {
|
||||
glassParts: lineItems.glassParts,
|
||||
supportingItems: lineItems.supportingItems,
|
||||
vaps: lineItems.vaps
|
||||
},
|
||||
payment: {
|
||||
InsuranceCoverage: {
|
||||
isVerified: payment.insuranceCoverage?.isVerified ?? false,
|
||||
coverageStatus: payment.insuranceCoverage?.coverageStatus,
|
||||
claimNumber: payment.insuranceCoverage?.claimNumber
|
||||
},
|
||||
isInsurance: payment.isInsurance ?? true,
|
||||
parentAccountNumber: this.issConfig.parentAccountNumber
|
||||
},
|
||||
serviceLocation: {
|
||||
address: {
|
||||
streetAddress: serviceLocation.address,
|
||||
city: serviceLocation.city,
|
||||
state: serviceLocation.state,
|
||||
zipCode: serviceLocation.zipCode,
|
||||
zipCodeCtu: serviceLocation.zipCodeCtu
|
||||
},
|
||||
appointmentType: serviceLocation.appointmentType,
|
||||
isVehicleProtected: serviceLocation.isVehicleProtected,
|
||||
provider: {
|
||||
providerNumber: serviceLocation.provider?.providerNumber,
|
||||
address: {
|
||||
streetAddress: serviceLocation.provider?.address?.streetAddress,
|
||||
city: serviceLocation.provider?.address?.city,
|
||||
state: serviceLocation.provider?.address?.state,
|
||||
zipCode: serviceLocation.provider?.address?.zipCode,
|
||||
zipCodeCtu: serviceLocation.provider?.address?.zipCodeCtu
|
||||
}
|
||||
},
|
||||
techNotes: contactInfo.notesForTechnician
|
||||
},
|
||||
schedule: {
|
||||
date: schedule.date,
|
||||
startTime: schedule.startTime,
|
||||
endTime: schedule.endTime,
|
||||
routeCode: schedule.routeCode,
|
||||
jobMaxMinutes: schedule.jobMaxMinutes,
|
||||
jobMinMinutes: schedule.jobMinMinutes
|
||||
},
|
||||
referralDate: this.order.referralDate,
|
||||
referralNumber: this.order.referralNumber?.toString(),
|
||||
referralCorrelationId: this.order.referralCorrelationId,
|
||||
referralSequenceNumber: this.order.referralSequenceNumber,
|
||||
eon: this.order.eon
|
||||
},
|
||||
schedule: {
|
||||
date: schedule.date,
|
||||
startTime: schedule.startTime,
|
||||
endTime: schedule.endTime,
|
||||
routeCode: schedule.routeCode,
|
||||
jobMaxMinutes: schedule.jobMaxMinutes,
|
||||
jobMinMinutes: schedule.jobMinMinutes
|
||||
},
|
||||
referralDate: this.order.referralDate,
|
||||
referralNumber: this.order.referralNumber?.toString(),
|
||||
referralCorrelationId: this.order.referralCorrelationId,
|
||||
referralSequenceNumber: this.order.referralSequenceNumber,
|
||||
eon: this.order.eon
|
||||
},
|
||||
additionalSuccessEventDataHandler: (response) =>
|
||||
`Email provided: ${customer.emailAddress ? 'true' : 'false'}`
|
||||
additionalSuccessEventDataHandler: (response) =>
|
||||
`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
|
||||
return resolve(result);
|
||||
}, (error) => {
|
||||
console.log(error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
|
@ -1987,14 +1988,16 @@ function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {
|
|||
|
||||
function convertGlassPieceNamingForApi(glassArray) {
|
||||
// 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) {
|
||||
return glassArray;
|
||||
}
|
||||
|
||||
return glassArray?.map((glass) => new {
|
||||
location: glass.glassLocation,
|
||||
name: glass.glassName
|
||||
}()) ?? [];
|
||||
return glassArray.map((glass) => ({
|
||||
location: glass?.glassLocation,
|
||||
name: glass?.glassName
|
||||
}));
|
||||
}
|
||||
|
||||
function convertResultsForApi(resultsArray) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ describe('Store', () => {
|
|||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
console.log('HI');
|
||||
const pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
store = useMainStore();
|
||||
|
|
@ -432,7 +431,7 @@ describe('Store', () => {
|
|||
it('Call to client returns exception, resulting in object with error property being returned', async () => {
|
||||
// Arrange
|
||||
expect.assertions(5);
|
||||
const error = 'this is the error';
|
||||
const error = 'register claim error';
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
|
||||
|
||||
// Act
|
||||
|
|
@ -490,12 +489,12 @@ describe('Store', () => {
|
|||
|
||||
describe('saveSession method', () => {
|
||||
describe('successful method call', () => {
|
||||
it('calls save session api endpoint', () => {
|
||||
it('calls save session api endpoint', async () => {
|
||||
// Arrange
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Asserts
|
||||
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
|
||||
|
|
@ -514,7 +513,7 @@ describe('Store', () => {
|
|||
// Asserts
|
||||
await expect(result).resolves.toBe(response);
|
||||
});
|
||||
it('calls api with expected application user data', () => {
|
||||
it('calls api with expected application user data', async () => {
|
||||
// Arrange
|
||||
const crmCustomerId = getRandomString(6, 6);
|
||||
const experiments = getRandomString(6, 6);
|
||||
|
|
@ -529,7 +528,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Asserts
|
||||
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 make = getRandomString(6, 6);
|
||||
const model = getRandomString(6, 6);
|
||||
|
|
@ -562,7 +561,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Asserts
|
||||
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
|
||||
const isRepair = getRandomString(6, 6);
|
||||
const numberOfChips = getRandomString(6, 6);
|
||||
|
|
@ -604,7 +603,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Assert
|
||||
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
|
||||
const customerFirstName = getRandomString(6, 6);
|
||||
const customerLastName = getRandomString(6, 6);
|
||||
|
|
@ -651,7 +650,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Asserts
|
||||
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
|
||||
const streetAddress = getRandomString(6, 6);
|
||||
const streetAddress2 = getRandomString(6, 6);
|
||||
|
|
@ -700,7 +699,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Assert
|
||||
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
|
||||
const glassParts = getRandomString(6, 6);
|
||||
const supportingItems = getRandomString(6, 6);
|
||||
|
|
@ -734,7 +733,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Assert
|
||||
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
|
||||
|
|
@ -751,7 +750,7 @@ describe('Store', () => {
|
|||
[coverageStatuses.PENDING],
|
||||
[coverageStatuses.NO_COMP],
|
||||
[coverageStatuses.VERIFIED]
|
||||
])('calls api with expected payment', (coverageStatus) => {
|
||||
])('calls api with expected payment', async (coverageStatus) => {
|
||||
// Arrange
|
||||
const parentAccountNumber = getRandomString(6, 6);
|
||||
const isInsurance = getRandomBoolean();
|
||||
|
|
@ -763,7 +762,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Assert
|
||||
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
|
||||
const notesForTechnician = getRandomString(6, 6);
|
||||
const address = getRandomString(6, 6);
|
||||
|
|
@ -797,7 +796,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Assert
|
||||
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
|
||||
const date = getRandomString(6, 6);
|
||||
const startTime = getRandomString(6, 6);
|
||||
|
|
@ -833,7 +832,7 @@ describe('Store', () => {
|
|||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Assert
|
||||
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
|
||||
const referralDate = getRandomString(6, 6);
|
||||
store.order.referralDate = referralDate;
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Assert
|
||||
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
|
||||
payload: expect.objectContaining({ referralDate })
|
||||
}));
|
||||
});
|
||||
it('calls api with expected referral number', () => {
|
||||
it('calls api with expected referral number', async () => {
|
||||
// Arrange
|
||||
const referralNumber = getRandomString(6, 6);
|
||||
store.order.referralNumber = referralNumber;
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
|
||||
// Act
|
||||
store.saveSession();
|
||||
await store.saveSession();
|
||||
|
||||
// Assert
|
||||
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
|
||||
|
|
@ -938,7 +937,7 @@ describe('Store', () => {
|
|||
});
|
||||
it('api call throws exception', async () => {
|
||||
expect.assertions(2);
|
||||
const error = 'this is the error';
|
||||
const error = 'save session error';
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
|
||||
|
||||
// Act
|
||||
|
|
@ -954,7 +953,7 @@ describe('Store', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe.only('loadSession method', () => {
|
||||
describe('loadSession method', () => {
|
||||
describe('successful method call', () => {
|
||||
const applicationUser = {
|
||||
crmCustomerId: getRandomString(6, 6),
|
||||
|
|
@ -1329,7 +1328,7 @@ describe('Store', () => {
|
|||
});
|
||||
it('api call throws exception', async () => {
|
||||
expect.assertions(2);
|
||||
const error = 'this is the error';
|
||||
const error = 'load session error';
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
|
||||
|
||||
// Act
|
||||
|
|
@ -1347,7 +1346,186 @@ describe('Store', () => {
|
|||
});
|
||||
|
||||
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', () => {
|
||||
|
|
@ -1404,7 +1582,7 @@ describe('Store', () => {
|
|||
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';
|
||||
const error = 'get duplicate referrals error';
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
|
||||
|
||||
// Act
|
||||
|
|
|
|||
Loading…
Reference in a new issue