From 2f42dc1e78275250d43323a9ec1571e98ac7db32 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Tue, 17 Oct 2023 15:57:24 -0400 Subject: [PATCH] unit tests - getFinalDeductible and updateDeductible --- src/store/store.spec.js | 90 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/src/store/store.spec.js b/src/store/store.spec.js index ce0fc9fd..22455c67 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -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); + }); + }); });