| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { CONNECTOR_CATEGORIES, CONNECTORS, connectorPath, connectorView, connectorsFor } from "./connectors.ts"; |
| 5 | import { PROVIDERS } from "./integrations.ts"; |
| 6 | |
| 7 | test("every connector has a unique id, a category and a scope", () => { |
| 8 | const ids = new Set<string>(); |
| 9 | const categories = new Set(CONNECTOR_CATEGORIES.map((category) => category.id)); |
| 10 | for (const connector of CONNECTORS) { |
| 11 | assert.ok(!ids.has(connector.id), `${connector.id} is listed twice`); |
| 12 | ids.add(connector.id); |
| 13 | assert.match(connector.id, /^[a-z0-9-]+$/, connector.id); |
| 14 | assert.ok(categories.has(connector.category), connector.id); |
| 15 | assert.ok(connector.scopes.length > 0, connector.id); |
| 16 | assert.ok(connector.description.length > 0 && !connector.description.includes("\n"), connector.id); |
| 17 | } |
| 18 | }); |
| 19 | |
| 20 | test("every category has connectors, and an available one in each scope it has is set up somewhere", () => { |
| 21 | for (const category of CONNECTOR_CATEGORIES) { |
| 22 | assert.ok(CONNECTORS.some((connector) => connector.category === category.id), category.id); |
| 23 | } |
| 24 | for (const scope of ["workspace", "personal"] as const) { |
| 25 | for (const view of connectorsFor(scope)) { |
| 26 | if (view.status === "available") assert.ok(view.href?.startsWith("/"), `${view.id} (${scope}) has nowhere to set it up`); |
| 27 | else assert.equal(view.href, null, view.id); |
| 28 | } |
| 29 | } |
| 30 | }); |
| 31 | |
| 32 | test("every integration provider is an available connector", () => { |
| 33 | for (const provider of Object.keys(PROVIDERS)) { |
| 34 | const connector = CONNECTORS.find((c) => c.provider === provider); |
| 35 | assert.ok(connector, `${provider} has no connector`); |
| 36 | assert.equal(connector.status, "available", provider); |
| 37 | } |
| 38 | }); |
| 39 | |
| 40 | test("a connector shows its personal side to you", () => { |
| 41 | const github = CONNECTORS.find((c) => c.id === "github")!; |
| 42 | const mine = connectorView(github, "personal")!; |
| 43 | assert.equal(mine.href, "/settings/github"); |
| 44 | assert.ok(mine.capabilities.includes("Signs you in")); |
| 45 | assert.equal(mine.alsoIn, "workspace"); |
| 46 | const linear = CONNECTORS.find((c) => c.id === "linear")!; |
| 47 | assert.equal(connectorView(linear, "workspace")!.status, "available"); |
| 48 | assert.equal(connectorView(linear, "personal")!.status, "soon"); |
| 49 | assert.equal(connectorView(linear, "personal")!.href, null); |
| 50 | const calendar = CONNECTORS.find((c) => c.id === "google-calendar")!; |
| 51 | assert.equal(connectorView(calendar, "workspace"), null); |
| 52 | }); |
| 53 | |
| 54 | test("a setup path names the workspace", () => { |
| 55 | assert.equal(connectorPath("/:workspace/-/integrations/models?add=openai#add", "acme"), "/acme/-/integrations/models?add=openai#add"); |
| 56 | assert.equal(connectorPath("/new/github?workspace=:workspace", "acme"), "/new/github?workspace=acme"); |
| 57 | }); |