mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:01:24 +00:00
test(actions): table-drive discord reaction and permission cases
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { DiscordActionConfig, OpenClawConfig } from "../../config/config.js";
|
import type { DiscordActionConfig, OpenClawConfig } from "../../config/config.js";
|
||||||
import { handleDiscordGuildAction } from "./discord-actions-guild.js";
|
import { handleDiscordGuildAction } from "./discord-actions-guild.js";
|
||||||
import { handleDiscordMessagingAction } from "./discord-actions-messaging.js";
|
import { handleDiscordMessagingAction } from "./discord-actions-messaging.js";
|
||||||
@@ -77,31 +77,37 @@ const channelInfoEnabled = (key: keyof DiscordActionConfig) => key === "channelI
|
|||||||
const moderationEnabled = (key: keyof DiscordActionConfig) => key === "moderation";
|
const moderationEnabled = (key: keyof DiscordActionConfig) => key === "moderation";
|
||||||
|
|
||||||
describe("handleDiscordMessagingAction", () => {
|
describe("handleDiscordMessagingAction", () => {
|
||||||
it("adds reactions", async () => {
|
beforeEach(() => {
|
||||||
await handleDiscordMessagingAction(
|
vi.clearAllMocks();
|
||||||
"react",
|
});
|
||||||
{
|
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
name: "without account",
|
||||||
|
params: {
|
||||||
channelId: "C1",
|
channelId: "C1",
|
||||||
messageId: "M1",
|
messageId: "M1",
|
||||||
emoji: "✅",
|
emoji: "✅",
|
||||||
},
|
},
|
||||||
enableAllActions,
|
expectedOptions: undefined,
|
||||||
);
|
},
|
||||||
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅");
|
{
|
||||||
});
|
name: "with accountId",
|
||||||
|
params: {
|
||||||
it("forwards accountId for reactions", async () => {
|
|
||||||
await handleDiscordMessagingAction(
|
|
||||||
"react",
|
|
||||||
{
|
|
||||||
channelId: "C1",
|
channelId: "C1",
|
||||||
messageId: "M1",
|
messageId: "M1",
|
||||||
emoji: "✅",
|
emoji: "✅",
|
||||||
accountId: "ops",
|
accountId: "ops",
|
||||||
},
|
},
|
||||||
enableAllActions,
|
expectedOptions: { accountId: "ops" },
|
||||||
);
|
},
|
||||||
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅", { accountId: "ops" });
|
])("adds reactions $name", async ({ params, expectedOptions }) => {
|
||||||
|
await handleDiscordMessagingAction("react", params, enableAllActions);
|
||||||
|
if (expectedOptions) {
|
||||||
|
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅", expectedOptions);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("removes reactions on empty emoji", async () => {
|
it("removes reactions on empty emoji", async () => {
|
||||||
@@ -297,6 +303,10 @@ const channelsEnabled = (key: keyof DiscordActionConfig) => key === "channels";
|
|||||||
const channelsDisabled = () => false;
|
const channelsDisabled = () => false;
|
||||||
|
|
||||||
describe("handleDiscordGuildAction - channel management", () => {
|
describe("handleDiscordGuildAction - channel management", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
it("creates a channel", async () => {
|
it("creates a channel", async () => {
|
||||||
const result = await handleDiscordGuildAction(
|
const result = await handleDiscordGuildAction(
|
||||||
"channelCreate",
|
"channelCreate",
|
||||||
@@ -487,45 +497,43 @@ describe("handleDiscordGuildAction - channel management", () => {
|
|||||||
expect(deleteChannelDiscord).toHaveBeenCalledWith("CAT1");
|
expect(deleteChannelDiscord).toHaveBeenCalledWith("CAT1");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets channel permissions for role", async () => {
|
it.each([
|
||||||
await handleDiscordGuildAction(
|
{
|
||||||
"channelPermissionSet",
|
name: "role",
|
||||||
{
|
params: {
|
||||||
channelId: "C1",
|
channelId: "C1",
|
||||||
targetId: "R1",
|
targetId: "R1",
|
||||||
targetType: "role",
|
targetType: "role" as const,
|
||||||
allow: "1024",
|
allow: "1024",
|
||||||
deny: "2048",
|
deny: "2048",
|
||||||
},
|
},
|
||||||
channelsEnabled,
|
expected: {
|
||||||
);
|
channelId: "C1",
|
||||||
expect(setChannelPermissionDiscord).toHaveBeenCalledWith({
|
targetId: "R1",
|
||||||
channelId: "C1",
|
targetType: 0,
|
||||||
targetId: "R1",
|
allow: "1024",
|
||||||
targetType: 0,
|
deny: "2048",
|
||||||
allow: "1024",
|
},
|
||||||
deny: "2048",
|
},
|
||||||
});
|
{
|
||||||
});
|
name: "member",
|
||||||
|
params: {
|
||||||
it("sets channel permissions for member", async () => {
|
|
||||||
await handleDiscordGuildAction(
|
|
||||||
"channelPermissionSet",
|
|
||||||
{
|
|
||||||
channelId: "C1",
|
channelId: "C1",
|
||||||
targetId: "U1",
|
targetId: "U1",
|
||||||
targetType: "member",
|
targetType: "member" as const,
|
||||||
allow: "1024",
|
allow: "1024",
|
||||||
},
|
},
|
||||||
channelsEnabled,
|
expected: {
|
||||||
);
|
channelId: "C1",
|
||||||
expect(setChannelPermissionDiscord).toHaveBeenCalledWith({
|
targetId: "U1",
|
||||||
channelId: "C1",
|
targetType: 1,
|
||||||
targetId: "U1",
|
allow: "1024",
|
||||||
targetType: 1,
|
deny: undefined,
|
||||||
allow: "1024",
|
},
|
||||||
deny: undefined,
|
},
|
||||||
});
|
])("sets channel permissions for $name", async ({ params, expected }) => {
|
||||||
|
await handleDiscordGuildAction("channelPermissionSet", params, channelsEnabled);
|
||||||
|
expect(setChannelPermissionDiscord).toHaveBeenCalledWith(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("removes channel permissions", async () => {
|
it("removes channel permissions", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user