@@ -357,8 +357,11 @@ describe('connectionResolver', () => {
357
357
358
358
describe ( '"Relay Cursor Connections Specification (PageInfo)":' , ( ) => {
359
359
describe ( 'HasPreviousPage' , ( ) => {
360
- it ( 'If last was not set, return false.' , ( ) => {
361
- expect ( preparePageInfo ( fiveEdges , { } , 5 , 2 ) . hasPreviousPage ) . toBe ( false ) ;
360
+ it ( 'If last was not set (but first is present), return false.' , ( ) => {
361
+ expect ( preparePageInfo ( fiveEdges , { first : 2 } , 5 , 2 ) . hasPreviousPage ) . toBe ( false ) ;
362
+ } ) ;
363
+ it ( 'If last was not set (and first is empty), return true.' , ( ) => {
364
+ expect ( preparePageInfo ( fiveEdges , { } , 5 , 2 ) . hasPreviousPage ) . toBe ( true ) ;
362
365
} ) ;
363
366
it ( 'If edges contains more than last elements, return true.' , ( ) => {
364
367
expect ( preparePageInfo ( fiveEdges , { last : 3 } , 3 , 2 ) . hasPreviousPage ) . toBe ( true ) ;
@@ -811,4 +814,26 @@ describe('connectionResolver', () => {
811
814
expect ( result . edges [ 1 ] . node . id ) . toBe ( 2 ) ;
812
815
} ) ;
813
816
} ) ;
817
+
818
+ describe ( 'default `first` argument if first/last are empty' , ( ) => {
819
+ const defaultResolver = prepareConnectionResolver ( userTypeComposer , {
820
+ countResolverName : 'count' ,
821
+ findResolverName : 'findMany' ,
822
+ sort : sortOptions ,
823
+ defaultLimit : 5 ,
824
+ } ) ;
825
+
826
+ it ( 'should use defaultLimit option' , async ( ) => {
827
+ const data = await defaultResolver . resolve ( { args : { } } ) ;
828
+ expect ( data . edges . length ) . toBe ( 5 ) ;
829
+ expect ( data . pageInfo . hasNextPage ) . toBe ( true ) ;
830
+ } ) ;
831
+
832
+ it ( 'should use defaultLimit option with after option' , async ( ) => {
833
+ const data = await defaultResolver . resolve ( { args : { after : 'NA==' } } ) ;
834
+ expect ( data . edges . length ) . toBe ( 5 ) ;
835
+ expect ( data . pageInfo . hasNextPage ) . toBe ( true ) ;
836
+ expect ( data . pageInfo . hasPreviousPage ) . toBe ( true ) ;
837
+ } ) ;
838
+ } ) ;
814
839
} ) ;
0 commit comments