Skip to main content
Glama
getTranscripts.test.ts2.22 kB
import { GetTranscriptsTool } from "../getTranscripts"; import type { TranscriptService } from "../../../services/transcript.service"; import { IServiceContainer } from "../../../container"; jest.mock("../../../services/transcript.service"); describe("GetTranscriptsTool", () => { let mockTranscriptService: jest.Mocked<TranscriptService>; let tool: GetTranscriptsTool; beforeEach(() => { mockTranscriptService = { getTranscriptSegments: jest.fn(), } as unknown as jest.Mocked<TranscriptService>; const container = { transcriptService: mockTranscriptService, } as unknown as IServiceContainer; tool = new GetTranscriptsTool(container); jest.clearAllMocks(); }); it("should be defined", () => { expect(tool).toBeDefined(); expect(tool.name).toBe("getTranscripts"); }); it("should return a successful result with the correct content", async () => { const mockTranscript = { intro: "Hello", outro: "World" }; mockTranscriptService.getTranscriptSegments.mockResolvedValue( mockTranscript as any ); const params = { videoIds: ["1"] }; const result = await tool.execute(params); expect(result.success).toBe(true); if (!result.success || !result.content) throw new Error("Test failed: success true but no content"); const returnedData = JSON.parse(result.content[0].text as string); expect(returnedData).toEqual({ "1": mockTranscript }); }); it("should return an error if transcriptService.getTranscriptSegments throws an error", async () => { mockTranscriptService.getTranscriptSegments.mockRejectedValue( new Error("Transcript not available") ); const params = { videoIds: ["1"] }; const result = await tool.execute(params); expect(result.isError).toBe(true); expect(result.content[0].text).toContain("Transcript not available"); }); it("should return a Zod validation error for invalid parameters", async () => { const invalidParams = { videoIds: [""] }; // videoId cannot be empty const result = await tool.execute(invalidParams); expect(result.isError).toBe(true); expect(result.content[0].text).toContain("Video ID cannot be empty"); }); });

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/kirbah/mcp-youtube'

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