mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test: remove redundant slash channel-policy integration case
This commit is contained in:
@@ -188,123 +188,3 @@ describe("Slack native command argument menus", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createPolicyHarness() {
|
||||
const commands = new Map<unknown, (args: unknown) => Promise<void>>();
|
||||
const postEphemeral = vi.fn().mockResolvedValue({ ok: true });
|
||||
const app = {
|
||||
client: { chat: { postEphemeral } },
|
||||
command: (name: unknown, handler: (args: unknown) => Promise<void>) => {
|
||||
commands.set(name, handler);
|
||||
},
|
||||
};
|
||||
|
||||
const ctx = {
|
||||
cfg: { commands: { native: false } },
|
||||
runtime: {},
|
||||
botToken: "bot-token",
|
||||
botUserId: "bot",
|
||||
teamId: "T1",
|
||||
allowFrom: ["*"],
|
||||
dmEnabled: true,
|
||||
dmPolicy: "open",
|
||||
groupDmEnabled: false,
|
||||
groupDmChannels: [],
|
||||
defaultRequireMention: true,
|
||||
groupPolicy: "open",
|
||||
useAccessGroups: true,
|
||||
channelsConfig: undefined,
|
||||
slashCommand: {
|
||||
enabled: true,
|
||||
name: "openclaw",
|
||||
ephemeral: true,
|
||||
sessionPrefix: "slack:slash",
|
||||
},
|
||||
textLimit: 4000,
|
||||
app,
|
||||
isChannelAllowed: () => true,
|
||||
resolveChannelName: async () => ({ name: "unlisted", type: "channel" }),
|
||||
resolveUserName: async () => ({ name: "Ada" }),
|
||||
} as Record<string, unknown>;
|
||||
|
||||
const account = { accountId: "acct", config: { commands: { native: false } } } as unknown;
|
||||
|
||||
return { commands, ctx, account, postEphemeral };
|
||||
}
|
||||
|
||||
function resetPolicyHarness(harness: ReturnType<typeof createPolicyHarness>) {
|
||||
harness.ctx.allowFrom = ["*"];
|
||||
harness.ctx.groupPolicy = "open";
|
||||
harness.ctx.useAccessGroups = true;
|
||||
harness.ctx.channelsConfig = undefined;
|
||||
harness.ctx.resolveChannelName = async () => ({ name: "unlisted", type: "channel" });
|
||||
}
|
||||
|
||||
async function runSlashHandler(params: {
|
||||
commands: Map<unknown, (args: unknown) => Promise<void>>;
|
||||
command: Partial<{
|
||||
user_id: string;
|
||||
user_name: string;
|
||||
channel_id: string;
|
||||
channel_name: string;
|
||||
text: string;
|
||||
trigger_id: string;
|
||||
}> &
|
||||
Pick<{ channel_id: string; channel_name: string }, "channel_id" | "channel_name">;
|
||||
}): Promise<{ respond: ReturnType<typeof vi.fn>; ack: ReturnType<typeof vi.fn> }> {
|
||||
const handler = [...params.commands.values()][0];
|
||||
if (!handler) {
|
||||
throw new Error("Missing slash handler");
|
||||
}
|
||||
|
||||
const respond = vi.fn().mockResolvedValue(undefined);
|
||||
const ack = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
await handler({
|
||||
command: {
|
||||
user_id: "U1",
|
||||
user_name: "Ada",
|
||||
text: "hello",
|
||||
trigger_id: "t1",
|
||||
...params.command,
|
||||
},
|
||||
ack,
|
||||
respond,
|
||||
});
|
||||
|
||||
return { respond, ack };
|
||||
}
|
||||
|
||||
describe("slack slash commands channel policy", () => {
|
||||
let harness: ReturnType<typeof createPolicyHarness>;
|
||||
|
||||
beforeAll(async () => {
|
||||
harness = createPolicyHarness();
|
||||
await registerCommands(harness.ctx, harness.account);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
harness.postEphemeral.mockClear();
|
||||
resetPolicyHarness(harness);
|
||||
});
|
||||
|
||||
it("blocks unlisted channels when groupPolicy is allowlist", async () => {
|
||||
harness.ctx.groupPolicy = "allowlist";
|
||||
harness.ctx.channelsConfig = { C_LISTED: { requireMention: true } };
|
||||
harness.ctx.resolveChannelName = async () => ({ name: "unlisted", type: "channel" });
|
||||
|
||||
const { respond } = await runSlashHandler({
|
||||
commands: harness.commands,
|
||||
command: {
|
||||
channel_id: "C_UNLISTED",
|
||||
channel_name: "unlisted",
|
||||
},
|
||||
});
|
||||
|
||||
expect(dispatchMock).not.toHaveBeenCalled();
|
||||
expect(respond).toHaveBeenCalledWith({
|
||||
text: "This channel is not allowed.",
|
||||
response_type: "ephemeral",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user