@@ -216,13 +216,25 @@ describe('Activity Service', () => {
216
216
const query = { } ;
217
217
const aggregationResult = [ ] ;
218
218
const listAggregationMock = jest . spyOn ( service as any , 'listAggregation' ) ;
219
- listAggregationMock . mockResolvedValueOnce ( aggregationResult ) ;
219
+ // Count
220
+ listAggregationMock . mockReturnValueOnce ( {
221
+ count : ( ) => [ { count : 20000 } ] ,
222
+ } ) ;
223
+ // 2 pages
224
+ listAggregationMock . mockReturnValueOnce ( {
225
+ skip : jest . fn ( ) . mockReturnThis ( ) ,
226
+ limit : jest . fn ( ) . mockResolvedValueOnce ( aggregationResult ) ,
227
+ } ) ;
228
+ listAggregationMock . mockReturnValueOnce ( {
229
+ skip : jest . fn ( ) . mockReturnThis ( ) ,
230
+ limit : jest . fn ( ) . mockResolvedValueOnce ( aggregationResult ) ,
231
+ } ) ;
220
232
221
233
const mockFile = Buffer . from ( 'Test content' ) ;
222
234
jest . spyOn ( XLSBuilder , 'default' ) . mockResolvedValueOnce ( mockFile as any ) ;
223
235
224
236
const result = await service . downloadList ( query ) ;
225
- expect ( listAggregationMock ) . toHaveBeenCalled ( ) ;
237
+ expect ( listAggregationMock ) . toHaveBeenCalledTimes ( 3 ) ; // 1 for count, 2 for pagination
226
238
expect ( result ) . toEqual ( {
227
239
fileName : ( service as any ) . listExportFileName ,
228
240
file : mockFile ,
@@ -235,7 +247,11 @@ describe('Activity Service', () => {
235
247
236
248
const listAggregationMock = jest
237
249
. spyOn ( service as any , 'listAggregation' )
238
- . mockRejectedValueOnce ( error ) ;
250
+ . mockReturnValueOnce ( {
251
+ count : ( ) => {
252
+ throw error ;
253
+ } ,
254
+ } ) ;
239
255
240
256
await expect ( service . downloadList ( query ) ) . rejects . toThrow ( error ) ;
241
257
expect ( listAggregationMock ) . toHaveBeenCalled ( ) ;
0 commit comments