diff --git a/src/tools/cards.test.ts b/src/tools/cards.test.ts index 4772daf..d82c468 100644 --- a/src/tools/cards.test.ts +++ b/src/tools/cards.test.ts @@ -385,6 +385,125 @@ describe("getCardTool", () => { ).rejects.toThrow("[NOT_FOUND] Card nonexistent_id"); }); + test("should include steps array when present", async () => { + setTestAccount("897362094"); + const cardWithSteps = { + ...mockCard, + steps: [ + { id: "step_1", content: "Review PR", completed: true }, + { id: "step_2", content: "Run tests", completed: false }, + ], + }; + server.use( + http.get(`${BASE_URL}/:accountSlug/cards/:cardIdentifier`, () => { + return HttpResponse.json(cardWithSteps); + }), + ); + + const result = await getCardTool.execute({ card_number: 42 }); + const parsed = JSON.parse(result); + expect(parsed.steps).toHaveLength(2); + expect(parsed.steps[0]).toEqual({ + id: "step_1", + content: "Review PR", + completed: true, + }); + }); + + test("should default steps to empty array when absent", async () => { + setTestAccount("897362094"); + server.use( + http.get(`${BASE_URL}/:accountSlug/cards/:cardIdentifier`, () => { + return HttpResponse.json(mockCard); + }), + ); + + const result = await getCardTool.execute({ card_number: 42 }); + const parsed = JSON.parse(result); + expect(parsed.steps).toEqual([]); + }); + + test("should include image_url when present", async () => { + setTestAccount("897362094"); + const imageCard = { ...mockCard, image_url: "https://example.com/img.png" }; + server.use( + http.get(`${BASE_URL}/:accountSlug/cards/:cardIdentifier`, () => { + return HttpResponse.json(imageCard); + }), + ); + + const result = await getCardTool.execute({ card_number: 42 }); + const parsed = JSON.parse(result); + expect(parsed.image_url).toBe("https://example.com/img.png"); + }); + + test("should default image_url to null when absent", async () => { + setTestAccount("897362094"); + server.use( + http.get(`${BASE_URL}/:accountSlug/cards/:cardIdentifier`, () => { + return HttpResponse.json(mockCard); + }), + ); + + const result = await getCardTool.execute({ card_number: 42 }); + const parsed = JSON.parse(result); + expect(parsed.image_url).toBeNull(); + }); + + test("should include golden field in response", async () => { + setTestAccount("897362094"); + const goldenCard = { ...mockCard, golden: true }; + server.use( + http.get(`${BASE_URL}/:accountSlug/cards/:cardIdentifier`, () => { + return HttpResponse.json(goldenCard); + }), + ); + + const result = await getCardTool.execute({ card_number: 42 }); + const parsed = JSON.parse(result); + expect(parsed.golden).toBe(true); + }); + + test("should include last_active_at when present", async () => { + setTestAccount("897362094"); + const activeCard = { ...mockCard, last_active_at: "2024-01-20T00:00:00Z" }; + server.use( + http.get(`${BASE_URL}/:accountSlug/cards/:cardIdentifier`, () => { + return HttpResponse.json(activeCard); + }), + ); + + const result = await getCardTool.execute({ card_number: 42 }); + const parsed = JSON.parse(result); + expect(parsed.last_active_at).toBe("2024-01-20T00:00:00Z"); + }); + + test("should default last_active_at to null when absent", async () => { + setTestAccount("897362094"); + server.use( + http.get(`${BASE_URL}/:accountSlug/cards/:cardIdentifier`, () => { + return HttpResponse.json(mockCard); + }), + ); + + const result = await getCardTool.execute({ card_number: 42 }); + const parsed = JSON.parse(result); + expect(parsed.last_active_at).toBeNull(); + }); + + test("should default golden to false when absent", async () => { + setTestAccount("897362094"); + server.use( + http.get(`${BASE_URL}/:accountSlug/cards/:cardIdentifier`, () => { + return HttpResponse.json(mockCard); + }), + ); + + const result = await getCardTool.execute({ card_number: 42 }); + const parsed = JSON.parse(result); + expect(parsed.golden).toBe(false); + }); + describe("schema validation", () => { test("should use strict schema that rejects unknown keys", () => { const result = getCardTool.parameters.safeParse({ diff --git a/src/tools/cards.ts b/src/tools/cards.ts index 23ebe57..66eefc3 100644 --- a/src/tools/cards.ts +++ b/src/tools/cards.ts @@ -31,6 +31,10 @@ function formatCard(card: Card): string { created_at: card.created_at, updated_at: card.updated_at, closed_at: card.closed_at, + golden: card.golden ?? false, + last_active_at: card.last_active_at ?? null, + image_url: card.image_url ?? null, + steps: card.steps ?? [], }, null, 2,