fix: return page as object {page, next, total, hasMore, nextUrl} for routes.js compat

routes.js reads resp.page?.hasMore and resp.page?.nextUrl — the old
HTTP client returned page as an object from parsePageInfo. The CLI
pivot accidentally returned page as a number, making hasMore always
undefined in routes.js. Restore the object shape in both gitea and
gitlab clients. Update tests to assert the object shape.
This commit is contained in:
2026-09-05 20:36:46 +00:00
parent 9032c9245a
commit 75687dc9b0
4 changed files with 73 additions and 33 deletions
+21 -8
View File
@@ -187,37 +187,50 @@ describe('createGitLabClient request basics', () => {
});
describe('pagination', () => {
test('returns hasMore=true when Link header has rel="next"', async () => {
test('page is an object with hasMore=true when Link header has rel="next"', async () => {
spawnMock = mockSpawn(
cliOutput([{ id: 1 }], {
headers: {
'Link': '<https://gitlab.com/api/v4/projects/g%2Fp/issues?page=2>; rel="next"',
'X-Total': '10',
},
}),
);
const client = createGitLabClient({ token: 't', baseUrl: 'https://gitlab.com' });
const result = await client.issues('g/p', { per_page: 1 });
expect(result.hasMore).toBe(true);
expect(result.page).toBe(1);
expect(result.page).toEqual(expect.objectContaining({
hasMore: true,
nextUrl: 'https://gitlab.com/api/v4/projects/g%2Fp/issues?page=2',
next: 'https://gitlab.com/api/v4/projects/g%2Fp/issues?page=2',
page: 1,
total: 10,
}));
expect(Array.isArray(result.data)).toBe(true);
});
test('returns hasMore=false when no Link header', async () => {
test('page is an object with hasMore=false when no Link header', async () => {
spawnMock = mockSpawn(cliOutput([{ id: 1 }]));
const client = createGitLabClient({ token: 't', baseUrl: 'https://gitlab.com' });
const result = await client.issues('g/p', { per_page: 50 });
expect(result.hasMore).toBe(false);
expect(result.page).toBe(1);
expect(result.page).toEqual(expect.objectContaining({
hasMore: false,
next: null,
total: null,
}));
});
test('page is null for non-array responses', async () => {
test('page is an object for non-array responses too', async () => {
spawnMock = mockSpawn(cliOutput({ id: 42 }));
const client = createGitLabClient({ token: 't', baseUrl: 'https://gitlab.com' });
const result = await client.user();
expect(result.page).toBeNull();
expect(result.page).toEqual(expect.objectContaining({
hasMore: false,
next: null,
page: null,
}));
});
});