|
5 | 5 | * in src/commands/event/view.ts |
6 | 6 | */ |
7 | 7 |
|
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"; |
9 | 17 | import { parsePositionalArgs } from "../../../src/commands/event/view.js"; |
10 | 18 | import type { ProjectWithOrg } from "../../../src/lib/api-client.js"; |
11 | 19 | // biome-ignore lint/performance/noNamespaceImport: needed for spyOn mocking |
@@ -327,4 +335,61 @@ describe("resolveProjectBySlug", () => { |
327 | 335 | expect(result.project).toBe("web-frontend"); |
328 | 336 | }); |
329 | 337 | }); |
| 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 | + }); |
330 | 395 | }); |
0 commit comments