Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ describe("searchCode", () => {

// ─── fetchAllResults ──────────────────────────────────────────────────────────

const makeFetchItem = (i: number) => ({
path: `src/file${i}.ts`,
html_url: `https://github.com/org/repo/blob/main/src/file${i}.ts`,
repository: { full_name: "org/repo", archived: false },
text_matches: [],
});

describe("fetchAllResults", () => {
afterEach(() => {
globalThis.fetch = originalFetch;
Expand Down Expand Up @@ -180,12 +187,6 @@ describe("fetchAllResults", () => {
});

it("fetches multiple pages until total is reached", async () => {
const makeItem = (i: number) => ({
path: `src/file${i}.ts`,
html_url: `https://github.com/org/repo/blob/main/src/file${i}.ts`,
repository: { full_name: "org/repo", archived: false },
text_matches: [],
});
let searchPage = 0;
globalThis.fetch = (async (url: string | URL | Request) => {
const urlStr = url.toString();
Expand All @@ -195,8 +196,8 @@ describe("fetchAllResults", () => {
searchPage++;
const items =
searchPage === 1
? Array.from({ length: 2 }, (_, i) => makeItem(i))
: Array.from({ length: 1 }, (_, i) => makeItem(2 + i));
? Array.from({ length: 2 }, (_, i) => makeFetchItem(i))
: Array.from({ length: 1 }, (_, i) => makeFetchItem(2 + i));
return new Response(JSON.stringify({ items, total_count: 3 }), {
status: 200,
headers: { "content-type": "application/json" },
Expand Down