|
| 1 | +import { describe, expect, it } from "@effect/vitest"; |
| 2 | +import type { IntegrationPlugin } from "@executor-js/sdk/client"; |
| 3 | + |
| 4 | +import { |
| 5 | + availableCatalogKinds, |
| 6 | + filterCatalogEntries, |
| 7 | + parseCatalogSearch, |
| 8 | + pickConnectTarget, |
| 9 | + presetDomains, |
| 10 | +} from "./integrations-sh-catalog"; |
| 11 | + |
| 12 | +const plugin = (key: string, presets: IntegrationPlugin["presets"]): IntegrationPlugin => ({ |
| 13 | + key, |
| 14 | + label: key, |
| 15 | + add: () => null, |
| 16 | + presets, |
| 17 | +}); |
| 18 | + |
| 19 | +describe("parseCatalogSearch", () => { |
| 20 | + it("keeps connectable kinds and drops CLI-only entries", () => { |
| 21 | + const entries = parseCatalogSearch({ |
| 22 | + results: [ |
| 23 | + { domain: "linear.app", description: "Issues", kinds: ["mcp", "cli"] }, |
| 24 | + { domain: "cli-only.dev", description: "A CLI", kinds: ["cli"] }, |
| 25 | + ], |
| 26 | + }); |
| 27 | + expect(entries).toEqual([{ domain: "linear.app", description: "Issues", kinds: ["mcp"] }]); |
| 28 | + }); |
| 29 | + |
| 30 | + it("returns nothing for a malformed payload", () => { |
| 31 | + expect(parseCatalogSearch({ nope: true })).toEqual([]); |
| 32 | + expect(parseCatalogSearch(undefined)).toEqual([]); |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +describe("pickConnectTarget", () => { |
| 37 | + const payload = { |
| 38 | + surfaces: [ |
| 39 | + { type: "graphql", url: "https://api.linear.app/graphql", slug: "linear-graphql-api" }, |
| 40 | + { type: "mcp", url: "https://mcp.linear.app/mcp", slug: "linear" }, |
| 41 | + { type: "http", spec: "https://example.com/openapi.json", slug: "example-rest" }, |
| 42 | + { type: "cli", slug: "linear-cli" }, |
| 43 | + ], |
| 44 | + }; |
| 45 | + |
| 46 | + it("resolves the MCP endpoint for the mcp kind", () => { |
| 47 | + expect(pickConnectTarget(payload, "mcp")).toEqual({ |
| 48 | + kind: "mcp", |
| 49 | + url: "https://mcp.linear.app/mcp", |
| 50 | + slug: "linear", |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + it("resolves the spec URL (not the base URL) for the openapi kind", () => { |
| 55 | + expect(pickConnectTarget(payload, "openapi")).toEqual({ |
| 56 | + kind: "openapi", |
| 57 | + url: "https://example.com/openapi.json", |
| 58 | + slug: "example-rest", |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + it("resolves the GraphQL endpoint for the graphql kind", () => { |
| 63 | + expect(pickConnectTarget(payload, "graphql")).toEqual({ |
| 64 | + kind: "graphql", |
| 65 | + url: "https://api.linear.app/graphql", |
| 66 | + slug: "linear-graphql-api", |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + it("skips specless http surfaces for the openapi kind", () => { |
| 71 | + const specless = { surfaces: [{ type: "http", url: "https://api.example.com" }] }; |
| 72 | + expect(pickConnectTarget(specless, "openapi")).toBeUndefined(); |
| 73 | + }); |
| 74 | + |
| 75 | + it("returns undefined for a malformed document", () => { |
| 76 | + expect(pickConnectTarget({ surfaces: "nope" }, "mcp")).toBeUndefined(); |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
| 80 | +describe("preset filtering", () => { |
| 81 | + const plugins: IntegrationPlugin[] = [ |
| 82 | + plugin("mcp", [ |
| 83 | + { |
| 84 | + id: "linear", |
| 85 | + name: "Linear", |
| 86 | + summary: "Issues", |
| 87 | + icon: "https://integrations.sh/logo/linear.app", |
| 88 | + }, |
| 89 | + ]), |
| 90 | + plugin("openapi", [ |
| 91 | + { |
| 92 | + id: "stripe", |
| 93 | + name: "Stripe", |
| 94 | + summary: "Payments", |
| 95 | + url: "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json", |
| 96 | + icon: "https://integrations.sh/logo/stripe.com", |
| 97 | + }, |
| 98 | + ]), |
| 99 | + ]; |
| 100 | + |
| 101 | + it("derives preset domains from logo-proxy icons and preset URLs", () => { |
| 102 | + const domains = presetDomains(plugins); |
| 103 | + expect(domains.has("linear.app")).toBe(true); |
| 104 | + expect(domains.has("stripe.com")).toBe(true); |
| 105 | + }); |
| 106 | + |
| 107 | + it("lists only kinds a loaded plugin can add", () => { |
| 108 | + expect(availableCatalogKinds(plugins)).toEqual(["mcp", "openapi"]); |
| 109 | + }); |
| 110 | + |
| 111 | + it("hides preset-covered domains and unaddable kinds", () => { |
| 112 | + const entries = filterCatalogEntries( |
| 113 | + [ |
| 114 | + { domain: "linear.app", description: "Issues", kinds: ["mcp"] }, |
| 115 | + { domain: "shopify.dev", description: "Commerce", kinds: ["graphql"] }, |
| 116 | + { domain: "notion.com", description: "Notes", kinds: ["mcp", "graphql"] }, |
| 117 | + ], |
| 118 | + { excludeDomains: presetDomains(plugins), availableKinds: availableCatalogKinds(plugins) }, |
| 119 | + ); |
| 120 | + expect(entries).toEqual([{ domain: "notion.com", description: "Notes", kinds: ["mcp"] }]); |
| 121 | + }); |
| 122 | +}); |
0 commit comments