@@ -15,160 +15,162 @@ const authHelper = createAuthHelper();
1515const sftpHelper = new SftpHelper ( ) ;
1616const lambdaClient = new LambdaClient ( { region : 'eu-west-2' } ) ;
1717
18- beforeAll ( async ( ) => {
19- await sftpHelper . connect ( ) ;
20- } ) ;
18+ test . describe ( 'Letter Proofing' , ( ) => {
19+ test . beforeAll ( async ( ) => {
20+ await sftpHelper . connect ( ) ;
21+ } ) ;
22+
23+ test . afterAll ( async ( ) => {
24+ await sftpHelper . end ( ) ;
25+ } ) ;
26+
27+ test ( 'proofs are downloaded and linked to the DB entry' , async ( ) => {
28+ const templateId = 'test-template-id-proofing-e2e-success' ;
29+ const user = await authHelper . getTestUser ( TestUserId . User1 ) ;
30+
31+ // add entries to database
32+ await templateStorageHelper . seedTemplateData ( [
33+ TemplateFactory . createLetterTemplate (
34+ templateId ,
35+ user . userId ,
36+ templateId ,
37+ 'WAITING_FOR_PROOF'
38+ ) ,
39+ ] ) ;
2140
22- afterAll ( async ( ) => {
23- await sftpHelper . end ( ) ;
24- } ) ;
41+ // add proofs to SFTP mock
42+ const pdfContent = readFileSync (
43+ './fixtures/pdf-upload/no-custom-personalisation/template.pdf'
44+ ) ;
2545
26- test ( 'proofs are downloaded and linked to the DB entry' , async ( ) => {
27- const templateId = 'test-template-id-proofing-e2e-success' ;
28- const user = await authHelper . getTestUser ( TestUserId . User1 ) ;
29-
30- // add entries to database
31- await templateStorageHelper . seedTemplateData ( [
32- TemplateFactory . createLetterTemplate (
33- templateId ,
34- user . userId ,
35- templateId ,
36- 'WAITING_FOR_PROOF'
37- ) ,
38- ] ) ;
39-
40- // add proofs to SFTP mock
41- const pdfContent = readFileSync (
42- './fixtures/pdf-upload/no-custom-personalisation/template.pdf'
43- ) ;
44-
45- await sftpHelper . put (
46- pdfContent ,
47- `WTMMOCK/Outgoing/proofs/${ templateId } /proof-1.pdf`
48- ) ;
49- await sftpHelper . put (
50- pdfContent ,
51- `WTMMOCK/Outgoing/proofs/${ templateId } /proof-2.pdf`
52- ) ;
53- await sftpHelper . put (
54- pdfContent ,
55- `WTMMOCK/Outgoing/proofs/${ templateId } /proof-3.pdf`
56- ) ;
57-
58- // invoke SFTP poll lambda
59- await lambdaClient . send (
60- new InvokeCommand ( {
61- FunctionName : process . env . SFTP_POLL_LAMBDA_NAME ,
62- } )
63- ) ;
64-
65- // check for expected results
66- await expect ( async ( ) => {
67- const template = await templateStorageHelper . getTemplate ( {
68- owner : user . userId ,
69- id : templateId ,
70- } ) ;
71-
72- expect ( template . files ?. proofs ) . toEqual ( {
73- 'proof-1' : {
74- fileName : `proofs/${ user . userId } /${ templateId } /proof-1.pdf` ,
75- virusScanStatus : 'PASSED' ,
76- } ,
77- 'proof-2' : {
78- fileName : `proofs/${ user . userId } /${ templateId } /proof-2.pdf` ,
79- virusScanStatus : 'PASSED' ,
80- } ,
81- 'proof-3' : {
82- fileName : `proofs/${ user . userId } /${ templateId } /proof-3.pdf` ,
83- virusScanStatus : 'PASSED' ,
84- } ,
85- } ) ;
86-
87- expect ( template . templateStatus ) . toEqual ( 'PROOF_AVAILABLE' ) ;
88-
89- for ( const fileName of [ 'proof-1' , 'proof-2' , 'proof-3' ] ) {
90- const quarantinePdf = await templateStorageHelper . getLetterProofFile (
91- process . env . TEMPLATES_QUARANTINE_BUCKET_NAME ,
92- 'proofs' ,
46+ await sftpHelper . put (
47+ pdfContent ,
48+ `WTMMOCK/Outgoing/proofs/${ templateId } /proof-1.pdf`
49+ ) ;
50+ await sftpHelper . put (
51+ pdfContent ,
52+ `WTMMOCK/Outgoing/proofs/${ templateId } /proof-2.pdf`
53+ ) ;
54+ await sftpHelper . put (
55+ pdfContent ,
56+ `WTMMOCK/Outgoing/proofs/${ templateId } /proof-3.pdf`
57+ ) ;
58+
59+ // invoke SFTP poll lambda
60+ await lambdaClient . send (
61+ new InvokeCommand ( {
62+ FunctionName : process . env . SFTP_POLL_LAMBDA_NAME ,
63+ } )
64+ ) ;
65+
66+ // check for expected results
67+ await expect ( async ( ) => {
68+ const template = await templateStorageHelper . getTemplate ( {
69+ owner : user . userId ,
70+ id : templateId ,
71+ } ) ;
72+
73+ expect ( template . files ?. proofs ) . toEqual ( {
74+ 'proof-1' : {
75+ fileName : `proofs/${ user . userId } /${ templateId } /proof-1.pdf` ,
76+ virusScanStatus : 'PASSED' ,
77+ } ,
78+ 'proof-2' : {
79+ fileName : `proofs/${ user . userId } /${ templateId } /proof-2.pdf` ,
80+ virusScanStatus : 'PASSED' ,
81+ } ,
82+ 'proof-3' : {
83+ fileName : `proofs/${ user . userId } /${ templateId } /proof-3.pdf` ,
84+ virusScanStatus : 'PASSED' ,
85+ } ,
86+ } ) ;
87+
88+ expect ( template . templateStatus ) . toEqual ( 'PROOF_AVAILABLE' ) ;
89+
90+ for ( const fileName of [ 'proof-1' , 'proof-2' , 'proof-3' ] ) {
91+ const quarantinePdf = await templateStorageHelper . getLetterProofFile (
92+ process . env . TEMPLATES_QUARANTINE_BUCKET_NAME ,
93+ 'proofs' ,
94+ templateId ,
95+ 'proof' ,
96+ 'pdf'
97+ ) ;
98+
99+ expect ( quarantinePdf ?. ChecksumSHA256 ) . toEqual (
100+ pdfUploadFixtures . withPersonalisation . pdf . checksumSha256 ( )
101+ ) ;
102+
103+ const internalPdf = await templateStorageHelper . getLetterTemplateFile (
104+ process . env . TEMPLATES_INTERNAL_BUCKET_NAME ,
105+ 'proofs' ,
106+ { owner : user . userId , id : templateId } ,
107+ fileName ,
108+ 'pdf'
109+ ) ;
110+
111+ expect ( internalPdf ?. ChecksumSHA256 ) . toEqual (
112+ pdfUploadFixtures . withPersonalisation . pdf . checksumSha256 ( )
113+ ) ;
114+ }
115+ } ) . toPass ( { timeout : 10_000 } ) ;
116+ } ) ;
117+
118+ test ( 'if the only proof fails the virus scan, the status is not updated to PROOF_AVAILABLE' , async ( ) => {
119+ const templateId = 'test-template-id-proofing-e2e-failure' ;
120+ const user = await authHelper . getTestUser ( TestUserId . User1 ) ;
121+
122+ // add entries to database
123+ await templateStorageHelper . seedTemplateData ( [
124+ TemplateFactory . createLetterTemplate (
93125 templateId ,
94- 'proof' ,
95- 'pdf'
96- ) ;
126+ user . userId ,
127+ templateId ,
128+ 'WAITING_FOR_PROOF'
129+ ) ,
130+ ] ) ;
97131
98- expect ( quarantinePdf ?. ChecksumSHA256 ) . toEqual (
99- pdfUploadFixtures . withPersonalisation . pdf . checksumSha256 ( )
100- ) ;
132+ // add proofs to SFTP mock
133+ const pdfContent = readFileSync (
134+ './fixtures/pdf-upload/no-custom-personalisation/password.pdf'
135+ ) ;
136+
137+ await sftpHelper . put (
138+ pdfContent ,
139+ `WTMMOCK/Outgoing/proofs/${ templateId } /proof.pdf`
140+ ) ;
141+
142+ // invoke SFTP poll lambda
143+ await lambdaClient . send (
144+ new InvokeCommand ( {
145+ FunctionName : process . env . SFTP_POLL_LAMBDA_NAME ,
146+ } )
147+ ) ;
148+
149+ // check for expected results
150+ await expect ( async ( ) => {
151+ const template = await templateStorageHelper . getTemplate ( {
152+ owner : user . userId ,
153+ id : templateId ,
154+ } ) ;
155+
156+ expect ( template . files ?. proofs ) . toEqual ( {
157+ proof : {
158+ fileName : `proofs/${ user . userId } /${ templateId } /proof.pdf` ,
159+ virusScanStatus : 'FAILED' ,
160+ } ,
161+ } ) ;
162+
163+ expect ( template . templateStatus ) . toEqual ( 'WAITING_FOR_PROOF' ) ;
101164
102- const internalPdf = await templateStorageHelper . getLetterTemplateFile (
103- process . env . TEMPLATES_INTERNAL_BUCKET_NAME ,
165+ const pdf = await templateStorageHelper . getLetterProofFile (
166+ process . env . TEMPLATES_QUARANTINE_BUCKET_NAME ,
104167 'proofs' ,
105- { owner : user . userId , id : templateId } ,
106- fileName ,
168+ templateId ,
169+ 'proof' ,
107170 'pdf'
108171 ) ;
109172
110- expect ( internalPdf ?. ChecksumSHA256 ) . toEqual (
111- pdfUploadFixtures . withPersonalisation . pdf . checksumSha256 ( )
112- ) ;
113- }
114- } ) . toPass ( { timeout : 10_000 } ) ;
115- } ) ;
116-
117- test ( 'if the only proof fails the virus scan, the status is not updated to PROOF_AVAILABLE' , async ( ) => {
118- const templateId = 'test-template-id-proofing-e2e-failure' ;
119- const user = await authHelper . getTestUser ( TestUserId . User1 ) ;
120-
121- // add entries to database
122- await templateStorageHelper . seedTemplateData ( [
123- TemplateFactory . createLetterTemplate (
124- templateId ,
125- user . userId ,
126- templateId ,
127- 'WAITING_FOR_PROOF'
128- ) ,
129- ] ) ;
130-
131- // add proofs to SFTP mock
132- const pdfContent = readFileSync (
133- './fixtures/pdf-upload/no-custom-personalisation/password.pdf'
134- ) ;
135-
136- await sftpHelper . put (
137- pdfContent ,
138- `WTMMOCK/Outgoing/proofs/${ templateId } /proof.pdf`
139- ) ;
140-
141- // invoke SFTP poll lambda
142- await lambdaClient . send (
143- new InvokeCommand ( {
144- FunctionName : process . env . SFTP_POLL_LAMBDA_NAME ,
145- } )
146- ) ;
147-
148- // check for expected results
149- await expect ( async ( ) => {
150- const template = await templateStorageHelper . getTemplate ( {
151- owner : user . userId ,
152- id : templateId ,
153- } ) ;
154-
155- expect ( template . files ?. proofs ) . toEqual ( {
156- proof : {
157- fileName : `proofs/${ user . userId } /${ templateId } /proof.pdf` ,
158- virusScanStatus : 'FAILED' ,
159- } ,
160- } ) ;
161-
162- expect ( template . templateStatus ) . toEqual ( 'WAITING_FOR_PROOF' ) ;
163-
164- const pdf = await templateStorageHelper . getLetterProofFile (
165- process . env . TEMPLATES_QUARANTINE_BUCKET_NAME ,
166- 'proofs' ,
167- templateId ,
168- 'proof' ,
169- 'pdf'
170- ) ;
171-
172- expect ( pdf ) . toBe ( null ) ;
173- } ) . toPass ( { timeout : 10_000 } ) ;
173+ expect ( pdf ) . toBe ( null ) ;
174+ } ) . toPass ( { timeout : 10_000 } ) ;
175+ } ) ;
174176} ) ;
0 commit comments