|
| 1 | +import assert from "node:assert"; |
| 2 | +import * as fs from "node:fs"; |
| 3 | +import * as path from "node:path"; |
| 4 | +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; |
| 5 | +import { registerSkillResource } from "../src/resources/paystack-skill.js"; |
| 6 | + |
| 7 | +const SKILL_CONTENT = fs.readFileSync( |
| 8 | + path.join(__dirname, "..", "src", "data", "paystack-skill.md"), |
| 9 | + "utf-8" |
| 10 | +); |
| 11 | + |
| 12 | +describe("PaystackSkillResource", () => { |
| 13 | + let resourceHandler: any; |
| 14 | + let registeredName: string; |
| 15 | + let registeredUri: string; |
| 16 | + let registeredMetadata: any; |
| 17 | + |
| 18 | + before(() => { |
| 19 | + const server = { |
| 20 | + registerResource: (name: string, uri: string, metadata: any, handler: any) => { |
| 21 | + registeredName = name; |
| 22 | + registeredUri = uri; |
| 23 | + registeredMetadata = metadata; |
| 24 | + resourceHandler = handler; |
| 25 | + } |
| 26 | + } as any; |
| 27 | + |
| 28 | + registerSkillResource(server, SKILL_CONTENT); |
| 29 | + }); |
| 30 | + |
| 31 | + describe("Registration", () => { |
| 32 | + it("should register with the correct name", () => { |
| 33 | + assert.strictEqual(registeredName, "paystack_skill"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should register with the correct URI", () => { |
| 37 | + assert.strictEqual(registeredUri, "paystack://skill"); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should set mimeType to text/markdown", () => { |
| 41 | + assert.strictEqual(registeredMetadata.mimeType, "text/markdown"); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should have a description", () => { |
| 45 | + assert.ok(registeredMetadata.description); |
| 46 | + assert.ok(registeredMetadata.description.length > 0); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe("Content", () => { |
| 51 | + let content: string; |
| 52 | + |
| 53 | + before(async () => { |
| 54 | + const mockUri = new URL("paystack://skill"); |
| 55 | + const result = await resourceHandler(mockUri); |
| 56 | + content = result.contents[0].text; |
| 57 | + }); |
| 58 | + |
| 59 | + it("should return text/markdown mimeType in response", async () => { |
| 60 | + const mockUri = new URL("paystack://skill"); |
| 61 | + const result = await resourceHandler(mockUri); |
| 62 | + assert.strictEqual(result.contents[0].mimeType, "text/markdown"); |
| 63 | + }); |
| 64 | + |
| 65 | + it("should include documentation index section", () => { |
| 66 | + assert.ok(content.includes("## Documentation Index")); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should include code snippets section", () => { |
| 70 | + assert.ok(content.includes("## Code Snippets")); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should include payment channels by country section", () => { |
| 74 | + assert.ok(content.includes("## Payment Channels by Country")); |
| 75 | + }); |
| 76 | + |
| 77 | + it("should include links to Paystack docs", () => { |
| 78 | + assert.ok(content.includes("https://paystack.com/docs/llms.txt")); |
| 79 | + }); |
| 80 | + |
| 81 | + it("should include snippet repo URL pattern for JS", () => { |
| 82 | + assert.ok(content.includes("PaystackOSS/doc-code-snippets")); |
| 83 | + assert.ok(content.includes("index.js")); |
| 84 | + }); |
| 85 | + |
| 86 | + it("should include snippet repo URL pattern for Shell", () => { |
| 87 | + assert.ok(content.includes("index.sh")); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should include all supported countries", () => { |
| 91 | + assert.ok(content.includes("Nigeria")); |
| 92 | + assert.ok(content.includes("Ghana")); |
| 93 | + assert.ok(content.includes("South Africa")); |
| 94 | + assert.ok(content.includes("Kenya")); |
| 95 | + assert.ok(content.includes("Côte d'Ivoire")); |
| 96 | + }); |
| 97 | + }); |
| 98 | +}); |
| 99 | + |
| 100 | +describe("ServerInstructions", () => { |
| 101 | + it("should pass instructions to the McpServer constructor", async () => { |
| 102 | + // Dynamically import server module to verify instructions are set |
| 103 | + // We check the source directly since McpServer options are private |
| 104 | + const fs = await import("node:fs"); |
| 105 | + const path = await import("node:path"); |
| 106 | + const serverSource = fs.readFileSync( |
| 107 | + path.join(__dirname, "../src/server.ts"), |
| 108 | + "utf-8" |
| 109 | + ); |
| 110 | + |
| 111 | + assert.ok( |
| 112 | + serverSource.includes("instructions:"), |
| 113 | + "server.ts should pass instructions to McpServer" |
| 114 | + ); |
| 115 | + assert.ok( |
| 116 | + serverSource.includes("smallest currency unit"), |
| 117 | + "instructions should include currency unit rule" |
| 118 | + ); |
| 119 | + assert.ok( |
| 120 | + serverSource.includes("get_paystack_operation"), |
| 121 | + "instructions should reference the operation tool" |
| 122 | + ); |
| 123 | + assert.ok( |
| 124 | + serverSource.includes("do not invent"), |
| 125 | + "instructions should include anti-hallucination directive" |
| 126 | + ); |
| 127 | + }); |
| 128 | +}); |
0 commit comments