Skip to content

Commit e8b79c3

Browse files
authored
trivial: fix next_page/nextPage confusion in paginated MSW util (#2987)
fix next_page/nextPage confusion in paginated msw util
1 parent ae965cf commit e8b79c3

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

mock-api/msw/handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,10 +1144,10 @@ export const handlers = makeHandlers({
11441144
return utilizationForSilo(silo)
11451145
},
11461146
siloUtilizationList({ query }) {
1147-
const { items: silos, nextPage } = paginated(query, db.silos)
1147+
const { items: silos, next_page } = paginated(query, db.silos)
11481148
return {
11491149
items: silos.map(utilizationForSilo),
1150-
nextPage,
1150+
next_page,
11511151
}
11521152
},
11531153
vpcList({ query }) {

mock-api/msw/util.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ describe('paginated', () => {
1717
const items = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]
1818
const page = paginated({}, items)
1919
expect(page.items).toEqual([{ id: 'a' }, { id: 'b' }, { id: 'c' }])
20-
expect(page.nextPage).toBeNull()
20+
expect(page.next_page).toBeNull()
2121
})
2222

2323
it('should return the first 100 items with no limit passed', () => {
2424
const items = Array.from({ length: 200 }).map((_, i) => ({ id: 'i' + i }))
2525
const page = paginated({}, items)
2626
expect(page.items.length).toBe(100)
2727
expect(page.items).toEqual(items.slice(0, 100))
28-
expect(page.nextPage).toBe('i100')
28+
expect(page.next_page).toBe('i100')
2929
})
3030

31-
it('should return page with null `nextPage` if items equal page', () => {
31+
it('should return page with null `next_page` if items equal page', () => {
3232
const items = [
3333
{ id: 'a' },
3434
{ id: 'b' },
@@ -44,7 +44,7 @@ describe('paginated', () => {
4444
const page = paginated({}, items)
4545
expect(page.items.length).toBe(10)
4646
expect(page.items).toEqual(items.slice(0, 10))
47-
expect(page.nextPage).toBeNull()
47+
expect(page.next_page).toBeNull()
4848
})
4949

5050
it('should return 5 items with a limit of 5', () => {
@@ -59,15 +59,15 @@ describe('paginated', () => {
5959
const page = paginated({ limit: 5 }, items)
6060
expect(page.items.length).toBe(5)
6161
expect(page.items).toEqual(items.slice(0, 5))
62-
expect(page.nextPage).toBe('f')
62+
expect(page.next_page).toBe('f')
6363
})
6464

6565
it('should return the second page when given a `page_token`', () => {
6666
const items = [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }]
6767
const page = paginated({ pageToken: 'b' }, items)
6868
expect(page.items.length).toBe(3)
6969
expect(page.items).toEqual([{ id: 'b' }, { id: 'c' }, { id: 'd' }])
70-
expect(page.nextPage).toBeNull()
70+
expect(page.next_page).toBeNull()
7171
})
7272
})
7373

mock-api/msw/util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface PaginateOptions {
4343
}
4444
export interface ResultsPage<I extends { id: string }> {
4545
items: I[]
46-
nextPage: string | null
46+
next_page: string | null
4747
}
4848

4949
export const paginated = <P extends PaginateOptions, I extends { id: string }>(
@@ -59,20 +59,20 @@ export const paginated = <P extends PaginateOptions, I extends { id: string }>(
5959
if (startIndex > items.length) {
6060
return {
6161
items: [],
62-
nextPage: null,
62+
next_page: null,
6363
}
6464
}
6565

6666
if (limit + startIndex >= items.length) {
6767
return {
6868
items: items.slice(startIndex),
69-
nextPage: null,
69+
next_page: null,
7070
}
7171
}
7272

7373
return {
7474
items: items.slice(startIndex, startIndex + limit),
75-
nextPage: `${items[startIndex + limit].id}`,
75+
next_page: `${items[startIndex + limit].id}`,
7676
}
7777
}
7878

0 commit comments

Comments
 (0)