@@ -5,6 +5,7 @@ class RunInBatches {
55 }
66
77 async getAll ( keys : string ) : Promise < string > ;
8+ async getAll ( keys : string [ ] ) : Promise < string [ ] > ;
89
910 @InBatches ( )
1011 async getAll ( keys : string | string [ ] ) : Promise < string | string [ ] > {
@@ -66,4 +67,26 @@ describe('Batch Decorator', () => {
6667 const values = await Promise . all ( promises ) ;
6768 expect ( values ) . toEqual ( [ 'batch1.1-index-0-i1' , 'batch1.2-index-1-i1' , 'batch2-index-0-i1' ] ) ;
6869 } ) ;
70+
71+ it ( 'should also work when passing array of keys to batch enabled method' , async ( ) => {
72+ const runner = new RunInBatches ( 'i1' ) ;
73+
74+ const values = await runner . getAll ( [ 'a' , 'b' , 'c' ] ) ;
75+ expect ( values ) . toEqual ( [ 'a-index-0-i1' , 'b-index-1-i1' , 'c-index-2-i1' ] ) ;
76+ } ) ;
77+
78+ it ( 'should also work when passing array of keys to batch enabled method (multiple batches)' , async ( ) => {
79+ const runner = new RunInBatches ( 'i1' ) ;
80+
81+ const keys = Array . from ( { length : 50 } , ( _ , i ) => 'key-' + i ) ;
82+ const values = await runner . getAll ( keys ) ;
83+
84+ expect ( values ) . toHaveLength ( 50 ) ;
85+ // batch 1 of 25 items
86+ expect ( values ) . toContain ( 'key-0-index-0-i1' ) ;
87+ expect ( values ) . toContain ( 'key-24-index-24-i1' ) ;
88+ // batch 2 of 25 items
89+ expect ( values ) . toContain ( 'key-25-index-0-i1' ) ;
90+ expect ( values ) . toContain ( 'key-49-index-24-i1' ) ;
91+ } ) ;
6992} ) ;
0 commit comments