@@ -65,48 +65,57 @@ describe('createClientApi', () => {
6565 ) . rejects . toEqual ( error )
6666 } )
6767
68- test ( 'getSpaces calls getMany with query' , async ( ) => {
69- const { api, makeRequest } = setup (
70- Promise . resolve ( { sys : { type : 'Array' } , total : 0 , skip : 0 , limit : 100 , items : [ ] } ) ,
71- )
68+ const collectionResponse = { sys : { type : 'Array' } , total : 0 , skip : 0 , limit : 100 , items : [ ] }
69+ const cursorCollectionResponse = { sys : { type : 'Array' } , limit : 100 , items : [ ] , pages : { } }
70+
71+ test ( 'getSpaces calls getMany' , async ( ) => {
72+ const { api, makeRequest } = setup ( Promise . resolve ( collectionResponse ) )
7273 await api . getSpaces ( { limit : 10 } )
7374 expect ( makeRequest ) . toHaveBeenCalledWith (
7475 expect . objectContaining ( { entityType : 'Space' , action : 'getMany' } ) ,
7576 )
7677 } )
7778
7879 test ( 'getSpaces with cursor:true passes cursor in query' , async ( ) => {
79- const { api, makeRequest } = setup (
80- Promise . resolve ( { sys : { type : 'Array' } , total : 0 , skip : 0 , limit : 100 , items : [ ] } ) ,
81- )
80+ const { api, makeRequest } = setup ( Promise . resolve ( cursorCollectionResponse ) )
8281 await api . getSpaces ( { cursor : true , limit : 10 } )
8382 const [ call ] = makeRequest . mock . calls
8483 expect ( call [ 0 ] . action ) . toBe ( 'getMany' )
8584 expect ( call [ 0 ] . params . query ) . toMatchObject ( { cursor : true , limit : 10 } )
8685 } )
8786
8887 test ( 'getSpaces with cursor:true and pageNext passes pageNext in query' , async ( ) => {
89- const { api, makeRequest } = setup (
90- Promise . resolve ( { sys : { type : 'Array' } , total : 0 , skip : 0 , limit : 100 , items : [ ] } ) ,
91- )
88+ const { api, makeRequest } = setup ( Promise . resolve ( cursorCollectionResponse ) )
9289 await api . getSpaces ( { cursor : true , pageNext : 'next-token' } )
9390 const [ call ] = makeRequest . mock . calls
9491 expect ( call [ 0 ] . params . query ) . toMatchObject ( { cursor : true , pageNext : 'next-token' } )
9592 } )
9693
97- test ( 'getSpaces with organizationId passes it in params ' , async ( ) => {
98- const { api, makeRequest } = setup (
99- Promise . resolve ( { sys : { type : 'Array ' } , total : 0 , skip : 0 , limit : 100 , items : [ ] } ) ,
94+ test ( 'getSpaces with cursor:true returns cursor paginated collection ' , async ( ) => {
95+ const { api } = setup (
96+ Promise . resolve ( { ... cursorCollectionResponse , pages : { next : 'pageNext=abc ' } } ) ,
10097 )
98+ const result = await api . getSpaces ( { cursor : true } )
99+ expect ( result ) . toHaveProperty ( 'pages' )
100+ expect ( result ) . not . toHaveProperty ( 'total' )
101+ } )
102+
103+ test ( 'getSpaces without cursor returns regular collection' , async ( ) => {
104+ const { api } = setup ( Promise . resolve ( collectionResponse ) )
105+ const result = await api . getSpaces ( )
106+ expect ( result ) . toHaveProperty ( 'total' )
107+ expect ( result ) . not . toHaveProperty ( 'pages' )
108+ } )
109+
110+ test ( 'getSpaces with organizationId passes it in params' , async ( ) => {
111+ const { api, makeRequest } = setup ( Promise . resolve ( collectionResponse ) )
101112 await api . getSpaces ( { } , 'test-org' )
102113 const [ call ] = makeRequest . mock . calls
103114 expect ( call [ 0 ] . params . organizationId ) . toBe ( 'test-org' )
104115 } )
105116
106117 test ( 'getSpaces without organizationId omits it from params' , async ( ) => {
107- const { api, makeRequest } = setup (
108- Promise . resolve ( { sys : { type : 'Array' } , total : 0 , skip : 0 , limit : 100 , items : [ ] } ) ,
109- )
118+ const { api, makeRequest } = setup ( Promise . resolve ( collectionResponse ) )
110119 await api . getSpaces ( )
111120 const [ call ] = makeRequest . mock . calls
112121 expect ( call [ 0 ] . params . organizationId ) . toBeUndefined ( )
0 commit comments