Skip to main content
Glama
get.test.ts2.05 kB
/** * Tests for getMemory function helper logic * Tests the pure function patterns used in get.ts */ import { describe, expect, test } from "bun:test"; describe("getMemory", () => { describe("input validation", () => { function isValidId(id: string): boolean { return id.length > 0 && id.startsWith("mem_"); } test("accepts valid memory ID", () => { expect(isValidId("mem_abc123")).toBe(true); }); test("rejects empty ID", () => { expect(isValidId("")).toBe(false); }); test("rejects ID without prefix", () => { expect(isValidId("abc123")).toBe(false); }); test("rejects ID with wrong prefix", () => { expect(isValidId("vec_abc123")).toBe(false); }); }); describe("result handling", () => { interface Memory { id: string; title: string; } function processResult(memory: Memory | null): { found: boolean; memory?: Memory; } { if (memory === null) { return { found: false }; } return { found: true, memory }; } test("returns found true with memory when exists", () => { const memory = { id: "mem_123", title: "Test" }; const result = processResult(memory); expect(result.found).toBe(true); expect(result.memory).toBe(memory); }); test("returns found false when null", () => { const result = processResult(null); expect(result.found).toBe(false); expect(result.memory).toBeUndefined(); }); }); describe("access time update", () => { function shouldUpdateAccessTime(memory: unknown): boolean { return memory !== null && memory !== undefined; } test("should update when memory found", () => { expect(shouldUpdateAccessTime({ id: "mem_123" })).toBe(true); }); test("should not update when null", () => { expect(shouldUpdateAccessTime(null)).toBe(false); }); test("should not update when undefined", () => { expect(shouldUpdateAccessTime(undefined)).toBe(false); }); }); });

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/docleaai/doclea-mcp'

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