Skip to content
Merged
Show file tree
Hide file tree
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
119 changes: 119 additions & 0 deletions src/tools/cards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 4 additions & 0 deletions src/tools/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down