@@ -17,6 +17,9 @@ describe('linked-project-columns', () => {
1717 const getColumnsFixture = readFileSync ( resolvePath ( __dirname , './fixtures/get-project-columns.json' ) , {
1818 encoding : 'utf8'
1919 } ) ;
20+ const getSingleColumnFixture = readFileSync ( resolvePath ( __dirname , './fixtures/get-single-project-column.json' ) , {
21+ encoding : 'utf8'
22+ } ) ;
2023 const deleteCardFixture = readFileSync ( resolvePath ( __dirname , './fixtures/delete-project-card.json' ) , {
2124 encoding : 'utf8'
2225 } ) ;
@@ -28,6 +31,7 @@ describe('linked-project-columns', () => {
2831 } ) ;
2932
3033 let getColumnsResponse ;
34+ let getSingleColumnResponse ;
3135
3236 beforeEach ( ( ) => {
3337 process . env = {
@@ -45,8 +49,10 @@ describe('linked-project-columns', () => {
4549 sinon . stub ( octokit . graphql , 'defaults' ) . returns ( api ) ;
4650
4751 getColumnsResponse = JSON . parse ( getColumnsFixture ) ;
52+ getSingleColumnResponse = JSON . parse ( getSingleColumnFixture ) ;
4853
4954 api . withArgs ( queries . GET_PROJECT_COLUMNS ) . resolves ( getColumnsResponse ) ;
55+ api . withArgs ( queries . GET_SINGLE_PROJECT_COLUMN ) . resolves ( getSingleColumnResponse ) ;
5056 api . withArgs ( queries . DELETE_PROJECT_CARD ) . callsFake ( ( query , input ) => {
5157 const response = JSON . parse ( deleteCardFixture ) ;
5258 response . deleteProjectCard . deletedCardId = input . cardId ;
@@ -483,6 +489,54 @@ describe('linked-project-columns', () => {
483489 expect ( api . getCall ( 0 ) . args [ 0 ] ) . toContain ( 'archivedStates: [NOT_ARCHIVED]' ) ;
484490 } ) ;
485491
492+ it ( 'gathers additional pages of cards for source columns' , async ( ) => {
493+ getColumnsResponse . sourceColumns [ 0 ] . cards . pageInfo . hasNextPage = true ;
494+ getColumnsResponse . sourceColumns [ 0 ] . cards . pageInfo . endCursor = 'abc' ;
495+ getSingleColumnResponse . column . cards . nodes . push ( { id : 1 , note : '1' } , { id : 2 , note : '2' } ) ;
496+
497+ await run ( ) ;
498+
499+ expect ( core . warning . callCount ) . toEqual ( 0 ) ;
500+ expect ( core . setFailed . callCount ) . toEqual ( 0 ) ;
501+ expect ( api . callCount ) . toEqual ( 7 ) ;
502+ // call 0 -> get columns
503+ expect ( api . getCall ( 1 ) . args ) . toEqual ( [
504+ queries . GET_SINGLE_PROJECT_COLUMN ,
505+ {
506+ id : getColumnsResponse . sourceColumns [ 0 ] . id ,
507+ after : 'abc'
508+ }
509+ ] ) ;
510+ // call 2 -> add automation note
511+ expect ( api . getCall ( 3 ) . args ) . toEqual ( [ queries . ADD_PROJECT_CARD , { columnId : 2 , note : '1' } ] ) ;
512+ expect ( api . getCall ( 4 ) . args ) . toEqual ( [ queries . MOVE_PROJECT_CARD , { columnId : 2 , cardId : 201 , afterCardId : 200 } ] ) ;
513+ expect ( api . getCall ( 5 ) . args ) . toEqual ( [ queries . ADD_PROJECT_CARD , { columnId : 2 , note : '2' } ] ) ;
514+ expect ( api . getCall ( 6 ) . args ) . toEqual ( [ queries . MOVE_PROJECT_CARD , { columnId : 2 , cardId : 202 , afterCardId : 201 } ] ) ;
515+ } ) ;
516+
517+ it ( 'gathers additional pages of cards for the target column' , async ( ) => {
518+ getColumnsResponse . targetColumn . cards . pageInfo . hasNextPage = true ;
519+ getColumnsResponse . targetColumn . cards . pageInfo . endCursor = 'abc' ;
520+ getSingleColumnResponse . column . cards . nodes . push ( { id : 1 , note : '1' } , { id : 2 , note : '2' } ) ;
521+
522+ await run ( ) ;
523+
524+ expect ( core . warning . callCount ) . toEqual ( 0 ) ;
525+ expect ( core . setFailed . callCount ) . toEqual ( 0 ) ;
526+ expect ( api . callCount ) . toEqual ( 5 ) ;
527+ // call 0 -> get columns
528+ expect ( api . getCall ( 1 ) . args ) . toEqual ( [
529+ queries . GET_SINGLE_PROJECT_COLUMN ,
530+ {
531+ id : getColumnsResponse . targetColumn . id ,
532+ after : 'abc'
533+ }
534+ ] ) ;
535+ expect ( api . getCall ( 2 ) . args ) . toEqual ( [ queries . DELETE_PROJECT_CARD , { cardId : 2 } ] ) ;
536+ expect ( api . getCall ( 3 ) . args ) . toEqual ( [ queries . DELETE_PROJECT_CARD , { cardId : 1 } ] ) ;
537+ // call 4 -> add automation note
538+ } ) ;
539+
486540 describe ( 'with multiple source columns' , ( ) => {
487541 const secondSourceColumnId = 'second' ;
488542
@@ -496,7 +550,11 @@ describe('linked-project-columns', () => {
496550 name : 'source project'
497551 } ,
498552 cards : {
499- nodes : [ ]
553+ nodes : [ ] ,
554+ pageInfo : {
555+ hasNextPage : false ,
556+ endCursor : null
557+ }
500558 }
501559 } ) ;
502560 } ) ;
0 commit comments