/**
* Contract Tests: get-item tool
*
* Tests input validation and output schema compliance for the get-item tool.
* These tests verify the tool's contract without making real API calls.
*/
import { describe, expect, it } from "vitest";
import { GetItemInputSchema, getItemHandler, getItemTool } from "../../src/tools/get-item.js";
describe("get-item tool contract", () => {
describe("Input Validation", () => {
it("should accept valid itemId", () => {
const input = { itemId: "123456" };
const result = GetItemInputSchema.safeParse(input);
expect(result.success).toBe(true);
});
it("should accept numeric string itemId", () => {
const input = { itemId: "38456789" };
const result = GetItemInputSchema.safeParse(input);
expect(result.success).toBe(true);
});
it("should reject empty itemId", () => {
const input = { itemId: "" };
const result = GetItemInputSchema.safeParse(input);
expect(result.success).toBe(false);
});
it("should reject missing itemId", () => {
const input = {};
const result = GetItemInputSchema.safeParse(input);
expect(result.success).toBe(false);
});
it("should reject null itemId", () => {
const input = { itemId: null };
const result = GetItemInputSchema.safeParse(input);
expect(result.success).toBe(false);
});
it("should reject undefined itemId", () => {
const input = { itemId: undefined };
const result = GetItemInputSchema.safeParse(input);
expect(result.success).toBe(false);
});
});
describe("Tool Metadata", () => {
it("should have correct tool name", () => {
expect(getItemTool.name).toBe("get-item");
});
it("should have comprehensive description", () => {
expect(getItemTool.description).toBeTruthy();
expect(getItemTool.description.length).toBeGreaterThan(100);
expect(getItemTool.description).toContain("nested comment tree");
});
it("should have properly defined input schema", () => {
expect(getItemTool.inputSchema).toBeDefined();
expect(getItemTool.inputSchema.type).toBe("object");
expect(getItemTool.inputSchema.properties).toHaveProperty("itemId");
});
it("should require itemId parameter", () => {
expect(getItemTool.inputSchema.required).toContain("itemId");
});
});
describe("Output Schema", () => {
it("should return error for empty itemId", async () => {
const result = await getItemHandler({ itemId: "" });
expect(result.isError).toBe(true);
expect(result.content).toHaveLength(1);
expect(result.content[0].type).toBe("text");
});
it("should return error for missing itemId", async () => {
const result = await getItemHandler({});
expect(result.isError).toBe(true);
const content = result.content[0];
if (content.type === "text") {
expect(content.text).toContain("itemId");
}
});
});
});