Skip to content

Commit c1c17a8

Browse files
committed
feat: add tc for new extractRespondentCopyEmailDatas function
1 parent 4880fe5 commit c1c17a8

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

src/app/modules/submission/multirespondent-submission/__tests__/multirespondent-submission.utils.spec.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { ValidateFieldErrorV3 } from '../../submission.errors'
4545
import {
4646
createMultirespondentSubmissionDto,
4747
createPublicMultirespondentSubmissionDto,
48+
extractRespondentCopyEmailDatas,
4849
getQuestionAnswerPairsForMultipleFields,
4950
retrieveWorkflowStepEmailAddresses,
5051
validateMrfFieldResponses,
@@ -58,6 +59,93 @@ describe('multirespondent-submission.utils', () => {
5859
edit: [],
5960
}
6061

62+
describe('extractRespondentCopyEmailDatas', () => {
63+
it('should return email data for only current step email fields with auto reply enabled and has answer', () => {
64+
// Arrange
65+
const inactiveEmailField = new ObjectId().toHexString()
66+
const activeEmailField = new ObjectId().toHexString()
67+
const activeEmailFieldNoAnswer = new ObjectId().toHexString()
68+
const activeEmailFieldNoAutoReply = new ObjectId().toHexString()
69+
const shortTextFieldId = new ObjectId().toHexString()
70+
const autoReplyOptionDefaults = {
71+
autoReplySubject: 'Test Subject',
72+
autoReplySender: 'Test Sender',
73+
autoReplyMessage: 'Test Body',
74+
includeFormSummary: true,
75+
hasAutoReply: true,
76+
}
77+
const formFields = [
78+
generateDefaultField(BasicField.Email, {
79+
_id: inactiveEmailField,
80+
autoReplyOptions: autoReplyOptionDefaults,
81+
}),
82+
generateDefaultField(BasicField.Email, {
83+
_id: activeEmailField,
84+
autoReplyOptions: autoReplyOptionDefaults,
85+
}),
86+
generateDefaultField(BasicField.Email, {
87+
_id: activeEmailFieldNoAnswer,
88+
autoReplyOptions: autoReplyOptionDefaults,
89+
}),
90+
generateDefaultField(BasicField.ShortText, {
91+
_id: shortTextFieldId,
92+
autoReplyOptions: autoReplyOptionDefaults,
93+
}),
94+
generateDefaultField(BasicField.Email, {
95+
_id: activeEmailFieldNoAutoReply,
96+
autoReplyOptions: {
97+
...autoReplyOptionDefaults,
98+
hasAutoReply: false,
99+
},
100+
}),
101+
]
102+
103+
// Act
104+
const result = extractRespondentCopyEmailDatas({
105+
responses: {
106+
[inactiveEmailField]: {
107+
fieldType: BasicField.Email,
108+
answer: {
109+
110+
},
111+
},
112+
[activeEmailField]: {
113+
fieldType: BasicField.Email,
114+
answer: {
115+
116+
},
117+
},
118+
[shortTextFieldId]: {
119+
fieldType: BasicField.ShortText,
120+
answer: 'short text answer',
121+
},
122+
[activeEmailFieldNoAutoReply]: {
123+
fieldType: BasicField.Email,
124+
answer: { value: '[email protected]' },
125+
},
126+
},
127+
formFields,
128+
currentStepActiveFields: [
129+
activeEmailField,
130+
shortTextFieldId,
131+
activeEmailFieldNoAnswer,
132+
activeEmailFieldNoAutoReply,
133+
],
134+
})
135+
136+
// Assert
137+
expect(result).toEqual([
138+
{
139+
140+
subject: 'Test Subject',
141+
sender: 'Test Sender',
142+
body: 'Test Body',
143+
includeFormSummary: true,
144+
},
145+
])
146+
})
147+
})
148+
61149
describe('createPublicMultirespondentSubmissionDto', () => {
62150
const getAllTypesFormFieldsWithDropdownOptionsToRecipientsMap = () => {
63151
return Object.values(BasicField).map((fieldType) => {

0 commit comments

Comments
 (0)