Skip to content

Commit 15015ff

Browse files
committed
test: add coverage for numeric project ID resolution in resolveProjectBySlug
1 parent 6fcdfd7 commit 15015ff

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

test/commands/event/view.test.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
* in src/commands/event/view.ts
66
*/
77

8-
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
8+
import {
9+
afterEach,
10+
beforeEach,
11+
describe,
12+
expect,
13+
mock,
14+
spyOn,
15+
test,
16+
} from "bun:test";
917
import { parsePositionalArgs } from "../../../src/commands/event/view.js";
1018
import type { ProjectWithOrg } from "../../../src/lib/api-client.js";
1119
// biome-ignore lint/performance/noNamespaceImport: needed for spyOn mocking
@@ -327,4 +335,61 @@ describe("resolveProjectBySlug", () => {
327335
expect(result.project).toBe("web-frontend");
328336
});
329337
});
338+
339+
describe("numeric project ID", () => {
340+
test("uses numeric-ID-specific error when not found", async () => {
341+
findProjectsBySlugSpy.mockResolvedValue([]);
342+
343+
try {
344+
await resolveProjectBySlug("7275560680", HINT);
345+
expect.unreachable("Should have thrown");
346+
} catch (error) {
347+
expect(error).toBeInstanceOf(ContextError);
348+
const message = (error as ContextError).message;
349+
expect(message).toContain('Project "7275560680"');
350+
expect(message).toContain("No project with this ID was found");
351+
}
352+
});
353+
354+
test("writes stderr hint when numeric ID resolves to a different slug", async () => {
355+
findProjectsBySlugSpy.mockResolvedValue([
356+
{
357+
slug: "my-frontend",
358+
orgSlug: "acme",
359+
id: "7275560680",
360+
name: "Frontend",
361+
},
362+
] as ProjectWithOrg[]);
363+
const stderrWrite = mock(() => true);
364+
const stderr = { write: stderrWrite };
365+
366+
const result = await resolveProjectBySlug(
367+
"7275560680",
368+
HINT,
369+
undefined,
370+
stderr
371+
);
372+
373+
expect(result).toEqual({ org: "acme", project: "my-frontend" });
374+
expect(stderrWrite).toHaveBeenCalledTimes(1);
375+
const hint = stderrWrite.mock.calls[0][0] as string;
376+
expect(hint).toContain("7275560680");
377+
expect(hint).toContain("acme/my-frontend");
378+
});
379+
380+
test("does not write hint when stderr is not provided", async () => {
381+
findProjectsBySlugSpy.mockResolvedValue([
382+
{
383+
slug: "my-frontend",
384+
orgSlug: "acme",
385+
id: "7275560680",
386+
name: "Frontend",
387+
},
388+
] as ProjectWithOrg[]);
389+
390+
// Should not throw even without stderr
391+
const result = await resolveProjectBySlug("7275560680", HINT);
392+
expect(result).toEqual({ org: "acme", project: "my-frontend" });
393+
});
394+
});
330395
});

0 commit comments

Comments
 (0)