@@ -2,7 +2,7 @@ import { mock } from 'jest-mock-extended';
22import { TemplateRepository } from '../../infra/template-repository' ;
33import { UserDataRepository } from '../../infra/user-data-repository' ;
44import { App } from '../../app/send' ;
5- import { Batch , Manifest } from '../../domain/batch' ;
5+ import { SyntheticBatch , Manifest } from '../../domain/synthetic- batch' ;
66import { SftpClient } from '../../infra/sftp-client' ;
77import { Readable } from 'node:stream' ;
88import { mockTestDataCsv , streamToString } from '../helpers' ;
@@ -18,16 +18,16 @@ const testDataVersion = 'test-data-version-id';
1818function setup ( ) {
1919 const userDataRepository = mock < UserDataRepository > ( ) ;
2020 const templateRepository = mock < TemplateRepository > ( ) ;
21- const batch = mock < Batch > ( ) ;
22- const { logger } = createMockLogger ( ) ;
21+ const syntheticBatch = mock < SyntheticBatch > ( ) ;
22+ const { logger, logMessages } = createMockLogger ( ) ;
2323
2424 const sftpClient = mock < SftpClient > ( ) ;
2525
2626 const app = new App (
2727 userDataRepository ,
2828 templateRepository ,
2929 sftpEnvironment ,
30- batch ,
30+ syntheticBatch ,
3131 logger
3232 ) ;
3333
@@ -36,10 +36,11 @@ function setup() {
3636 mocks : {
3737 userDataRepository,
3838 templateRepository,
39- batch ,
39+ syntheticBatch ,
4040 logger,
4141 sftpClient,
4242 } ,
43+ logMessages,
4344 } ;
4445}
4546
@@ -128,18 +129,18 @@ describe('App', () => {
128129
129130 const testDataCsv = mockTestDataCsv ( [ 'custom1' , 'custom2' ] , testData ) ;
130131
131- mocks . batch . getId . mockReturnValueOnce ( batchId ) ;
132+ mocks . syntheticBatch . getId . mockReturnValueOnce ( batchId ) ;
132133
133134 mocks . userDataRepository . get . mockResolvedValueOnce ( {
134135 testData : testDataCsv ,
135136 pdf,
136137 } ) ;
137138
138- mocks . batch . buildBatch . mockReturnValueOnce ( batchData ) ;
139+ mocks . syntheticBatch . buildBatch . mockReturnValueOnce ( batchData ) ;
139140
140- mocks . batch . getHeader . mockReturnValueOnce ( batchColumns . join ( ',' ) ) ;
141+ mocks . syntheticBatch . getHeader . mockReturnValueOnce ( batchColumns . join ( ',' ) ) ;
141142
142- mocks . batch . buildManifest . mockReturnValueOnce ( manifestData ) ;
143+ mocks . syntheticBatch . buildManifest . mockReturnValueOnce ( manifestData ) ;
143144
144145 // manifest doesn't already exist
145146 mocks . sftpClient . exists . mockResolvedValueOnce ( false ) ;
@@ -154,18 +155,20 @@ describe('App', () => {
154155 testDataVersion
155156 ) ;
156157
157- expect ( mocks . batch . buildBatch ) . toHaveBeenCalledTimes ( 1 ) ;
158- expect ( mocks . batch . buildBatch ) . toHaveBeenCalledWith (
158+ expect ( mocks . syntheticBatch . buildBatch ) . toHaveBeenCalledTimes ( 1 ) ;
159+ expect ( mocks . syntheticBatch . buildBatch ) . toHaveBeenCalledWith (
159160 templateId ,
160161 personalisationFields ,
161162 testData
162163 ) ;
163164
164- expect ( mocks . batch . getHeader ) . toHaveBeenCalledTimes ( 1 ) ;
165- expect ( mocks . batch . getHeader ) . toHaveBeenCalledWith ( personalisationFields ) ;
165+ expect ( mocks . syntheticBatch . getHeader ) . toHaveBeenCalledTimes ( 1 ) ;
166+ expect ( mocks . syntheticBatch . getHeader ) . toHaveBeenCalledWith (
167+ personalisationFields
168+ ) ;
166169
167- expect ( mocks . batch . buildManifest ) . toHaveBeenCalledTimes ( 1 ) ;
168- expect ( mocks . batch . buildManifest ) . toHaveBeenCalledWith (
170+ expect ( mocks . syntheticBatch . buildManifest ) . toHaveBeenCalledTimes ( 1 ) ;
171+ expect ( mocks . syntheticBatch . buildManifest ) . toHaveBeenCalledWith (
169172 templateId ,
170173 batchId ,
171174 batchCsv
@@ -239,7 +242,7 @@ describe('App', () => {
239242 } ) ;
240243
241244 test ( 'exist early and does not send if the manifest is already in the SFTP server' , async ( ) => {
242- const { app, mocks } = setup ( ) ;
245+ const { app, mocks, logMessages } = setup ( ) ;
243246
244247 const personalisationFields = [ 'pdsField' ] ;
245248 const batchColumns = [ 'clientRef' , 'template' , ...personalisationFields ] ;
@@ -287,44 +290,47 @@ describe('App', () => {
287290 md5sum : batchHash ,
288291 } ;
289292
290- mocks . batch . getId . mockReturnValueOnce ( batchId ) ;
293+ mocks . syntheticBatch . getId . mockReturnValueOnce ( batchId ) ;
291294
292295 mocks . userDataRepository . get . mockResolvedValueOnce ( {
293296 testData : undefined ,
294297 pdf,
295298 } ) ;
296299
297- mocks . batch . buildBatch . mockReturnValueOnce ( batchData ) ;
300+ mocks . syntheticBatch . buildBatch . mockReturnValueOnce ( batchData ) ;
298301
299- mocks . batch . getHeader . mockReturnValueOnce ( batchColumns . join ( ',' ) ) ;
302+ mocks . syntheticBatch . getHeader . mockReturnValueOnce ( batchColumns . join ( ',' ) ) ;
300303
301- mocks . batch . buildManifest . mockReturnValueOnce ( manifestData ) ;
304+ mocks . syntheticBatch . buildManifest . mockReturnValueOnce ( manifestData ) ;
302305
303306 // manifest already exists
304307 mocks . sftpClient . exists . mockResolvedValueOnce ( '-' ) ;
305308
306309 await app . send ( JSON . stringify ( event ) , mocks . sftpClient , baseUploadDir ) ;
307310
308- expect ( mocks . userDataRepository . get ) . toHaveBeenCalledTimes ( 1 ) ;
309- expect ( mocks . userDataRepository . get ) . toHaveBeenCalledWith (
310- owner ,
311- templateId ,
312- pdfVersion ,
313- testDataVersion
311+ expect ( logMessages ) . toContainEqual (
312+ expect . objectContaining ( {
313+ level : 'warn' ,
314+ message : 'Manifest already exists, assuming duplicate event' ,
315+ } )
314316 ) ;
315317
316- expect ( mocks . batch . buildBatch ) . toHaveBeenCalledTimes ( 1 ) ;
317- expect ( mocks . batch . buildBatch ) . toHaveBeenCalledWith (
318+ expect ( mocks . userDataRepository . get ) . toHaveBeenCalledTimes ( 1 ) ;
319+
320+ expect ( mocks . syntheticBatch . buildBatch ) . toHaveBeenCalledTimes ( 1 ) ;
321+ expect ( mocks . syntheticBatch . buildBatch ) . toHaveBeenCalledWith (
318322 templateId ,
319323 personalisationFields ,
320324 undefined
321325 ) ;
322326
323- expect ( mocks . batch . getHeader ) . toHaveBeenCalledTimes ( 1 ) ;
324- expect ( mocks . batch . getHeader ) . toHaveBeenCalledWith ( personalisationFields ) ;
327+ expect ( mocks . syntheticBatch . getHeader ) . toHaveBeenCalledTimes ( 1 ) ;
328+ expect ( mocks . syntheticBatch . getHeader ) . toHaveBeenCalledWith (
329+ personalisationFields
330+ ) ;
325331
326- expect ( mocks . batch . buildManifest ) . toHaveBeenCalledTimes ( 1 ) ;
327- expect ( mocks . batch . buildManifest ) . toHaveBeenCalledWith (
332+ expect ( mocks . syntheticBatch . buildManifest ) . toHaveBeenCalledTimes ( 1 ) ;
333+ expect ( mocks . syntheticBatch . buildManifest ) . toHaveBeenCalledWith (
328334 templateId ,
329335 batchId ,
330336 batchCsv
0 commit comments