unit test for payload

This commit is contained in:
Katie Kroell 2023-10-20 16:02:47 -04:00
parent 63c5999261
commit 667c868864

View file

@ -1757,6 +1757,63 @@ describe('Store', () => {
})
}));
});
it('only "Yes" endorsement answers are added to payload', () => {
// Arrange
const accountNumber = getRandomString(6, 6);
const currentDeductible = getRandomInt(0, 5000);
const noCoverage = getRandomBoolean();
const endorsementAnswers = [
{
questionNum: getRandomInt(1, 10),
endorsementName: getRandomString(8, 20),
questionText: getRandomString(50, 100),
selectedAnswer: 'Yes'
},
{
questionNum: getRandomInt(1, 10),
endorsementName: getRandomString(8, 20),
questionText: getRandomString(50, 100),
selectedAnswer: 'Yes'
},
{
questionNum: getRandomInt(1, 10),
endorsementName: getRandomString(8, 20),
questionText: getRandomString(50, 100),
selectedAnswer: 'No'
}
];
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;
store.order.policy.endorsementQuestionAnswers = endorsementAnswers;
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
store.getFinalDeductible();
// Assert
const expected = [endorsementAnswers[0].endorsementName, endorsementAnswers[1].endorsementName];
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(({
method: endpoints.FinalDeductible.method,
endpoint: endpoints.FinalDeductible.url,
payload: ({
accountNumber,
currentDeductible,
noCoverage,
endorsements: expected,
policy: {
status: policy.status,
policyState: policy.policyState
}
})
}));
});
});
describe('unsuccessful api call', () => {
it('api call throws exception', async () => {