@@ -22,6 +22,7 @@ import {
2222 parseFilterToken ,
2323} from './filter'
2424import { paginate , PaginateConfig , Paginated , PaginationLimit , PaginationType } from './paginate'
25+ import globalConfig , { updateGlobalConfig } from './global-config'
2526
2627// Disable debug logs during tests
2728beforeAll ( ( ) => {
@@ -285,6 +286,57 @@ describe('paginate', () => {
285286 expect ( result . data ) . toStrictEqual ( cats . slice ( 0 , 1 ) )
286287 } )
287288
289+ it ( 'should accept and use empty string as default origin in config, even if global provided' , async ( ) => {
290+ updateGlobalConfig ( {
291+ defaultOrigin : 'http://localhost:8081' ,
292+ } )
293+
294+ const config : PaginateConfig < CatEntity > = {
295+ sortableColumns : [ 'id' ] ,
296+ defaultSortBy : [ [ 'id' , 'ASC' ] ] ,
297+ defaultLimit : 1 ,
298+ origin : '' ,
299+ }
300+
301+ const query : PaginateQuery = {
302+ path : 'http://localhost:8080/cat' ,
303+ }
304+
305+ const result = await paginate < CatEntity > ( query , catRepo , config )
306+
307+ expect ( result ) . toBeInstanceOf ( Paginated )
308+ expect ( result . links . current ) . toStrictEqual ( '/cat?page=1&limit=1&sortBy=id:ASC' )
309+
310+ updateGlobalConfig ( {
311+ defaultOrigin : undefined ,
312+ } )
313+ } )
314+
315+ it ( 'should use default origin from global config if provided, over the one from request' , async ( ) => {
316+ updateGlobalConfig ( {
317+ defaultOrigin : 'http://localhost:8081' ,
318+ } )
319+
320+ const config : PaginateConfig < CatEntity > = {
321+ sortableColumns : [ 'id' ] ,
322+ defaultSortBy : [ [ 'id' , 'ASC' ] ] ,
323+ defaultLimit : 1 ,
324+ }
325+
326+ const query : PaginateQuery = {
327+ path : 'http://localhost:8080/cat' ,
328+ }
329+
330+ const result = await paginate < CatEntity > ( query , catRepo , config )
331+
332+ expect ( result ) . toBeInstanceOf ( Paginated )
333+ expect ( result . links . current ) . toStrictEqual ( 'http://localhost:8081/cat?page=1&limit=1&sortBy=id:ASC' )
334+
335+ updateGlobalConfig ( {
336+ defaultOrigin : undefined ,
337+ } )
338+ } )
339+
288340 it ( 'should accept a query builder' , async ( ) => {
289341 const config : PaginateConfig < CatEntity > = {
290342 sortableColumns : [ 'id' ] ,
@@ -499,7 +551,7 @@ describe('paginate', () => {
499551
500552 const result = await paginate < CatEntity > ( query , catRepo , config )
501553
502- expect ( result . data ) . toStrictEqual ( cats . slice ( 0 , PaginationLimit . DEFAULT_LIMIT ) )
554+ expect ( result . data ) . toStrictEqual ( cats . slice ( 0 , globalConfig . defaultLimit ) )
503555 } )
504556
505557 it ( 'should return the count without data ignoring maxLimit if limit is COUNTER_ONLY' , async ( ) => {
0 commit comments