mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-27 11:56:43 +02:00
test(discord): share successful dm button assertions
This commit is contained in:
@@ -99,6 +99,34 @@ describe("agent components", () => {
|
||||
};
|
||||
};
|
||||
|
||||
async function expectSuccessfulDmButtonInteraction(params: {
|
||||
dmPolicy: "pairing" | "open";
|
||||
expectPairingStoreRead: boolean;
|
||||
}) {
|
||||
const button = createAgentComponentButton({
|
||||
cfg: createCfg(),
|
||||
accountId: "default",
|
||||
dmPolicy: params.dmPolicy,
|
||||
});
|
||||
const { interaction, defer, reply } = createDmButtonInteraction();
|
||||
|
||||
await button.run(interaction, { componentId: "hello" } as ComponentData);
|
||||
|
||||
expect(defer).not.toHaveBeenCalled();
|
||||
expect(reply).toHaveBeenCalledWith({ content: "✓", ephemeral: true });
|
||||
expect(enqueueSystemEventMock).toHaveBeenCalledWith(
|
||||
"[Discord component: hello clicked by Alice#1234 (123456789)]",
|
||||
expect.objectContaining({
|
||||
sessionKey: defaultDmSessionKey,
|
||||
}),
|
||||
);
|
||||
if (params.expectPairingStoreRead) {
|
||||
expect(readAllowFromStoreMock).toHaveBeenCalledWith("discord", "default");
|
||||
} else {
|
||||
expect(readAllowFromStoreMock).not.toHaveBeenCalled();
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
resetDiscordComponentRuntimeMocks();
|
||||
resetSystemEventsForTest();
|
||||
@@ -220,47 +248,19 @@ describe("agent components", () => {
|
||||
|
||||
it("authorizes DM interactions from pairing-store entries in pairing mode", async () => {
|
||||
readAllowFromStoreMock.mockResolvedValue(["123456789"]);
|
||||
const button = createAgentComponentButton({
|
||||
cfg: createCfg(),
|
||||
accountId: "default",
|
||||
await expectSuccessfulDmButtonInteraction({
|
||||
dmPolicy: "pairing",
|
||||
expectPairingStoreRead: true,
|
||||
});
|
||||
const { interaction, defer, reply } = createDmButtonInteraction();
|
||||
|
||||
await button.run(interaction, { componentId: "hello" } as ComponentData);
|
||||
|
||||
expect(defer).not.toHaveBeenCalled();
|
||||
expect(reply).toHaveBeenCalledWith({ content: "✓", ephemeral: true });
|
||||
expect(enqueueSystemEventMock).toHaveBeenCalledWith(
|
||||
"[Discord component: hello clicked by Alice#1234 (123456789)]",
|
||||
expect.objectContaining({
|
||||
sessionKey: defaultDmSessionKey,
|
||||
}),
|
||||
);
|
||||
expect(upsertPairingRequestMock).not.toHaveBeenCalled();
|
||||
expect(readAllowFromStoreMock).toHaveBeenCalledWith("discord", "default");
|
||||
});
|
||||
|
||||
it("allows DM component interactions in open mode without reading pairing store", async () => {
|
||||
readAllowFromStoreMock.mockResolvedValue(["123456789"]);
|
||||
const button = createAgentComponentButton({
|
||||
cfg: createCfg(),
|
||||
accountId: "default",
|
||||
await expectSuccessfulDmButtonInteraction({
|
||||
dmPolicy: "open",
|
||||
expectPairingStoreRead: false,
|
||||
});
|
||||
const { interaction, defer, reply } = createDmButtonInteraction();
|
||||
|
||||
await button.run(interaction, { componentId: "hello" } as ComponentData);
|
||||
|
||||
expect(defer).not.toHaveBeenCalled();
|
||||
expect(reply).toHaveBeenCalledWith({ content: "✓", ephemeral: true });
|
||||
expect(enqueueSystemEventMock).toHaveBeenCalledWith(
|
||||
"[Discord component: hello clicked by Alice#1234 (123456789)]",
|
||||
expect.objectContaining({
|
||||
sessionKey: defaultDmSessionKey,
|
||||
}),
|
||||
);
|
||||
expect(readAllowFromStoreMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses user conversation ids for direct-message component originating targets", () => {
|
||||
|
||||
Reference in New Issue
Block a user