mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 09:07:39 +00:00
test(actions): table-drive discord forwarding cases
This commit is contained in:
@@ -190,168 +190,137 @@ describe("discord message actions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("handleDiscordMessageAction", () => {
|
describe("handleDiscordMessageAction", () => {
|
||||||
it("forwards context accountId for send", async () => {
|
const embeds = [{ title: "Legacy", description: "Use components v2." }];
|
||||||
await handleDiscordMessageAction({
|
const forwardingCases = [
|
||||||
action: "send",
|
{
|
||||||
params: {
|
name: "forwards context accountId for send",
|
||||||
to: "channel:123",
|
input: {
|
||||||
message: "hi",
|
action: "send" as const,
|
||||||
|
params: { to: "channel:123", message: "hi" },
|
||||||
|
accountId: "ops",
|
||||||
},
|
},
|
||||||
cfg: {} as OpenClawConfig,
|
expected: {
|
||||||
accountId: "ops",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(handleDiscordAction).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
action: "sendMessage",
|
action: "sendMessage",
|
||||||
accountId: "ops",
|
accountId: "ops",
|
||||||
to: "channel:123",
|
to: "channel:123",
|
||||||
content: "hi",
|
content: "hi",
|
||||||
}),
|
|
||||||
expect.any(Object),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("forwards legacy embeds for send", async () => {
|
|
||||||
const embeds = [{ title: "Legacy", description: "Use components v2." }];
|
|
||||||
|
|
||||||
await handleDiscordMessageAction({
|
|
||||||
action: "send",
|
|
||||||
params: {
|
|
||||||
to: "channel:123",
|
|
||||||
message: "hi",
|
|
||||||
embeds,
|
|
||||||
},
|
},
|
||||||
cfg: {} as OpenClawConfig,
|
},
|
||||||
});
|
{
|
||||||
|
name: "forwards legacy embeds for send",
|
||||||
expect(handleDiscordAction).toHaveBeenCalledWith(
|
input: {
|
||||||
expect.objectContaining({
|
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),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("falls back to params accountId when context missing", async () => {
|
|
||||||
await handleDiscordMessageAction({
|
|
||||||
action: "poll",
|
|
||||||
params: {
|
|
||||||
to: "channel:123",
|
|
||||||
pollQuestion: "Ready?",
|
|
||||||
pollOption: ["Yes", "No"],
|
|
||||||
accountId: "marve",
|
|
||||||
},
|
},
|
||||||
cfg: {} as OpenClawConfig,
|
},
|
||||||
});
|
{
|
||||||
|
name: "falls back to params accountId when context missing",
|
||||||
expect(handleDiscordAction).toHaveBeenCalledWith(
|
input: {
|
||||||
expect.objectContaining({
|
action: "poll" as const,
|
||||||
|
params: {
|
||||||
|
to: "channel:123",
|
||||||
|
pollQuestion: "Ready?",
|
||||||
|
pollOption: ["Yes", "No"],
|
||||||
|
accountId: "marve",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: {
|
||||||
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,
|
},
|
||||||
accountId: "ops",
|
{
|
||||||
});
|
name: "forwards accountId for thread replies",
|
||||||
|
input: {
|
||||||
expect(handleDiscordAction).toHaveBeenCalledWith(
|
action: "thread-reply" as const,
|
||||||
expect.objectContaining({
|
params: { channelId: "123", message: "hi" },
|
||||||
|
accountId: "ops",
|
||||||
|
},
|
||||||
|
expected: {
|
||||||
action: "threadReply",
|
action: "threadReply",
|
||||||
accountId: "ops",
|
accountId: "ops",
|
||||||
channelId: "123",
|
channelId: "123",
|
||||||
content: "hi",
|
content: "hi",
|
||||||
}),
|
|
||||||
expect.any(Object),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("accepts threadId for thread replies (tool compatibility)", async () => {
|
|
||||||
await handleDiscordMessageAction({
|
|
||||||
action: "thread-reply",
|
|
||||||
params: {
|
|
||||||
// The `message` tool uses `threadId`.
|
|
||||||
threadId: "999",
|
|
||||||
// Include a conflicting channelId to ensure threadId takes precedence.
|
|
||||||
channelId: "123",
|
|
||||||
message: "hi",
|
|
||||||
},
|
},
|
||||||
cfg: {} as OpenClawConfig,
|
},
|
||||||
accountId: "ops",
|
{
|
||||||
});
|
name: "accepts threadId for thread replies (tool compatibility)",
|
||||||
|
input: {
|
||||||
expect(handleDiscordAction).toHaveBeenCalledWith(
|
action: "thread-reply" as const,
|
||||||
expect.objectContaining({
|
params: {
|
||||||
|
threadId: "999",
|
||||||
|
channelId: "123",
|
||||||
|
message: "hi",
|
||||||
|
},
|
||||||
|
accountId: "ops",
|
||||||
|
},
|
||||||
|
expected: {
|
||||||
action: "threadReply",
|
action: "threadReply",
|
||||||
accountId: "ops",
|
accountId: "ops",
|
||||||
channelId: "999",
|
channelId: "999",
|
||||||
content: "hi",
|
content: "hi",
|
||||||
}),
|
|
||||||
expect.any(Object),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("forwards thread-create message as content", async () => {
|
|
||||||
await handleDiscordMessageAction({
|
|
||||||
action: "thread-create",
|
|
||||||
params: {
|
|
||||||
to: "channel:123456789",
|
|
||||||
threadName: "Forum thread",
|
|
||||||
message: "Initial forum post body",
|
|
||||||
},
|
},
|
||||||
cfg: {} as OpenClawConfig,
|
},
|
||||||
});
|
{
|
||||||
|
name: "forwards thread-create message as content",
|
||||||
expect(handleDiscordAction).toHaveBeenCalledWith(
|
input: {
|
||||||
expect.objectContaining({
|
action: "thread-create" as const,
|
||||||
|
params: {
|
||||||
|
to: "channel:123456789",
|
||||||
|
threadName: "Forum thread",
|
||||||
|
message: "Initial forum post body",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: {
|
||||||
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),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("forwards thread edit fields for channel-edit", async () => {
|
|
||||||
await handleDiscordMessageAction({
|
|
||||||
action: "channel-edit",
|
|
||||||
params: {
|
|
||||||
channelId: "123456789",
|
|
||||||
archived: true,
|
|
||||||
locked: false,
|
|
||||||
autoArchiveDuration: 1440,
|
|
||||||
},
|
},
|
||||||
cfg: {} as OpenClawConfig,
|
},
|
||||||
});
|
{
|
||||||
|
name: "forwards thread edit fields for channel-edit",
|
||||||
expect(handleDiscordAction).toHaveBeenCalledWith(
|
input: {
|
||||||
expect.objectContaining({
|
action: "channel-edit" as const,
|
||||||
|
params: {
|
||||||
|
channelId: "123456789",
|
||||||
|
archived: true,
|
||||||
|
locked: false,
|
||||||
|
autoArchiveDuration: 1440,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: {
|
||||||
action: "channelEdit",
|
action: "channelEdit",
|
||||||
channelId: "123456789",
|
channelId: "123456789",
|
||||||
archived: true,
|
archived: true,
|
||||||
locked: false,
|
locked: false,
|
||||||
autoArchiveDuration: 1440,
|
autoArchiveDuration: 1440,
|
||||||
}),
|
},
|
||||||
expect.any(Object),
|
},
|
||||||
);
|
] 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),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
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({
|
||||||
|
|||||||
Reference in New Issue
Block a user