Skip to main content
Glama
data.test.ts2.04 kB
import { describe, it, expect } from "vitest"; import { convertFormatHandler, generateMockDataHandler } from "./data.js"; describe("Data Tools", () => { describe("convertFormatHandler", () => { it("should convert json to csv", () => { const result = convertFormatHandler({ input: '[{"name":"Alice","age":30},{"name":"Bob","age":25}]', from: "json", to: "csv", }); expect(result.content[0].text).toContain("name,age"); expect(result.content[0].text).toContain("Alice,30"); expect(result.content[0].text).toContain("Bob,25"); }); it("should convert simple csv to json", () => { const result = convertFormatHandler({ input: "name,age\nAlice,30", from: "csv", to: "json", }); expect(result.content[0].text).toContain('"name": "Alice"'); expect(result.content[0].text).toContain('"age": "30"'); }); it("should handle invalid input gracefully", () => { const result = convertFormatHandler({ input: "invalid", from: "json", to: "csv", }); // We expect an error message, but not a crash expect(result.isError).toBe(true); expect(result.content[0].text).toContain("Error converting format"); }); }); describe("generateMockDataHandler", () => { it("should generate json data", () => { const result = generateMockDataHandler({ schema: "User", count: 3, format: "json", }); expect(result.content[0].text).toContain("Mock Data (3 items)"); expect(result.content[0].text).toContain("```json"); // Check for names in mock data expect(result.content[0].text).toContain("Alice"); }); it("should generate sql insert", () => { const result = generateMockDataHandler({ schema: "User", count: 1, format: "sql", }); expect(result.content[0].text).toContain("INSERT INTO users"); expect(result.content[0].text).toContain("VALUES"); }); }); });

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/millsydotdev/Code-MCP'

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