import type { ConnectorConnection } from "@tactical-media-broadcast-hub/core"; import { connectorContractTests } from "@tactical-media-broadcast-hub/connector-sdk/testing"; import { createSlackConnector } from "./index.js"; const connection: ConnectorConnection = { id: "conn-slack", workspaceId: "ws-1", provider: "slack", channelId: "C0123456789", credentialId: { kind: "credential-ref", id: "cred-slack" }, fields: { botToken: "xoxb-test-token", teamId: "T0123456789", }, createdAt: new Date(), }; const fetchImpl: typeof fetch = async (input, init): Promise => { const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url; if (url === "https://slack.com/api/auth.test") { if (new Headers(init?.headers).get("authorization") !== "Bearer xoxb-test-token") { return new Response(JSON.stringify({ ok: false, error: "invalid_auth" })); } return new Response(JSON.stringify({ ok: true, team: "AnarchoPoster", team_id: "T0123456789", user: "anarchoposter", user_id: "U0123456789", bot_id: "B0123456789", })); } return new Response(JSON.stringify({ ok: false, error: `unexpected request: ${url}` })); }; connectorContractTests(createSlackConnector({ fetchImpl }), { connection });