diff --git a/test/prebuild/index.js b/test/prebuild/index.js index d46f743..11c2a3c 100644 --- a/test/prebuild/index.js +++ b/test/prebuild/index.js @@ -9,6 +9,9 @@ import { fuzzyMatchesWholeWord, eitherMatches } from '~/helpers/matching.js' +import { + PaginatedList +} from '~/helpers/api/pagination.js' require('dotenv').config() @@ -178,3 +181,45 @@ test('Can match names with pluses', (t) => { }) +test('Can paginate', async (t) => { + const cases = [ + { + from: { + list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + perPage: 2, + }, + expect: { + pageCount: 5, + pages: [ + { + number: 1, + items: [1, 2], + json: '[1,2]' + }, + { + number: 2, + items: [3, 4], + json: '[3,4]' + } + ] + } + } + ] + + for ( const { from, expect } of cases ) { + + const paginatedList = new PaginatedList( from ) + + // Assert that page count is correct + t.is( paginatedList.pageCount, expect.pageCount, 'pageCount is incorrect' ) + + // Assert that the pages we're expecting are there + for ( const expectedPage of expect.pages ) { + // Get respective output page + const outputPage = paginatedList.pages[ expectedPage.number - 1 ] + + t.deepEqual( outputPage, expectedPage, `Page ${ expectedPage.number } is an unexpected structure` ) + } + } + +} )