From 96462fd087a597f4ea57cf70f2fc542276eb8368 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Fri, 15 Sep 2023 14:57:26 -0400 Subject: [PATCH] add test for save endorsements method --- src/store/index.js | 5 ++--- src/store/store.spec.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 65051c35..9ef2f3ec 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -60,7 +60,7 @@ const getDefaultState = () => ({ repair: null, // numerical value; how much customer owes on deductible in repair case replace: null // numerical value; how much customer owes on deductible in replace case, }, - endorsementQuestionAnswers: null, + endorsementQuestionAnswers: null }, customer: { address: { @@ -917,12 +917,11 @@ export const useMainStore = defineStore({ const sortedEndorsementQuestionAnswersArray = sortArrayOfObjectsByPropertyValue(endorsementQuestionAnswersArray, 'result'); const haveEndorsementQuestionAnswersChanged = sortedPreviousResultsArray?.length !== sortedEndorsementQuestionAnswersArray.length || !sortedPreviousResultsArray?.every((x, i) => x.result === sortedEndorsementQuestionAnswersArray[i].result); - + if (haveEndorsementQuestionAnswersChanged) { this.updateEndorsementQuestionAnswers(null); } - // Save new values this.updateEndorsementQuestionAnswers(endorsementQuestionAnswersArray); }, diff --git a/src/store/store.spec.js b/src/store/store.spec.js index d03784f5..5ee963ab 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -955,4 +955,26 @@ describe('Store', () => { ); }); }); + + 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); + }); + }); });