Skip to content

Commit 1e9148a

Browse files
committed
feat: rename to submissionAttachment for clarity and move tcs to service
1 parent 5f9e9eb commit 1e9148a

File tree

7 files changed

+306
-353
lines changed

7 files changed

+306
-353
lines changed

src/app/modules/submission/encrypt-submission/__tests__/encrypt-submission.controller.spec.ts

Lines changed: 28 additions & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,9 @@ describe('encrypt-submission.controller', () => {
12611261
})
12621262
})
12631263

1264-
describe('emailData', () => {
1265-
it('should have the isVisible field set to true for form fields', async () => {
1264+
describe('passes the required correct data used to generate content for post-submission notification emails', () => {
1265+
1266+
it('passes the required isVisible values in email fields, submission attachments, and respondent emails', async () => {
12661267
// Arrange
12671268
const performEncryptPostSubmissionActionsSpy = jest.spyOn(
12681269
EncryptSubmissionService,
@@ -1294,291 +1295,64 @@ describe('encrypt-submission.controller', () => {
12941295
question: 'Long answer',
12951296
answer: 'this is an answer',
12961297
fieldType: 'textarea',
1297-
isVisible: true,
1298+
isVisible: true,
12981299
},
1300+
{
1301+
id: new ObjectId(),
1302+
question: 'Short answer',
1303+
answer: 'this is a short answer',
1304+
fieldType: 'textfield',
1305+
isVisible: false,
1306+
}
12991307
]
13001308

1301-
const mockReq = merge(
1302-
expressHandler.mockRequest({
1303-
params: { formId: 'some id' },
1304-
body: {
1305-
responses: mockResponses,
1306-
},
1307-
}),
1308-
{
1309-
formsg: {
1310-
encryptedPayload: {
1311-
encryptedContent: 'encryptedContent',
1312-
version: 1,
1313-
},
1314-
formDef: {},
1315-
encryptedFormDef: mockEncryptForm,
1316-
} as unknown as EncryptSubmissionDto,
1317-
} as unknown as FormCompleteDto,
1318-
) as unknown as SubmitEncryptModeFormHandlerRequest
1319-
const mockRes = expressHandler.mockResponse()
1320-
1321-
// Setup the SubmissionEmailObj
1322-
const emailData = new SubmissionEmailObj(
1323-
mockResponses as any as ProcessedFieldResponse[],
1324-
new Set(),
1325-
FormAuthType.NIL,
1326-
)
1327-
1328-
// Act
1329-
await submitEncryptModeFormForTest(mockReq, mockRes)
1330-
1331-
// Assert
1332-
expect(
1333-
performEncryptPostSubmissionActionsSpy.mock.calls[0][0].emailData,
1334-
).toEqual(emailData)
1335-
})
1336-
})
1337-
1338-
describe('submitEncryptModeForm', () => {
1339-
beforeEach(() => {
1340-
jest.clearAllMocks()
1341-
MockMailService.sendSubmissionToAdmin.mockReturnValue(okAsync(true))
1342-
})
1343-
1344-
it('should call sendSubmissionToAdmin with no attachments', async () => {
1345-
// Arrange
1346-
jest
1347-
.spyOn(MailService, 'sendSubmissionToAdmin')
1348-
.mockReturnValue(okAsync(true))
1349-
1350-
const mockFormId = new ObjectId()
1351-
const mockForm = {
1352-
_id: mockFormId,
1353-
title: 'Test Form',
1354-
authType: FormAuthType.NIL,
1355-
form_fields: [] as FormFieldSchema[],
1356-
emails: ['[email protected]'],
1357-
getUniqueMyInfoAttrs: () => [] as MyInfoAttribute[],
1358-
} as IPopulatedEncryptedForm
1359-
1360-
const mockAttachments: IAttachmentInfo[] = []
1361-
1362-
const mockReq = merge(
1363-
expressHandler.mockRequest({
1364-
params: { formId: mockFormId.toHexString() },
1365-
body: {
1366-
responses: [],
1367-
attachments: mockAttachments,
1368-
},
1369-
}),
1370-
{
1371-
formsg: {
1372-
encryptedPayload: {
1373-
encryptedContent: 'mockEncryptedContent',
1374-
version: 1,
1375-
},
1376-
formDef: {},
1377-
encryptedFormDef: mockForm,
1378-
unencryptedAttachments: mockAttachments,
1379-
} as unknown as EncryptSubmissionDto,
1380-
} as unknown as FormCompleteDto,
1381-
) as unknown as SubmitEncryptModeFormHandlerRequest
1382-
1383-
const mockRes = expressHandler.mockResponse()
1384-
1385-
// Act
1386-
await submitEncryptModeFormForTest(mockReq, mockRes)
1387-
1388-
// Assert (done)
1389-
expect(MockMailService.sendSubmissionToAdmin).toHaveBeenCalledWith(
1390-
expect.objectContaining({
1391-
attachments: mockAttachments,
1392-
}),
1393-
)
1394-
})
1395-
1396-
it('should call sendSubmissionToAdmin with the attachments', async () => {
1397-
// Arrange
1398-
jest
1399-
.spyOn(MailService, 'sendSubmissionToAdmin')
1400-
.mockReturnValue(okAsync(true))
1401-
1402-
const mockFormId = new ObjectId()
1403-
const mockForm = {
1404-
_id: mockFormId,
1405-
title: 'Test Form',
1406-
authType: FormAuthType.NIL,
1407-
form_fields: [] as FormFieldSchema[],
1408-
emails: ['[email protected]'],
1409-
getUniqueMyInfoAttrs: () => [] as MyInfoAttribute[],
1410-
} as IPopulatedEncryptedForm
1411-
1412-
const mockAttachments: IAttachmentInfo[] = [
1309+
const mockUnencryptedAttachments: IAttachmentInfo[] = [
14131310
{
14141311
filename: 'test.pdf',
14151312
content: Buffer.from('this is a test file'),
14161313
fieldId: 'test-field-id',
14171314
},
1418-
]
1419-
1420-
const mockReq = merge(
1421-
expressHandler.mockRequest({
1422-
params: { formId: mockFormId.toHexString() },
1423-
body: {
1424-
responses: [],
1425-
attachments: mockAttachments,
1426-
},
1427-
}),
14281315
{
1429-
formsg: {
1430-
encryptedPayload: {
1431-
encryptedContent: 'mockEncryptedContent',
1432-
version: 1,
1433-
},
1434-
formDef: {},
1435-
encryptedFormDef: mockForm,
1436-
unencryptedAttachments: mockAttachments,
1437-
} as unknown as EncryptSubmissionDto,
1438-
} as unknown as FormCompleteDto,
1439-
) as unknown as SubmitEncryptModeFormHandlerRequest
1440-
1441-
const mockRes = expressHandler.mockResponse()
1442-
1443-
// Act
1444-
await submitEncryptModeFormForTest(mockReq, mockRes)
1445-
1446-
// Assert (done)
1447-
expect(MockMailService.sendSubmissionToAdmin).toHaveBeenCalledWith(
1448-
expect.objectContaining({
1449-
attachments: mockAttachments,
1450-
}),
1451-
)
1452-
})
1453-
1454-
it('should pass expected dataCollationData to sendSubmissionToAdmin', async () => {
1455-
// Arrange
1456-
const mockFormId = new ObjectId()
1457-
const signatureFieldId = new ObjectId()
1458-
const mockForm = {
1459-
_id: mockFormId,
1460-
title: 'Test Form',
1461-
authType: FormAuthType.NIL,
1462-
form_fields: [] as FormFieldSchema[],
1463-
emails: ['[email protected]'],
1464-
getUniqueMyInfoAttrs: () => [] as MyInfoAttribute[],
1465-
} as IPopulatedEncryptedForm
1466-
1467-
const mockResponses = [
1468-
{
1469-
_id: new ObjectId(),
1470-
question: '[MyInfo] Test Question',
1471-
answer: 'Test Answer',
1472-
fieldType: 'text',
1473-
isVisible: true,
1474-
},
1475-
{
1476-
_id: signatureFieldId,
1477-
question: 'Signature Question',
1478-
answerArray: ['draw', '[[[10,20,0.5]],[[40,40,0.5]]]'],
1479-
fieldType: 'signature',
1480-
isVisible: true,
1481-
},
1316+
filename: 'test2.pdf',
1317+
content: Buffer.from('this is another test file'),
1318+
fieldId: 'test-field-id-2',
1319+
}
14821320
]
14831321

1322+
const mockRespondentEmails = ['[email protected]', '[email protected]']
1323+
14841324
const mockReq = merge(
14851325
expressHandler.mockRequest({
1486-
params: { formId: mockFormId.toHexString() },
1326+
params: { formId: 'some id' },
14871327
body: {
14881328
responses: mockResponses,
14891329
},
14901330
}),
14911331
{
14921332
formsg: {
14931333
encryptedPayload: {
1494-
encryptedContent: 'mockEncryptedContent',
1334+
encryptedContent: 'encryptedContent',
14951335
version: 1,
14961336
},
1337+
unencryptedAttachments: mockUnencryptedAttachments,
14971338
formDef: {},
1498-
encryptedFormDef: mockForm,
1339+
encryptedFormDef: mockEncryptForm,
1340+
respondentEmails: mockRespondentEmails,
14991341
} as unknown as EncryptSubmissionDto,
15001342
} as unknown as FormCompleteDto,
15011343
) as unknown as SubmitEncryptModeFormHandlerRequest
1502-
15031344
const mockRes = expressHandler.mockResponse()
1504-
15051345
// Act
15061346
await submitEncryptModeFormForTest(mockReq, mockRes)
15071347

15081348
// Assert
1509-
expect(MockMailService.sendSubmissionToAdmin).toHaveBeenCalledWith(
1510-
expect.objectContaining({
1511-
dataCollationData: expect.arrayContaining([
1512-
expect.objectContaining({
1513-
question: 'Test Question',
1514-
answer: 'Test Answer',
1515-
}),
1516-
expect.objectContaining({
1517-
question: '[signature] Signature Question',
1518-
answer: `Signature captured`,
1519-
}),
1520-
]),
1521-
}),
1522-
)
1523-
})
1524-
1525-
it('should strip [MyInfo] prefix from expected dataCollationData to sendSubmissionToAdmin', async () => {
1526-
// Arrange
1527-
const mockFormId = new ObjectId()
1528-
const mockForm = {
1529-
_id: mockFormId,
1530-
title: 'Test Form',
1531-
authType: FormAuthType.NIL,
1532-
form_fields: [] as FormFieldSchema[],
1533-
emails: ['[email protected]'],
1534-
getUniqueMyInfoAttrs: () => [] as MyInfoAttribute[],
1535-
} as IPopulatedEncryptedForm
1536-
1537-
const mockResponses = [
1538-
{
1539-
_id: new ObjectId(),
1540-
question: '[MyInfo] Name',
1541-
answer: 'Test Answer',
1542-
fieldType: 'text',
1543-
isVisible: true,
1544-
},
1545-
]
1546-
1547-
const mockReq = merge(
1548-
expressHandler.mockRequest({
1549-
params: { formId: mockFormId.toHexString() },
1550-
body: {
1551-
responses: mockResponses,
1552-
},
1553-
}),
1554-
{
1555-
formsg: {
1556-
encryptedPayload: {
1557-
encryptedContent: 'mockEncryptedContent',
1558-
version: 1,
1559-
},
1560-
formDef: {},
1561-
encryptedFormDef: mockForm,
1562-
} as unknown as EncryptSubmissionDto,
1563-
} as unknown as FormCompleteDto,
1564-
) as unknown as SubmitEncryptModeFormHandlerRequest
1565-
1566-
const mockRes = expressHandler.mockResponse()
1349+
expect(
1350+
performEncryptPostSubmissionActionsSpy.mock.calls[0][0].emailFields,
1351+
).toEqual(mockResponses)
15671352

1568-
// Act
1569-
await submitEncryptModeFormForTest(mockReq, mockRes)
1353+
expect(performEncryptPostSubmissionActionsSpy.mock.calls[0][0].submissionAttachments).toEqual(mockUnencryptedAttachments)
15701354

1571-
// Assert
1572-
expect(MockMailService.sendSubmissionToAdmin).toHaveBeenCalledWith(
1573-
expect.objectContaining({
1574-
dataCollationData: expect.arrayContaining([
1575-
expect.objectContaining({
1576-
question: 'Name',
1577-
answer: 'Test Answer',
1578-
}),
1579-
]),
1580-
}),
1581-
)
1355+
expect(performEncryptPostSubmissionActionsSpy.mock.calls[0][0].respondentEmails).toEqual(mockRespondentEmails)
15821356
})
15831357
})
15841358
})

0 commit comments

Comments
 (0)