@@ -173,50 +173,6 @@ describe('WorkerAdapter', () => {
173
173
expect ( result [ 0 ] ) . toHaveLength ( 1 ) ;
174
174
expect ( result [ 1 ] ) . toHaveLength ( 1 ) ;
175
175
} ) ;
176
-
177
- it ( 'should handle invalid (0) batch size' , async ( ) => {
178
- // Arrange
179
- const mockStream = jest . fn ( ) ;
180
- const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
181
-
182
- // Act
183
- const result = await adapter . streamAttachments ( {
184
- stream : mockStream ,
185
- batchSize : 0 ,
186
- } ) ;
187
-
188
- // Assert
189
- expect ( consoleErrorSpy ) . toHaveBeenCalled ( ) ;
190
- expect ( result ) . toEqual ( {
191
- error : expect . any ( Error ) ,
192
- } ) ;
193
- expect ( result ?. error ?. message ) . toContain ( 'Invalid attachments batch size' ) ;
194
-
195
- // Restore console.error
196
- consoleErrorSpy . mockRestore ( ) ;
197
- } ) ;
198
-
199
- it ( 'should handle invalid (negative) batch size' , async ( ) => {
200
- // Arrange
201
- const mockStream = jest . fn ( ) ;
202
- const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
203
-
204
- // Act
205
- const result = await adapter . streamAttachments ( {
206
- stream : mockStream ,
207
- batchSize : - 1 ,
208
- } ) ;
209
-
210
- // Assert
211
- expect ( consoleErrorSpy ) . toHaveBeenCalled ( ) ;
212
- expect ( result ) . toEqual ( {
213
- error : expect . any ( Error ) ,
214
- } ) ;
215
- expect ( result ?. error ?. message ) . toContain ( 'Invalid attachments batch size' ) ;
216
-
217
- // Restore console.error
218
- consoleErrorSpy . mockRestore ( ) ;
219
- } ) ;
220
176
} ) ;
221
177
222
178
describe ( 'defaultAttachmentsIterator' , ( ) => {
@@ -480,7 +436,29 @@ describe('WorkerAdapter', () => {
480
436
it ( 'should handle invalid batch size' , async ( ) => {
481
437
// Arrange
482
438
const mockStream = jest . fn ( ) ;
483
- const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
439
+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ) ;
440
+
441
+ // Set up adapter state with artifact IDs
442
+ adapter . state . toDevRev = {
443
+ attachmentsMetadata : {
444
+ artifactIds : [ 'artifact1' ] ,
445
+ lastProcessed : 0 ,
446
+ lastProcessedAttachmentsIdsList : [ ] ,
447
+ } ,
448
+ } ;
449
+
450
+ // Mock getting attachments
451
+ adapter [ 'uploader' ] . getAttachmentsFromArtifactId = jest . fn ( ) . mockResolvedValue ( {
452
+ attachments : [
453
+ { url : 'http://example.com/file1.pdf' , id : 'attachment1' , file_name : 'file1.pdf' , parent_id : 'parent1' } ,
454
+ ] ,
455
+ } ) ;
456
+
457
+ // Mock the required methods
458
+ adapter . initializeRepos = jest . fn ( ) ;
459
+ const mockReducedAttachments = [ [ 'batch1' ] ] ;
460
+ adapter [ 'defaultAttachmentsReducer' ] = jest . fn ( ) . mockReturnValue ( mockReducedAttachments ) ;
461
+ adapter [ 'defaultAttachmentsIterator' ] = jest . fn ( ) . mockResolvedValue ( { } ) ;
484
462
485
463
// Act
486
464
const result = await adapter . streamAttachments ( {
@@ -489,14 +467,72 @@ describe('WorkerAdapter', () => {
489
467
} ) ;
490
468
491
469
// Assert
492
- expect ( consoleErrorSpy ) . toHaveBeenCalled ( ) ;
493
- expect ( result ) . toEqual ( {
494
- error : expect . any ( Error ) ,
470
+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
471
+ 'The specified batch size (0) is invalid. Using 1 instead.'
472
+ ) ;
473
+
474
+ // Verify that the reducer was called with batchSize 50 (not 100)
475
+ expect ( adapter [ 'defaultAttachmentsReducer' ] ) . toHaveBeenCalledWith ( {
476
+ attachments : expect . any ( Array ) ,
477
+ adapter : adapter ,
478
+ batchSize : 1 ,
495
479
} ) ;
496
- expect ( result ?. error ?. message ) . toContain ( 'Invalid attachments batch size' ) ;
497
480
498
- // Restore console.error
499
- consoleErrorSpy . mockRestore ( ) ;
481
+ expect ( result ) . toBeUndefined ( ) ;
482
+
483
+ // Restore console.warn
484
+ consoleWarnSpy . mockRestore ( ) ;
485
+ } ) ;
486
+
487
+ it ( 'should cap batch size to 50 when batchSize is greater than 50' , async ( ) => {
488
+ // Arrange
489
+ const mockStream = jest . fn ( ) ;
490
+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ) ;
491
+
492
+ // Set up adapter state with artifact IDs
493
+ adapter . state . toDevRev = {
494
+ attachmentsMetadata : {
495
+ artifactIds : [ 'artifact1' ] ,
496
+ lastProcessed : 0 ,
497
+ lastProcessedAttachmentsIdsList : [ ] ,
498
+ } ,
499
+ } ;
500
+
501
+ // Mock getting attachments
502
+ adapter [ 'uploader' ] . getAttachmentsFromArtifactId = jest . fn ( ) . mockResolvedValue ( {
503
+ attachments : [
504
+ { url : 'http://example.com/file1.pdf' , id : 'attachment1' , file_name : 'file1.pdf' , parent_id : 'parent1' } ,
505
+ ] ,
506
+ } ) ;
507
+
508
+ // Mock the required methods
509
+ adapter . initializeRepos = jest . fn ( ) ;
510
+ const mockReducedAttachments = [ [ 'batch1' ] ] ;
511
+ adapter [ 'defaultAttachmentsReducer' ] = jest . fn ( ) . mockReturnValue ( mockReducedAttachments ) ;
512
+ adapter [ 'defaultAttachmentsIterator' ] = jest . fn ( ) . mockResolvedValue ( { } ) ;
513
+
514
+ // Act
515
+ const result = await adapter . streamAttachments ( {
516
+ stream : mockStream ,
517
+ batchSize : 100 , // Set batch size greater than 50
518
+ } ) ;
519
+
520
+ // Assert
521
+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
522
+ 'The specified batch size (100) is too large. Using 50 instead.'
523
+ ) ;
524
+
525
+ // Verify that the reducer was called with batchSize 50 (not 100)
526
+ expect ( adapter [ 'defaultAttachmentsReducer' ] ) . toHaveBeenCalledWith ( {
527
+ attachments : expect . any ( Array ) ,
528
+ adapter : adapter ,
529
+ batchSize : 50 , // Should be capped at 50
530
+ } ) ;
531
+
532
+ expect ( result ) . toBeUndefined ( ) ;
533
+
534
+ // Restore console.warn
535
+ consoleWarnSpy . mockRestore ( ) ;
500
536
} ) ;
501
537
502
538
it ( 'should handle empty attachments metadata artifact IDs' , async ( ) => {
0 commit comments