test: dedupe discord bound slash dispatch setup

This commit is contained in:
Peter Steinberger
2026-03-13 22:32:23 +00:00
parent 6cabcf3fd2
commit a7c293b8ef

View File

@@ -130,6 +130,25 @@ function expectBoundSessionDispatch(
expect(persistentBindingMocks.ensureConfiguredAcpBindingSession).toHaveBeenCalledTimes(1); expect(persistentBindingMocks.ensureConfiguredAcpBindingSession).toHaveBeenCalledTimes(1);
} }
async function expectBoundStatusCommandDispatch(params: {
cfg: OpenClawConfig;
interaction: MockCommandInteraction;
channelId: string;
boundSessionKey: string;
}) {
const command = createStatusCommand(params.cfg);
setConfiguredBinding(params.channelId, params.boundSessionKey);
vi.spyOn(pluginCommandsModule, "matchPluginCommand").mockReturnValue(null);
const dispatchSpy = createDispatchSpy();
await (command as { run: (interaction: unknown) => Promise<void> }).run(
params.interaction as unknown,
);
expectBoundSessionDispatch(dispatchSpy, params.boundSessionKey);
}
describe("Discord native plugin command dispatch", () => { describe("Discord native plugin command dispatch", () => {
beforeEach(() => { beforeEach(() => {
vi.restoreAllMocks(); vi.restoreAllMocks();
@@ -212,7 +231,6 @@ describe("Discord native plugin command dispatch", () => {
}, },
], ],
} as OpenClawConfig; } as OpenClawConfig;
const command = createStatusCommand(cfg);
const interaction = createInteraction({ const interaction = createInteraction({
channelType: ChannelType.GuildText, channelType: ChannelType.GuildText,
channelId, channelId,
@@ -220,14 +238,12 @@ describe("Discord native plugin command dispatch", () => {
guildName: "Ops", guildName: "Ops",
}); });
setConfiguredBinding(channelId, boundSessionKey); await expectBoundStatusCommandDispatch({
cfg,
vi.spyOn(pluginCommandsModule, "matchPluginCommand").mockReturnValue(null); interaction,
const dispatchSpy = createDispatchSpy(); channelId,
boundSessionKey,
await (command as { run: (interaction: unknown) => Promise<void> }).run(interaction as unknown); });
expectBoundSessionDispatch(dispatchSpy, boundSessionKey);
}); });
it("falls back to the routed slash and channel session keys when no bound session exists", async () => { it("falls back to the routed slash and channel session keys when no bound session exists", async () => {
@@ -312,19 +328,16 @@ describe("Discord native plugin command dispatch", () => {
}, },
}, },
} as OpenClawConfig; } as OpenClawConfig;
const command = createStatusCommand(cfg);
const interaction = createInteraction({ const interaction = createInteraction({
channelType: ChannelType.DM, channelType: ChannelType.DM,
channelId, channelId,
}); });
setConfiguredBinding(channelId, boundSessionKey); await expectBoundStatusCommandDispatch({
cfg,
vi.spyOn(pluginCommandsModule, "matchPluginCommand").mockReturnValue(null); interaction,
const dispatchSpy = createDispatchSpy(); channelId,
boundSessionKey,
await (command as { run: (interaction: unknown) => Promise<void> }).run(interaction as unknown); });
expectBoundSessionDispatch(dispatchSpy, boundSessionKey);
}); });
}); });