-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Attachment support in email responses for storage mode forms (#…
…8053) * feat: send attachment to mail service * test: add test case for submitEncryptModeForm * test: add attachments to mail service tests * test: add test for case where there are no attachments
- Loading branch information
Showing
3 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,11 @@ import { | |
SpVerifiedContent, | ||
} from 'src/app/modules/verified-content/verified-content.types' | ||
import MailService from 'src/app/services/mail/mail.service' | ||
import { FormFieldSchema, IPopulatedEncryptedForm } from 'src/types' | ||
import { | ||
FormFieldSchema, | ||
IAttachmentInfo, | ||
IPopulatedEncryptedForm, | ||
} from 'src/types' | ||
import { EncryptSubmissionDto, FormCompleteDto } from 'src/types/api' | ||
|
||
import { SubmissionEmailObj } from '../../email-submission/email-submission.util' | ||
|
@@ -1330,4 +1334,121 @@ describe('encrypt-submission.controller', () => { | |
) | ||
}) | ||
}) | ||
|
||
describe('submitEncryptModeForm', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
MockMailService.sendSubmissionToAdmin.mockReturnValue(okAsync(true)) | ||
}) | ||
|
||
it('should call sendSubmissionToAdmin with no attachments', async () => { | ||
// Arrange | ||
jest | ||
.spyOn(MailService, 'sendSubmissionToAdmin') | ||
.mockReturnValue(okAsync(true)) | ||
|
||
const mockFormId = new ObjectId() | ||
const mockForm = { | ||
_id: mockFormId, | ||
title: 'Test Form', | ||
authType: FormAuthType.NIL, | ||
form_fields: [] as FormFieldSchema[], | ||
emails: ['[email protected]'], | ||
getUniqueMyInfoAttrs: () => [] as MyInfoAttribute[], | ||
} as IPopulatedEncryptedForm | ||
|
||
const mockAttachments: IAttachmentInfo[] = [] | ||
|
||
const mockReq = merge( | ||
expressHandler.mockRequest({ | ||
params: { formId: mockFormId.toHexString() }, | ||
body: { | ||
responses: [], | ||
attachments: mockAttachments, | ||
}, | ||
}), | ||
{ | ||
formsg: { | ||
encryptedPayload: { | ||
encryptedContent: 'mockEncryptedContent', | ||
version: 1, | ||
}, | ||
formDef: {}, | ||
encryptedFormDef: mockForm, | ||
unencryptedAttachments: mockAttachments, | ||
} as unknown as EncryptSubmissionDto, | ||
} as unknown as FormCompleteDto, | ||
) as unknown as SubmitEncryptModeFormHandlerRequest | ||
|
||
const mockRes = expressHandler.mockResponse() | ||
|
||
// Act | ||
await submitEncryptModeFormForTest(mockReq, mockRes) | ||
|
||
// Assert (done) | ||
expect(MockMailService.sendSubmissionToAdmin).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
attachments: mockAttachments, | ||
}), | ||
) | ||
}) | ||
|
||
it('should call sendSubmissionToAdmin with the attachments', async () => { | ||
// Arrange | ||
jest | ||
.spyOn(MailService, 'sendSubmissionToAdmin') | ||
.mockReturnValue(okAsync(true)) | ||
|
||
const mockFormId = new ObjectId() | ||
const mockForm = { | ||
_id: mockFormId, | ||
title: 'Test Form', | ||
authType: FormAuthType.NIL, | ||
form_fields: [] as FormFieldSchema[], | ||
emails: ['[email protected]'], | ||
getUniqueMyInfoAttrs: () => [] as MyInfoAttribute[], | ||
} as IPopulatedEncryptedForm | ||
|
||
const mockAttachments: IAttachmentInfo[] = [ | ||
{ | ||
filename: 'test.pdf', | ||
content: Buffer.from('this is a test file'), | ||
fieldId: 'test-field-id', | ||
}, | ||
] | ||
|
||
const mockReq = merge( | ||
expressHandler.mockRequest({ | ||
params: { formId: mockFormId.toHexString() }, | ||
body: { | ||
responses: [], | ||
attachments: mockAttachments, | ||
}, | ||
}), | ||
{ | ||
formsg: { | ||
encryptedPayload: { | ||
encryptedContent: 'mockEncryptedContent', | ||
version: 1, | ||
}, | ||
formDef: {}, | ||
encryptedFormDef: mockForm, | ||
unencryptedAttachments: mockAttachments, | ||
} as unknown as EncryptSubmissionDto, | ||
} as unknown as FormCompleteDto, | ||
) as unknown as SubmitEncryptModeFormHandlerRequest | ||
|
||
const mockRes = expressHandler.mockResponse() | ||
|
||
// Act | ||
await submitEncryptModeFormForTest(mockReq, mockRes) | ||
|
||
// Assert (done) | ||
expect(MockMailService.sendSubmissionToAdmin).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
attachments: mockAttachments, | ||
}), | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters