@@ -2,7 +2,7 @@ import { expect } from 'chai';
22import { createConnection , getConnection } from 'typeorm' ;
33
44import { createQueryBuilder } from './utils/createQueryBuilder' ;
5- import { buildPaginator , PagingResult } from '../src/index' ;
5+ import { buildPaginator } from '../src/index' ;
66import { Example } from './entities/Example' ;
77
88describe ( 'TypeORM cursor-based pagination test' , ( ) => {
@@ -21,55 +21,46 @@ describe('TypeORM cursor-based pagination test', () => {
2121 await getConnection ( ) . query ( 'CREATE TABLE example as SELECT generate_series(1, 10) AS id;' ) ;
2222 } ) ;
2323
24- let firstPageResult : PagingResult < Example > ;
25- let nextPageResult : PagingResult < Example > ;
26-
27- it ( 'should have afterCursor if the result set has next page' , async ( ) => {
24+ it ( 'should paginate correctly with before and after cursor' , async ( ) => {
2825 const queryBuilder = createQueryBuilder ( ) ;
29- const paginator = buildPaginator ( {
26+
27+ const firstPagePaginator = buildPaginator ( {
3028 entity : Example ,
3129 query : {
3230 limit : 1 ,
3331 } ,
3432 } ) ;
33+ const firstPageResult = await firstPagePaginator . paginate ( queryBuilder . clone ( ) ) ;
3534
36- firstPageResult = await paginator . paginate ( queryBuilder ) ;
37-
38- expect ( firstPageResult . cursor . afterCursor ) . to . not . eq ( null ) ;
39- expect ( firstPageResult . cursor . beforeCursor ) . to . eq ( null ) ;
40- expect ( firstPageResult . data [ 0 ] . id ) . to . eq ( 10 ) ;
41- } ) ;
42-
43- it ( 'should have beforeCursor if the result set has prev page' , async ( ) => {
44- const queryBuilder = createQueryBuilder ( ) ;
45- const paginator = buildPaginator ( {
35+ const nextPagePaginator = buildPaginator ( {
4636 entity : Example ,
4737 query : {
4838 limit : 1 ,
4939 afterCursor : firstPageResult . cursor . afterCursor as string ,
5040 } ,
5141 } ) ;
42+ const nextPageResult = await nextPagePaginator . paginate ( queryBuilder . clone ( ) ) ;
5243
53- nextPageResult = await paginator . paginate ( queryBuilder ) ;
54-
55- expect ( nextPageResult . cursor . afterCursor ) . to . not . eq ( null ) ;
56- expect ( nextPageResult . cursor . beforeCursor ) . to . not . eq ( null ) ;
57- expect ( nextPageResult . data [ 0 ] . id ) . to . eq ( 9 ) ;
58- } ) ;
59-
60- it ( 'should return prev page result set if beforeCursor is set' , async ( ) => {
61- const queryBuilder = createQueryBuilder ( ) ;
62- const paginator = buildPaginator ( {
44+ const prevPagePaginator = buildPaginator ( {
6345 entity : Example ,
6446 query : {
6547 limit : 1 ,
6648 beforeCursor : nextPageResult . cursor . beforeCursor as string ,
6749 } ,
6850 } ) ;
51+ const prevPageResult = await prevPagePaginator . paginate ( queryBuilder . clone ( ) ) ;
6952
70- const result = await paginator . paginate ( queryBuilder ) ;
53+ expect ( firstPageResult . cursor . beforeCursor ) . to . eq ( null ) ;
54+ expect ( firstPageResult . cursor . afterCursor ) . to . not . eq ( null ) ;
55+ expect ( firstPageResult . data [ 0 ] . id ) . to . eq ( 10 ) ;
56+
57+ expect ( nextPageResult . cursor . beforeCursor ) . to . not . eq ( null ) ;
58+ expect ( nextPageResult . cursor . afterCursor ) . to . not . eq ( null ) ;
59+ expect ( nextPageResult . data [ 0 ] . id ) . to . eq ( 9 ) ;
7160
72- expect ( result . data [ 0 ] . id ) . to . eq ( 10 ) ;
61+ expect ( prevPageResult . cursor . beforeCursor ) . to . eq ( null ) ;
62+ expect ( prevPageResult . cursor . afterCursor ) . to . not . eq ( null ) ;
63+ expect ( prevPageResult . data [ 0 ] . id ) . to . eq ( 10 ) ;
7364 } ) ;
7465
7566 it ( 'should return entities with given order' , async ( ) => {
0 commit comments