unit tests - getFinalDeductible and updateDeductible

This commit is contained in:
Katie Kroell 2023-10-17 15:57:24 -04:00
parent 5c86c0546c
commit 2f42dc1e78

View file

@ -1107,7 +1107,7 @@ describe('Store', () => {
describe('getFinalDeductible method', () => {
describe('successful method call', () => {
it.only('calls get final deductible api endpoint', () => {
it('calls get final deductible api endpoint', () => {
// Arrange
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
@ -1116,10 +1116,98 @@ describe('Store', () => {
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
method: endpoints.FinalDeductible.method,
endpoint: endpoints.FinalDeductible.url
}));
});
it('returns expected response object', async () => {
// Arrange
const response = { deductible: getRandomInt(0, 5000) };
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));
// Act
const result = store.getFinalDeductible();
// Assert
await expect(result).resolves.toBe(response);
});
it('calls api with expected payload', () => {
// Arrange
const accountNumber = getRandomString(6, 6);
const currentDeductible = getRandomInt(0, 5000);
const noCoverage = getRandomBoolean();
const endorsements = [];
const policy = {
status: 'Active', // need to change this
policyState: getRandomString(2, 2)
};
store.issConfig.parentAccountNumber = accountNumber;
store.order.currentDeductible = currentDeductible;
store.order.policy.noCoverage = noCoverage;
store.order.policy.status = policy.status;
store.order.vehicle.registration.state = policy.policyState;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.getFinalDeductible();
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(({
method: endpoints.FinalDeductible.method,
endpoint: endpoints.FinalDeductible.url,
payload: ({
accountNumber,
currentDeductible,
noCoverage,
endorsements,
policy: {
status: policy.status,
policyState: policy.policyState
}
})
}));
});
});
describe('unsuccessful api call', () => {
it('api call throws exception', async () => {
// Arrange
const error = 'final deductible error';
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
// Act
await store.getFinalDeductible().catch((e) => {
expect(e).toEqual(error);
});
// Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
method: endpoints.FinalDeductible.method,
endpoint: endpoints.FinalDeductible.url
}));
});
});
});
describe('updateDeductible method', () => {
it('final deductible is saved as currentDeductible in store', () => {
// Arrange
const finalDeductible = getRandomInt(0, 5000);
// Act
store.updateDeductible(finalDeductible);
// Assert
expect(store.order.currentDeductible).toEqual(finalDeductible);
});
it('null final deductible => currentDeductible in store set to null', () => {
// Arrange
const finalDeductible = null;
// Act
store.updateDeductible(finalDeductible);
// Assert
expect(store.order.currentDeductible).toEqual(finalDeductible);
});
});
});