@@ -15,12 +15,18 @@ type HandlerCallbackType = Parameters<
1515 Schema [ 'sendEmail' ] [ 'functionHandler' ]
1616> [ 2 ] ;
1717
18+ const notifyDomainName = process . env . NOTIFY_DOMAIN_NAME ;
19+
1820beforeAll ( ( ) => {
1921 jest . useFakeTimers ( ) ;
2022 jest . setSystemTime ( new Date ( '2022-01-01 10:00' ) ) ;
2123 process . env . NOTIFY_DOMAIN_NAME = 'test.notify.nhs.uk' ;
2224} ) ;
2325
26+ afterAll ( ( ) => {
27+ process . env . NOTIFY_DOMAIN_NAME = notifyDomainName ;
28+ } ) ;
29+
2430test ( 'sends email' , async ( ) => {
2531 const mockSESClient = mockDeep < SESClient > ( {
2632 send : jest . fn ( ) . mockReturnValue ( {
@@ -52,29 +58,16 @@ test('sends email', async () => {
5258
5359 const messageId = rawMimeMessage ?. match ( / M e s s a g e - I D : < ( [ ^ @ ] + ) @ / ) ?. [ 1 ] ;
5460
55- const messageBoundary = rawMimeMessage ?. match ( / b o u n d a r y = ( [ \d A - z ] + ) / ) ?. [ 1 ] ;
56-
5761 const expectedMessage = `Date: Sat, 01 Jan 2022 10:00:00 +0000
5862From: =?utf-8?B?TkhTIE5vdGlmeQ==?= <[email protected] > 5963To: <recipient-email>
6064Message-ID: <${ messageId } @test.notify.nhs.uk>
6165Subject: =?utf-8?B?VGVtcGxhdGUgc3VibWl0dGVkIC0gdGVtcGxhdGUtbmFtZQ==?=
6266MIME-Version: 1.0
63- Content-Type: multipart/mixed; boundary=${ messageBoundary }
64-
65- --${ messageBoundary }
6667Content-Type: text/html; charset=UTF-8
6768Content-Transfer-Encoding: 7bit
6869
69- ${ emailTemplate ( 'template-id' , 'template-name' , 'template-message' ) }
70-
71- --${ messageBoundary }
72- Content-Type: text/markdown; name="template-content.md"
73- Content-Transfer-Encoding: base64
74- Content-Disposition: attachment; filename="template-content.md"
75-
76- dGVtcGxhdGUtbWVzc2FnZQ==
77- --${ messageBoundary } --` ;
70+ ${ emailTemplate ( 'template-id' , 'template-name' , 'template-message' ) } `;
7871
7972 expect ( rawMimeMessage ?. toString ( ) ) . toEqual ( expectedMessage ) ;
8073} ) ;
0 commit comments