Skip to main content
Glama
by wei
get-front-page.test.ts3.96 kB
/** * Contract Tests: get-front-page tool * * Tests input validation and output schema compliance for the get-front-page tool. * These tests verify the tool's contract without making real API calls. */ import { describe, expect, it } from "vitest"; import { GetFrontPageInputSchema, getFrontPageHandler, getFrontPageTool, } from "../../src/tools/get-front-page.js"; describe("get-front-page tool contract", () => { describe("Input Validation", () => { it("should accept valid input with no parameters", () => { const input = {}; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(true); }); it("should accept valid input with all parameters", () => { const input = { page: 0, hitsPerPage: 30, }; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(true); }); it("should reject negative page number", () => { const input = { page: -1 }; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(false); }); it("should accept page 0 (first page)", () => { const input = { page: 0 }; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(true); }); it("should reject hitsPerPage less than 1", () => { const input = { hitsPerPage: 0 }; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(false); }); it("should reject hitsPerPage greater than 1000", () => { const input = { hitsPerPage: 1001 }; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(false); }); it("should accept hitsPerPage within valid range (1-1000)", () => { const input = { hitsPerPage: 50 }; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(true); }); it("should apply default values for optional parameters", () => { const input = {}; const result = GetFrontPageInputSchema.parse(input); expect(result.page).toBe(0); expect(result.hitsPerPage).toBe(30); }); it("should reject non-integer page number", () => { const input = { page: 1.5 }; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(false); }); it("should reject non-integer hitsPerPage", () => { const input = { hitsPerPage: 20.5 }; const result = GetFrontPageInputSchema.safeParse(input); expect(result.success).toBe(false); }); }); describe("Tool Metadata", () => { it("should have correct tool name", () => { expect(getFrontPageTool.name).toBe("get-front-page"); }); it("should have comprehensive description", () => { expect(getFrontPageTool.description).toBeTruthy(); expect(getFrontPageTool.description.length).toBeGreaterThan(50); }); it("should have properly defined input schema", () => { expect(getFrontPageTool.inputSchema).toBeDefined(); expect(getFrontPageTool.inputSchema.type).toBe("object"); expect(getFrontPageTool.inputSchema.properties).toHaveProperty("page"); expect(getFrontPageTool.inputSchema.properties).toHaveProperty("hitsPerPage"); }); it("should not require any parameters", () => { // All parameters should be optional with defaults const result = GetFrontPageInputSchema.safeParse({}); expect(result.success).toBe(true); }); }); describe("Output Schema", () => { it("should return error for invalid page number", async () => { const result = await getFrontPageHandler({ page: -1 }); expect(result.isError).toBe(true); expect(result.content).toHaveLength(1); expect(result.content[0].type).toBe("text"); }); it("should return error for invalid hitsPerPage", async () => { const result = await getFrontPageHandler({ hitsPerPage: 2000 }); expect(result.isError).toBe(true); const content = result.content[0]; if (content.type === "text") { expect(content.text).toBeTruthy(); } }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wei/hn-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server