openclaw/extensions/slack/src/targets.test.ts
scoootscooob 8746362f5e
refactor(slack): move Slack channel code to extensions/slack/src/ (#45621)
Move all Slack channel implementation files from src/slack/ to
extensions/slack/src/ and replace originals with shim re-exports.
This follows the extension migration pattern for channel plugins.

- Copy all .ts files to extensions/slack/src/ (preserving directory
  structure: monitor/, http/, monitor/events/, monitor/message-handler/)
- Transform import paths: external src/ imports use relative paths
  back to src/, internal slack imports stay relative within extension
- Replace all src/slack/ files with shim re-exports pointing to
  the extension copies
- Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." so
  the DTS build can follow shim chains into extensions/
- Update write-plugin-sdk-entry-dts.ts re-export path accordingly
- Preserve extensions/slack/index.ts, package.json, openclaw.plugin.json,
  src/channel.ts, src/runtime.ts, src/channel.test.ts (untouched)
2026-03-14 02:47:04 -07:00

64 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { normalizeSlackMessagingTarget } from "../../../src/channels/plugins/normalize/slack.js";
import { parseSlackTarget, resolveSlackChannelId } from "./targets.js";
describe("parseSlackTarget", () => {
it("parses user mentions and prefixes", () => {
const cases = [
{ input: "<@U123>", id: "U123", normalized: "user:u123" },
{ input: "user:U456", id: "U456", normalized: "user:u456" },
{ input: "slack:U789", id: "U789", normalized: "user:u789" },
] as const;
for (const testCase of cases) {
expect(parseSlackTarget(testCase.input), testCase.input).toMatchObject({
kind: "user",
id: testCase.id,
normalized: testCase.normalized,
});
}
});
it("parses channel targets", () => {
const cases = [
{ input: "channel:C123", id: "C123", normalized: "channel:c123" },
{ input: "#C999", id: "C999", normalized: "channel:c999" },
] as const;
for (const testCase of cases) {
expect(parseSlackTarget(testCase.input), testCase.input).toMatchObject({
kind: "channel",
id: testCase.id,
normalized: testCase.normalized,
});
}
});
it("rejects invalid @ and # targets", () => {
const cases = [
{ input: "@bob-1", expectedMessage: /Slack DMs require a user id/ },
{ input: "#general-1", expectedMessage: /Slack channels require a channel id/ },
] as const;
for (const testCase of cases) {
expect(() => parseSlackTarget(testCase.input), testCase.input).toThrow(
testCase.expectedMessage,
);
}
});
});
describe("resolveSlackChannelId", () => {
it("strips channel: prefix and accepts raw ids", () => {
expect(resolveSlackChannelId("channel:C123")).toBe("C123");
expect(resolveSlackChannelId("C123")).toBe("C123");
});
it("rejects user targets", () => {
expect(() => resolveSlackChannelId("user:U123")).toThrow(/channel id is required/i);
});
});
describe("normalizeSlackMessagingTarget", () => {
it("defaults raw ids to channels", () => {
expect(normalizeSlackMessagingTarget("C123")).toBe("channel:c123");
});
});