2026-03-01 18:45:05 +01:00
|
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
|
import { handleSlackMessageAction } from "./slack-message-actions.js";
|
|
|
|
|
|
2026-03-02 21:31:18 +00:00
|
|
|
function createInvokeSpy() {
|
|
|
|
|
return vi.fn(async (action: Record<string, unknown>) => ({
|
|
|
|
|
ok: true,
|
|
|
|
|
content: action,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-01 18:45:05 +01:00
|
|
|
describe("handleSlackMessageAction", () => {
|
|
|
|
|
it("maps download-file to the internal downloadFile action", async () => {
|
2026-03-02 21:31:18 +00:00
|
|
|
const invoke = createInvokeSpy();
|
2026-03-01 18:45:05 +01:00
|
|
|
|
|
|
|
|
await handleSlackMessageAction({
|
|
|
|
|
providerId: "slack",
|
|
|
|
|
ctx: {
|
|
|
|
|
action: "download-file",
|
|
|
|
|
cfg: {},
|
|
|
|
|
params: {
|
|
|
|
|
channelId: "C1",
|
|
|
|
|
fileId: "F123",
|
2026-03-02 02:23:12 +00:00
|
|
|
threadId: "111.222",
|
2026-03-01 18:45:05 +01:00
|
|
|
},
|
|
|
|
|
} as never,
|
|
|
|
|
invoke: invoke as never,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(invoke).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
action: "downloadFile",
|
|
|
|
|
fileId: "F123",
|
2026-03-02 02:23:12 +00:00
|
|
|
channelId: "C1",
|
|
|
|
|
threadId: "111.222",
|
|
|
|
|
}),
|
|
|
|
|
expect.any(Object),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("maps download-file target aliases to scope fields", async () => {
|
2026-03-02 21:31:18 +00:00
|
|
|
const invoke = createInvokeSpy();
|
2026-03-02 02:23:12 +00:00
|
|
|
|
|
|
|
|
await handleSlackMessageAction({
|
|
|
|
|
providerId: "slack",
|
|
|
|
|
ctx: {
|
|
|
|
|
action: "download-file",
|
|
|
|
|
cfg: {},
|
|
|
|
|
params: {
|
|
|
|
|
to: "channel:C2",
|
|
|
|
|
fileId: "F999",
|
|
|
|
|
replyTo: "333.444",
|
|
|
|
|
},
|
|
|
|
|
} as never,
|
|
|
|
|
invoke: invoke as never,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(invoke).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
action: "downloadFile",
|
|
|
|
|
fileId: "F999",
|
|
|
|
|
channelId: "channel:C2",
|
|
|
|
|
threadId: "333.444",
|
2026-03-01 18:45:05 +01:00
|
|
|
}),
|
|
|
|
|
expect.any(Object),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|