DigitalConsumer.ISS/src/store/store.spec.js
2023-10-05 17:00:15 -04:00

1101 lines
41 KiB
JavaScript

import { useMainStore } from '@/store/index.js';
import { setActivePinia, createPinia } from 'pinia';
import globalMethods from '@/global-methods.js';
import { getRandomString, getRandomGuid, getRandomInt, getRandomBoolean } from '@/helpers/data-generation.js';
import coverageStatuses from '@/constants/coverage-statuses.js';
import { endpoints } from '@/constants/endpoints';
import { AppointmentTypeStrings } from '@/constants/schedule-constants';
describe('Store', () => {
let store;
beforeEach(() => {
const pinia = createPinia();
setActivePinia(pinia);
store = useMainStore();
store.applicationUser.eventBus = [];
jest.resetAllMocks();
});
it('Should Store Vehicle Year', () => {
const testYear = '2001';
store.updateVehicleYear(testYear);
expect(store.order.vehicle.year).toEqual(testYear);
});
it('Should add events to the bus', () => {
// Arrange
const category = getRandomString(1, 25);
const subCategory = getRandomString(5, 20);
const isDismissible = getRandomBoolean();
const copy = getRandomString(5, 25);
const headline = getRandomString(5, 25);
const type = getRandomString(5, 15);
const event = {
category,
subCategory,
eventValue: {
isDismissible,
messageCopy: copy,
messageHeadline: headline,
type
}
};
// Act
store.addEventToBus(event);
// Assert
expect(store.applicationUser.eventBus[0]).toEqual(event);
});
it('Should remove events from the bus', () => {
// Arrange
const category = getRandomString(1, 25);
const subCategory = getRandomString(5, 20);
const isDismissible = getRandomBoolean();
const copy = getRandomString(5, 25);
const headline = getRandomString(5, 25);
const type = getRandomString(5, 15);
const event = {
category,
subCategory,
eventValue: {
isDismissible,
messageCopy: copy,
messageHeadline: headline,
type
}
};
store.addEventToBus(event);
expect(store.applicationUser.eventBus.length).toBe(1);
// Act
store.removeEventFromBus({ category: event.category, subCategory: event.subCategory });
// Assert
expect(store.applicationUser.eventBus.length).toBe(0);
});
it('Should return correct event using the getter function eventBusItem', () => {
// Arrange
const category = getRandomString(1, 25);
const subCategory = getRandomString(5, 20);
const isDismissible = getRandomBoolean();
const copy = getRandomString(5, 25);
const headline = getRandomString(5, 25);
const type = getRandomString(5, 15);
const event = {
category,
subCategory,
eventValue: {
isDismissible,
messageCopy: copy,
messageHeadline: headline,
type
}
};
store.addEventToBus(event);
// Act
const actual = store.eventBusItem(event.category, event.subCategory);
// Assert
expect(actual).toEqual(event.eventValue);
});
it('UpdateVehicle should merge vehicle with response object', () => {
// Arrange
const carId = getRandomString(10, 14);
const category = getRandomString(3, 7);
const year = getRandomInt(1960, 2023);
const make = getRandomString(4, 10);
const model = getRandomString(4, 10);
const style = getRandomString(4, 15);
const imageUrl = getRandomString(50, 100);
const imageVifNumber = getRandomInt(10000, 99999).toString();
const imageColor = getRandomString(4, 10);
const providedVehicle = {
carId,
category,
year,
make,
model,
style,
imageUrl,
imageVifNumber,
imageVifColor: imageColor
};
const expectedVehicle = {
carId,
category,
year,
make,
model,
style,
imageUrl,
imageVifNumber,
imageColor
};
// Act
store.updateVehicle(providedVehicle);
// Assert
expect(store.order.vehicle).toMatchObject(expectedVehicle);
});
it('UpdateVehicle should set policy values appropriately with repair waived', () => {
// Arrange
const noCoverage = getRandomBoolean();
const deductible = getRandomInt(1, 500);
const vehicle = {
noCoverage,
deductible,
repairWaived: true
};
const expectedPolicy = {
noCoverage,
deductible: {
replace: deductible,
repair: 0
}
};
// Act
store.updateVehicle(vehicle);
// Assert
expect(store.order.policy).toMatchObject(expectedPolicy);
});
it('UpdateVehicle should set policy values appropriately with repair not waived', () => {
// Arrange
const noCoverage = getRandomBoolean();
const deductible = getRandomInt(1, 500);
const vehicle = {
noCoverage,
deductible,
repairWaived: false
};
const expectedPolicy = {
noCoverage,
deductible: {
replace: deductible,
repair: deductible
}
};
// Act
store.updateVehicle(vehicle);
// Assert
expect(store.order.policy).toMatchObject(expectedPolicy);
});
it.each([
[true, coverageStatuses.NO_COMP],
[false, coverageStatuses.PENDING]
])(
'UpdateVehicle should set coverageStatus appropriately based on noCoverage value',
(expectedNoCoverage, expectedCoverageStatus) => {
// Arrange
const vehicle = {
noCoverage: expectedNoCoverage
};
// Act
store.updateVehicle(vehicle);
// Assert
expect(store.order.policy.noCoverage).toBe(expectedNoCoverage);
expect(store.order.payment.insuranceCoverage.coverageStatus).toBe(expectedCoverageStatus);
}
);
// TODO update test to work also checking store values
it('setVehicle should call globalMethods.callHttpClient', () => {
// Arrange
const carId = getRandomString(10, 14);
const category = getRandomString(3, 7);
const year = getRandomInt(1960, 2023);
const make = getRandomString(4, 10);
const model = getRandomString(4, 10);
const style = getRandomString(4, 15);
const imageUrl = getRandomString(50, 100);
const imageVifNumber = getRandomInt(10000, 99999).toString();
const imageColor = getRandomString(4, 10);
const response = {
data: {
carId,
category,
year,
make,
model,
style,
imageUrl,
imageVifNumber,
imageVifColor: imageColor
}
};
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));
// Act
const returned = store.setVehicle();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalled();
expect(returned).resolves.toMatchObject(response);
});
it('saveVehicleDamage with windshield repair should update damage with number of chips not null', () => {
// Arrange
const glassName = getRandomString(4, 10);
const glassLocation = getRandomString(5, 15);
const isWindshieldRepair = true;
const selectedGlassToReplace = [{
glassName,
glassLocation
}];
const chipCount = getRandomInt(0, 3);
// Act
store.saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, chipCount);
// Assert
expect(store.order.damage.glassToReplace).toEqual(selectedGlassToReplace);
expect(store.order.damage.isRepair).toEqual(isWindshieldRepair);
expect(store.order.damage.numberOfChips).toEqual(chipCount);
});
it('saveVehicleDamage without windshield repair should update damage with number of chips null', () => {
// Arrange
const glassName = getRandomString(4, 10);
const glassLocation = getRandomString(5, 15);
const isWindshieldRepair = false;
const selectedGlassToReplace = [{
glassName,
glassLocation
}];
const chipCount = getRandomInt(0, 3);
const expectedChipCount = null;
// Act
store.saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, chipCount);
// Assert
expect(store.order.damage.glassToReplace).toEqual(selectedGlassToReplace);
expect(store.order.damage.isRepair).toEqual(isWindshieldRepair);
expect(store.order.damage.numberOfChips).toEqual(expectedChipCount);
});
it('should return registration data if available', () => {
// Arrange
const streetAddress = getRandomString(5, 15);
const city = getRandomString(5, 15);
const state = getRandomString(5, 10);
const zipCode = getRandomInt(10000, 99999).toString();
const firstName = getRandomString(5, 20);
const lastName = getRandomString(5, 20);
const expected = {
addressQuestions: {
streetAddress,
city,
state,
zipCode
},
firstName,
lastName
};
store.order.vehicle.registration = {
licensePlate: null,
address: streetAddress,
city,
state,
zipCode,
firstName,
lastName
};
// Act
const actual = store.customerData;
// Assert
expect(actual).toEqual(expected);
});
it('should return customer data if registration data unavailable', () => {
// Arrange
const address = getRandomString(1, 25);
const city = getRandomString(5, 20);
const state = getRandomString(4, 20);
const zipCode = getRandomInt(10000, 99999).toString();
const firstName = getRandomString(5, 25);
const lastName = getRandomString(5, 25);
const expected = {
addressQuestions: {
streetAddress: address,
city,
state,
zipCode
},
firstName,
lastName
};
store.order.vehicle.registration.address = null;
store.order.customer = {
address: {
streetAddress: address,
city,
state,
zipCode
},
firstName,
lastName
};
// Act
const actual = store.customerData;
// Assert
expect(actual).toMatchObject(expected);
});
describe('registerClaim method', () => {
it('successful response with no coverage => isVerified true and coverage status no comp', async () => {
// Arrange
const response = {
data: {
claimantId: null,
claimNumber: getRandomString(9, 9),
correlationId: getRandomGuid(),
isSuccess: true,
isError: false,
successMessage: getRandomString(9, 9),
deductible: 0
}
};
store.policy.noCoverage = true;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));
// Act
await store.registerClaim();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalled();
expect(store.payment.insuranceCoverage.isVerified).toBe(true);
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.NO_COMP);
expect(store.payment.insuranceCoverage.claimNumber).toBe(null);
});
it('successful response with coverage => isVerified true and coverage status verified', async () => {
// Arrange
const response = {
data: {
claimantId: null,
claimNumber: getRandomString(9, 9),
correlationId: getRandomGuid(),
isSuccess: true,
isError: false,
successMessage: getRandomString(9, 9),
deductible: 0
}
};
store.policy.noCoverage = false;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));
// Act
await store.registerClaim();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalled();
expect(store.payment.insuranceCoverage.isVerified).toBe(true);
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.VERIFIED);
expect(store.payment.insuranceCoverage.claimNumber).toBe(response.data.claimNumber);
});
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';
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
// Act
await store.registerClaim().catch((e) => {
expect(e).toEqual(error);
});
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalled();
expect(store.payment.insuranceCoverage.isVerified).toBe(false);
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.PENDING);
expect(store.payment.insuranceCoverage.claimNumber).toBe(null);
});
});
describe('updateContactInfo method', () => {
it('UpdateContactInfo updates contact info in store', () => {
// Arrange
const firstName = getRandomString(4, 10);
const lastName = getRandomString(5, 15);
const emailAddress = false;
const phoneNumber = getRandomInt(1000000000, 9999999999);
const requestTextUpdates = getRandomBoolean();
const notesForTechnician = getRandomString(50, 150);
// Act
store.updateContactInfo({ firstName,
lastName,
emailAddress,
phoneNumber,
requestTextUpdates,
notesForTechnician });
// Assert
expect(store.contactInfo.firstName).toEqual(firstName);
expect(store.contactInfo.lastName).toEqual(lastName);
expect(store.contactInfo.emailAddress).toEqual(emailAddress);
expect(store.contactInfo.phoneNumber).toEqual(phoneNumber);
expect(store.contactInfo.requestTextUpdates).toEqual(requestTextUpdates);
expect(store.contactInfo.notesForTechnician).toEqual(notesForTechnician);
});
it('All null values => contact info set in store to all nulls', () => {
// Act
store.updateContactInfo({});
// Assert
expect(store.contactInfo.firstName).toEqual('');
expect(store.contactInfo.lastName).toEqual('');
expect(store.contactInfo.emailAddress).toEqual('');
expect(store.contactInfo.phoneNumber).toEqual('');
expect(store.contactInfo.requestTextUpdates).toEqual(false);
expect(store.contactInfo.notesForTechnician).toEqual('');
});
});
describe('saveSession method', () => {
describe('successful method call', () => {
it('calls save session api endpoint', () => {
// Arrange
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
method: endpoints.SaveSession.method,
endpoint: endpoints.SaveSession.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.saveSession();
// Asserts
await expect(result).resolves.toBe(response);
});
it('calls api with expected application user data', () => {
// Arrange
const applicationUser = {
crmCustomerId: getRandomString(6, 6),
experiments: getRandomString(6, 6),
lastPageVisited: getRandomString(6, 6),
pageData: getRandomString(6, 6),
savedSessionId: getRandomString(6, 6)
};
store.applicationUser = applicationUser;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
const result = store.saveSession();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
applicationUser: expect.objectContaining({
crmCustomerId: applicationUser.crmCustomerId,
experiments: applicationUser.experiments,
lastPage: applicationUser.lastPageVisited,
pageData: applicationUser.pageData,
savedSessionId: applicationUser.savedSessionId
})
})
}));
});
it('calls api with expected vehicle', () => {
const vehicle = {
year: getRandomString(6, 6),
make: getRandomString(6, 6),
model: getRandomString(6, 6),
style: getRandomString(6, 6),
carId: getRandomString(6, 6),
vin: getRandomString(6, 6),
registration: { licensePlate: getRandomString(6, 6) }
};
store.order.vehicle = vehicle;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
vehicle: expect.objectContaining({
year: vehicle.year,
make: vehicle.make,
model: vehicle.model,
style: vehicle.style,
carId: vehicle.carId,
vin: vehicle.vin,
licensePlateNumber: vehicle.registration.licensePlate
})
})
}));
});
it('calls api with expected damage', () => {
// Arrange
const damage = {
isRepair: getRandomString(6, 6),
numberOfChips: getRandomString(6, 6),
glassToReplace: [],
partQuestionAnswers: getRandomString(6, 6),
moldingQuestionAnswers: getRandomString(6, 6),
capabilityQuestionAnswers: getRandomString(6, 6)
};
const policy = {
dateOfLoss: getRandomString(6, 6),
damageCause: getRandomString(6, 6),
damageState: getRandomString(6, 6),
damageCity: getRandomString(6, 6),
isDamageGlassOnly: getRandomString(6, 6)
};
store.order.damage = damage;
store.order.policy = policy;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
damage: expect.objectContaining({
numberOfChips: damage.numberOfChips,
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
})
})
}));
});
it('calls api with expected policy', () => {
// Arrange
const customer = {
firstName: getRandomString(6, 6),
lastName: getRandomString(6, 6),
emailAddress: getRandomString(6, 6),
phoneNumber: getRandomString(6, 6),
address: {
state: getRandomString(2, 2)
}
};
const policy = {
policyNumber: getRandomString(6, 6),
policyZipCode: getRandomString(6, 6),
policyLookupSuccessful: getRandomString(6, 6),
noCoverage: getRandomString(6, 6)
};
const originalDeductible = getRandomString(6, 6);
const currentDeductible = getRandomString(6, 6);
store.order.originalDeductible = originalDeductible;
store.order.currentDeductible = currentDeductible;
store.order.customer = customer;
store.order.policy = policy;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
policy: expect.objectContaining({
policyHolder: expect.objectContaining({
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,
currentDeductible
})
})
}));
});
it('calls api with expected customer', () => {
// Arrange
const customer = {
address: {
streetAddress: getRandomString(6, 6),
streetAddress2: getRandomString(6, 6),
city: getRandomString(6, 6),
state: getRandomString(6, 6),
zipCode: getRandomString(6, 6)
}
};
const contactInfo = {
firstName: getRandomString(6, 6),
lastName: getRandomString(6, 6),
emailAddress: getRandomString(6, 6),
phoneNumber: getRandomString(6, 6),
requestTextUpdates: getRandomBoolean()
};
store.order.contactInfo = contactInfo;
store.order.customer = customer;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
customer: expect.objectContaining({
address: expect.objectContaining({
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,
lastName: contactInfo.lastName,
phoneNumber: contactInfo.phoneNumber,
optInSms: contactInfo.requestTextUpdates
})
})
}));
});
it('calls api with expected lineItems', () => {
// Arrange
const lineItems = {
glassParts: getRandomString(6, 6),
supportingItems: getRandomString(6, 6),
vaps: getRandomString(6, 6)
};
store.order.lineItems = lineItems;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
lineItems: expect.objectContaining({
glassParts: lineItems.glassParts,
supportingItems: lineItems.supportingItems,
vaps: lineItems.vaps
})
})
}));
});
it.each([
[coverageStatuses.PENDING],
[coverageStatuses.NO_COMP],
[coverageStatuses.VERIFIED]
])('calls api with expected payment', (coverageStatus) => {
// Arrange
const parentAccountNumber = getRandomString(6, 6);
const payment = {
isInsurance: getRandomBoolean(),
insuranceCoverage: {
isVerified: getRandomBoolean(),
coverageStatus
}
};
store.issConfig.parentAccountNumber = parentAccountNumber;
store.order.payment = payment;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
payment: expect.objectContaining({
InsuranceCoverage: expect.objectContaining({
isVerified: payment.insuranceCoverage.isVerified,
coverageStatus
}),
isInsurance: payment.isInsurance,
parentAccountNumber
})
})
}));
});
it('calls api with expected service location', () => {
// Arrange
const notesForTechnician = getRandomString(6, 6);
const serviceLocation = {
address: getRandomString(6, 6),
city: getRandomString(6, 6),
state: getRandomString(6, 6),
zipCode: getRandomString(6, 6),
zipCodeCtu: getRandomString(6, 6)
};
store.order.contactInfo.notesForTechnician = notesForTechnician;
store.order.serviceLocation = serviceLocation;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
serviceLocation: expect.objectContaining({
address: expect.objectContaining({
streetAddress: serviceLocation.address,
city: serviceLocation.city,
state: serviceLocation.state,
zipCode: serviceLocation.zipCode,
zipCodeCtu: serviceLocation.zipCodeCtu
}),
techNotes: notesForTechnician
})
})
}));
});
it('calls api with expected schedule', () => {
// Arrange
const schedule = {
date: getRandomString(6, 6),
startTime: getRandomString(6, 6),
endTime: getRandomString(6, 6),
routeCode: getRandomString(6, 6),
jobMaxMinutes: getRandomString(6, 6),
jobMinMinutes: getRandomString(6, 6)
};
store.order.schedule = schedule;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
schedule: expect.objectContaining({
date: schedule.date,
startTime: schedule.startTime,
endTime: schedule.endTime,
routeCode: schedule.routeCode,
jobMaxMinutes: schedule.jobMaxMinutes,
jobMinMinutes: schedule.jobMinMinutes
})
})
}));
});
it('calls api with expected referral date', () => {
// Arrange
const referralDate = getRandomString(6, 6);
store.order.referralDate = referralDate;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({ referralDate })
}));
});
it('calls api with expected referral number', () => {
// Arrange
const referralNumber = getRandomString(6, 6);
store.order.referralNumber = referralNumber;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.saveSession();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({ referralNumber })
}));
});
});
it('No glassArray => empty list', async () => {
store.damage.glassToReplace = null;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
await store.saveSession();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
damage: expect.objectContaining({
glassToReplace: []
})
})
}));
});
it('glassArray empty => empty list', async () => {
store.damage.glassToReplace = [];
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
await store.saveSession();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
damage: expect.objectContaining({
glassToReplace: []
})
})
}));
});
it('Nonempty glass array => expected glass array sent', async () => {
const location1 = getRandomString(5);
const location2 = getRandomString(5);
const name1 = getRandomString(10);
const name2 = getRandomString(10);
store.damage.glassToReplace = [
{ glassLocation: location1, glassName: name1 },
{ glassLocation: location2, glassName: name2 }
],
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
await store.saveSession();
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
damage: expect.objectContaining({
glassToReplace: expect.arrayContaining([
{ location: location1, name: name1 },
{ location: location2, name: name2 }
])
})
})
}));
});
it('api call throws exception', async () => {
expect.assertions(2);
const error = 'this is the error';
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
// Act
await store.saveSession().catch((e) => {
expect(e).toEqual(error);
});
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
method: endpoints.SaveSession.method,
endpoint: endpoints.SaveSession.url
}));
});
});
describe('saveEndorsementQuestionAnswers method', () => {
it('method should update endorsement question data in store', () => {
// Arrange
const questionNum = getRandomInt(1, 100);
const questionText = getRandomString(50, 300);
const selectedAnswer = getRandomString(2, 3);
const endorsementQuestionAnswersArray = [
{
questionNum,
questionText,
selectedAnswer
}
];
// Act
store.saveEndorsementQuestionAnswers(endorsementQuestionAnswersArray);
// Assert
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);
});
});
describe('updatePolicyITACFlag method', () => {
it('updatePolicyITACFlag updates policy.isITAC flag in store', () => {
// Arrange
const moqIsITAC = getRandomBoolean();
// Act
store.updatePolicyITACFlag(moqIsITAC);
// Assert
expect(store.order.policy.isITAC).toEqual(moqIsITAC);
});
});
describe('isMobileAppointment', () => {
it('Should return true for mobile appointments', () => {
// Arrange
// Act
store.updateServiceLocation({
appointmentType: AppointmentTypeStrings.MOBILE
});
// Assert
expect(store.isMobileAppointment).toBe(true);
});
it('Should return true for mobile-insurance appointments', () => {
// Arrange
// Act
store.updateServiceLocation({
appointmentType: AppointmentTypeStrings.MOBILE_NOT_ITAC
});
// Assert
expect(store.isMobileAppointment).toBe(true);
});
it('Should return false for non-mobile appointments', () => {
// Arrange
// Act
store.updateServiceLocation({
appointmentType: AppointmentTypeStrings.IN_SHOP
});
// Assert
expect(store.isMobileAppointment).toBe(false);
});
it('Should return false for null appointments', () => {
// Arrange
// Act
store.updateServiceLocation({ appointmentType: null });
// Assert
expect(store.isMobileAppointment).toBe(false);
});
});
describe('isDropoffAppointment', () => {
it('Should return true for drop-off appointments', () => {
// Arrange
// Act
store.updateServiceLocation({
appointmentType: AppointmentTypeStrings.DROP_OFF
});
// Assert
expect(store.isDropOffAppointment).toBe(true);
});
it('Should return false for non-drop-off appointments', () => {
// Arrange
// Act
store.updateServiceLocation({
appointmentType: AppointmentTypeStrings.MOBILE
});
// Assert
expect(store.isDropOffAppointment).toBe(false);
});
it('Should return false for null appointments', () => {
// Arrange
// Act
store.updateServiceLocation({ appointmentType: null });
// Assert
expect(store.isDropOffAppointment).toBe(false);
});
});
});