@@ -254,7 +254,10 @@ describe('AssemblaConnector', function() {
254
254
status : 'Fixed'
255
255
} ] ;
256
256
257
- paginationParams = { 'per_page' : 100 } ;
257
+ paginationParams = {
258
+ 'page' : 1 ,
259
+ 'per_page' : connector . TICKET_LIST_PAGE_SIZE
260
+ } ;
258
261
259
262
stubHttpReponseFor ( 'get' , ticketsApiUrl + '/statuses.json' ) . andRespondWith ( 200 , apiData . ticketStatuses ) ;
260
263
} ) ;
@@ -307,6 +310,77 @@ describe('AssemblaConnector', function() {
307
310
} ) ;
308
311
309
312
313
+ describe ( 'pagination' , function ( ) {
314
+ var originalConnectorPageSize , page1 , page2 , page3 ;
315
+
316
+ beforeEach ( function ( ) {
317
+ originalConnectorPageSize = connector . TICKET_LIST_PAGE_SIZE ;
318
+ } ) ;
319
+
320
+ afterEach ( function ( ) {
321
+ connector . TICKET_LIST_PAGE_SIZE = originalConnectorPageSize ;
322
+ } ) ;
323
+
324
+ beforeEach ( function ( ) {
325
+ stubHttpReponseFor ( 'get' , spaceApiUrl + '/milestones/all.json' ) . andRespondWith ( 200 , [ ] ) ;
326
+
327
+ paginationParams [ 'per_page' ] =
328
+ connector . TICKET_LIST_PAGE_SIZE = 2 ;
329
+
330
+ page1 = [ {
331
+ number : 1 ,
332
+ summary : 'Summary 1' ,
333
+ description : 'Description 1' ,
334
+ state : 1 ,
335
+ status : 'In-Progress'
336
+ } , {
337
+ number : 2 ,
338
+ summary : 'Summary 2' ,
339
+ description : 'Description 2' ,
340
+ state : 1 ,
341
+ status : 'Fixed'
342
+ } ] ;
343
+ paginationParams . page = 1 ;
344
+ stubHttpReponseFor ( 'get' , ticketsApiUrl + '.json' , paginationParams ) . andRespondWith ( 200 , page1 ) ;
345
+
346
+ page2 = [ {
347
+ number : 3 ,
348
+ summary : 'Summary 3' ,
349
+ description : 'Description 3' ,
350
+ state : 1 ,
351
+ status : 'In-Progress'
352
+ } , {
353
+ number : 4 ,
354
+ summary : 'Summary 4' ,
355
+ description : 'Description 4' ,
356
+ state : 1 ,
357
+ status : 'Fixed'
358
+ } ] ;
359
+ paginationParams . page = 2 ;
360
+ stubHttpReponseFor ( 'get' , ticketsApiUrl + '.json' , paginationParams ) . andRespondWith ( 200 , page2 ) ;
361
+
362
+ page3 = [ {
363
+ number : 5 ,
364
+ summary : 'Summary 5' ,
365
+ description : 'Description 5' ,
366
+ state : 1 ,
367
+ status : 'Fixed'
368
+ } ] ;
369
+ paginationParams . page = 3 ;
370
+ stubHttpReponseFor ( 'get' , ticketsApiUrl + '.json' , paginationParams ) . andRespondWith ( 200 , page3 ) ;
371
+ } ) ;
372
+
373
+ it ( 'fetches all the tickets page-by-page' , function ( done ) {
374
+ connector . getGoals ( params , function ( jsendResponse ) {
375
+ expect ( jsendResponse . data . goals . length ) . toBe ( page1 . length + page2 . length + page3 . length ) ;
376
+ expect ( request . get . callCount ) . toBe ( 5 ) ; // 1 statuses + 1 milestones + 3 pages of tickets
377
+
378
+ done ( ) ;
379
+ } ) ;
380
+ } ) ;
381
+ } ) ;
382
+
383
+
310
384
it ( 'transforms and packs the received tickets into a success JSend response and passes it to the callback' , function ( done ) {
311
385
stubHttpReponseFor ( 'get' , spaceApiUrl + '/milestones/all.json' ) . andRespondWith ( 200 , [ ] ) ;
312
386
stubHttpReponseFor ( 'get' , ticketsApiUrl + '.json' , paginationParams ) . andRespondWith ( 200 , apiData . tickets ) ;
0 commit comments