test(actions): table-drive discord forwarding cases

This commit is contained in:
Peter Steinberger
2026-02-21 23:11:56 +00:00
parent 95dab6e019
commit 8cdb184f10

View File

@@ -190,168 +190,137 @@ describe("discord message actions", () => {
}); });
describe("handleDiscordMessageAction", () => { describe("handleDiscordMessageAction", () => {
it("forwards context accountId for send", async () => {
await handleDiscordMessageAction({
action: "send",
params: {
to: "channel:123",
message: "hi",
},
cfg: {} as OpenClawConfig,
accountId: "ops",
});
expect(handleDiscordAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "sendMessage",
accountId: "ops",
to: "channel:123",
content: "hi",
}),
expect.any(Object),
);
});
it("forwards legacy embeds for send", async () => {
const embeds = [{ title: "Legacy", description: "Use components v2." }]; const embeds = [{ title: "Legacy", description: "Use components v2." }];
const forwardingCases = [
await handleDiscordMessageAction({ {
action: "send", name: "forwards context accountId for send",
params: { input: {
to: "channel:123", action: "send" as const,
message: "hi", params: { to: "channel:123", message: "hi" },
embeds, accountId: "ops",
}, },
cfg: {} as OpenClawConfig, expected: {
}); action: "sendMessage",
accountId: "ops",
expect(handleDiscordAction).toHaveBeenCalledWith( to: "channel:123",
expect.objectContaining({ content: "hi",
},
},
{
name: "forwards legacy embeds for send",
input: {
action: "send" as const,
params: { to: "channel:123", message: "hi", embeds },
},
expected: {
action: "sendMessage", action: "sendMessage",
to: "channel:123", to: "channel:123",
content: "hi", content: "hi",
embeds, embeds,
}), },
expect.any(Object), },
); {
}); name: "falls back to params accountId when context missing",
input: {
it("falls back to params accountId when context missing", async () => { action: "poll" as const,
await handleDiscordMessageAction({
action: "poll",
params: { params: {
to: "channel:123", to: "channel:123",
pollQuestion: "Ready?", pollQuestion: "Ready?",
pollOption: ["Yes", "No"], pollOption: ["Yes", "No"],
accountId: "marve", accountId: "marve",
}, },
cfg: {} as OpenClawConfig, },
}); expected: {
expect(handleDiscordAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "poll", action: "poll",
accountId: "marve", accountId: "marve",
to: "channel:123", to: "channel:123",
question: "Ready?", question: "Ready?",
answers: ["Yes", "No"], answers: ["Yes", "No"],
}),
expect.any(Object),
);
});
it("forwards accountId for thread replies", async () => {
await handleDiscordMessageAction({
action: "thread-reply",
params: {
channelId: "123",
message: "hi",
}, },
cfg: {} as OpenClawConfig, },
{
name: "forwards accountId for thread replies",
input: {
action: "thread-reply" as const,
params: { channelId: "123", message: "hi" },
accountId: "ops", accountId: "ops",
}); },
expected: {
expect(handleDiscordAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "threadReply", action: "threadReply",
accountId: "ops", accountId: "ops",
channelId: "123", channelId: "123",
content: "hi", content: "hi",
}), },
expect.any(Object), },
); {
}); name: "accepts threadId for thread replies (tool compatibility)",
input: {
it("accepts threadId for thread replies (tool compatibility)", async () => { action: "thread-reply" as const,
await handleDiscordMessageAction({
action: "thread-reply",
params: { params: {
// The `message` tool uses `threadId`.
threadId: "999", threadId: "999",
// Include a conflicting channelId to ensure threadId takes precedence.
channelId: "123", channelId: "123",
message: "hi", message: "hi",
}, },
cfg: {} as OpenClawConfig,
accountId: "ops", accountId: "ops",
}); },
expected: {
expect(handleDiscordAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "threadReply", action: "threadReply",
accountId: "ops", accountId: "ops",
channelId: "999", channelId: "999",
content: "hi", content: "hi",
}), },
expect.any(Object), },
); {
}); name: "forwards thread-create message as content",
input: {
it("forwards thread-create message as content", async () => { action: "thread-create" as const,
await handleDiscordMessageAction({
action: "thread-create",
params: { params: {
to: "channel:123456789", to: "channel:123456789",
threadName: "Forum thread", threadName: "Forum thread",
message: "Initial forum post body", message: "Initial forum post body",
}, },
cfg: {} as OpenClawConfig, },
}); expected: {
expect(handleDiscordAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "threadCreate", action: "threadCreate",
channelId: "123456789", channelId: "123456789",
name: "Forum thread", name: "Forum thread",
content: "Initial forum post body", content: "Initial forum post body",
}), },
expect.any(Object), },
); {
}); name: "forwards thread edit fields for channel-edit",
input: {
it("forwards thread edit fields for channel-edit", async () => { action: "channel-edit" as const,
await handleDiscordMessageAction({
action: "channel-edit",
params: { params: {
channelId: "123456789", channelId: "123456789",
archived: true, archived: true,
locked: false, locked: false,
autoArchiveDuration: 1440, autoArchiveDuration: 1440,
}, },
cfg: {} as OpenClawConfig, },
}); expected: {
expect(handleDiscordAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "channelEdit", action: "channelEdit",
channelId: "123456789", channelId: "123456789",
archived: true, archived: true,
locked: false, locked: false,
autoArchiveDuration: 1440, autoArchiveDuration: 1440,
}), },
},
] as const;
for (const testCase of forwardingCases) {
it(testCase.name, async () => {
await handleDiscordMessageAction({
...testCase.input,
cfg: {} as OpenClawConfig,
});
expect(handleDiscordAction).toHaveBeenCalledWith(
expect.objectContaining(testCase.expected),
expect.any(Object), expect.any(Object),
); );
}); });
}
it("uses trusted requesterSenderId for moderation and ignores params senderUserId", async () => { it("uses trusted requesterSenderId for moderation and ignores params senderUserId", async () => {
await handleDiscordMessageAction({ await handleDiscordMessageAction({