mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-24 23:53:02 +00:00
test: tighten discord webhook activity assertions
This commit is contained in:
@@ -2,6 +2,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
|
||||
|
||||
const recordChannelActivityMock = vi.hoisted(() => vi.fn());
|
||||
const loadConfigMock = vi.hoisted(() => vi.fn(() => ({ channels: { discord: {} } })));
|
||||
let dateNowSpy: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/plugin-config-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/plugin-config-runtime")>(
|
||||
@@ -33,6 +34,7 @@ describe("sendWebhookMessageDiscord activity", () => {
|
||||
beforeEach(() => {
|
||||
recordChannelActivityMock.mockClear();
|
||||
loadConfigMock.mockClear();
|
||||
dateNowSpy = vi.spyOn(Date, "now").mockReturnValue(1_700_000_000_000);
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async () => {
|
||||
@@ -45,6 +47,7 @@ describe("sendWebhookMessageDiscord activity", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
dateNowSpy.mockRestore();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
@@ -67,10 +70,32 @@ describe("sendWebhookMessageDiscord activity", () => {
|
||||
expect(result).toMatchObject({
|
||||
messageId: "msg-1",
|
||||
channelId: "thread-1",
|
||||
receipt: expect.objectContaining({
|
||||
threadId: "thread-1",
|
||||
platformMessageIds: ["msg-1"],
|
||||
}),
|
||||
});
|
||||
expect(result.receipt).toEqual({
|
||||
primaryPlatformMessageId: "msg-1",
|
||||
platformMessageIds: ["msg-1"],
|
||||
parts: [
|
||||
{
|
||||
platformMessageId: "msg-1",
|
||||
kind: "text",
|
||||
index: 0,
|
||||
threadId: "thread-1",
|
||||
raw: {
|
||||
channel: "discord",
|
||||
messageId: "msg-1",
|
||||
channelId: "thread-1",
|
||||
},
|
||||
},
|
||||
],
|
||||
threadId: "thread-1",
|
||||
sentAt: 1_700_000_000_000,
|
||||
raw: [
|
||||
{
|
||||
channel: "discord",
|
||||
messageId: "msg-1",
|
||||
channelId: "thread-1",
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(recordChannelActivityMock).toHaveBeenCalledWith({
|
||||
channel: "discord",
|
||||
@@ -99,11 +124,19 @@ describe("sendWebhookMessageDiscord activity", () => {
|
||||
threadId: "thread-1",
|
||||
});
|
||||
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
const fetchMock = vi.mocked(fetch);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
expect(fetchMock.mock.calls[0]).toEqual([
|
||||
"https://discord.com/api/v10/webhooks/wh-1/tok-1?wait=true&thread_id=thread-1",
|
||||
expect.objectContaining({
|
||||
body: expect.stringContaining('"content":"hello <@123456789012345678>"'),
|
||||
}),
|
||||
);
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: "hello <@123456789012345678>",
|
||||
}),
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user