MCPcopy
hub / github.com/desktop/desktop / assertNext

Function assertNext

app/test/unit/api-test.ts:18–50  ·  view source on GitHub ↗
(current: IPageInfo, expected: IPageInfo)

Source from the content-addressed store, hash-verified

16}
17
18function assertNext(current: IPageInfo, expected: IPageInfo) {
19 const headers = createHeadersWithNextLink(
20 `/items?per_page=${current.per_page}&page=${current.page}`
21 )
22
23 const nextPath = getNextPagePathWithIncreasingPageSize(
24 new Response(null, { headers })
25 )
26
27 assert(nextPath !== null)
28 const { pathname, query } = URL.parse(nextPath, true)
29
30 assert.equal(pathname, '/items')
31
32 const per_page = parseInt(
33 typeof query.per_page === 'string' ? query.per_page : '',
34 10
35 )
36 const page = parseInt(typeof query.page === 'string' ? query.page : '', 10)
37
38 assert.equal(per_page, expected.per_page)
39 assert.equal(page, expected.page)
40
41 // If getNextPagePathWithIncreasingPageSize has fiddled with the
42 // page size or page number we want to ensure that the next page will
43 // get us more items than what we've gotten thus far.
44 if (current.per_page !== per_page || current.page !== page) {
45 const receivedCurrent = current.per_page * current.page
46 const receivedNext = per_page * page
47
48 assert(receivedNext > receivedCurrent)
49 }
50}
51
52describe('API', () => {
53 describe('getNextPagePathWithIncreasingPageSize', () => {

Callers 1

api-test.tsFile · 0.85

Calls 3

parseMethod · 0.65

Tested by

no test coverage detected