

























@@ -2,6 +2,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
2233const recordChannelActivityMock = vi.hoisted(() => vi.fn());
44const loadConfigMock = vi.hoisted(() => vi.fn(() => ({ channels: { discord: {} } })));
5+let dateNowSpy: ReturnType<typeof vi.spyOn>;
5667vi.mock("openclaw/plugin-sdk/plugin-config-runtime", async () => {
78const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/plugin-config-runtime")>(
@@ -33,6 +34,7 @@ describe("sendWebhookMessageDiscord activity", () => {
3334beforeEach(() => {
3435recordChannelActivityMock.mockClear();
3536loadConfigMock.mockClear();
37+dateNowSpy = vi.spyOn(Date, "now").mockReturnValue(1_700_000_000_000);
3638vi.stubGlobal(
3739"fetch",
3840vi.fn(async () => {
@@ -45,6 +47,7 @@ describe("sendWebhookMessageDiscord activity", () => {
4547});
46484749afterEach(() => {
50+dateNowSpy.mockRestore();
4851vi.unstubAllGlobals();
4952});
5053@@ -67,10 +70,32 @@ describe("sendWebhookMessageDiscord activity", () => {
6770expect(result).toMatchObject({
6871messageId: "msg-1",
6972channelId: "thread-1",
70-receipt: expect.objectContaining({
71-threadId: "thread-1",
72-platformMessageIds: ["msg-1"],
73-}),
73+});
74+expect(result.receipt).toEqual({
75+primaryPlatformMessageId: "msg-1",
76+platformMessageIds: ["msg-1"],
77+parts: [
78+{
79+platformMessageId: "msg-1",
80+kind: "text",
81+index: 0,
82+threadId: "thread-1",
83+raw: {
84+channel: "discord",
85+messageId: "msg-1",
86+channelId: "thread-1",
87+},
88+},
89+],
90+threadId: "thread-1",
91+sentAt: 1_700_000_000_000,
92+raw: [
93+{
94+channel: "discord",
95+messageId: "msg-1",
96+channelId: "thread-1",
97+},
98+],
7499});
75100expect(recordChannelActivityMock).toHaveBeenCalledWith({
76101channel: "discord",
@@ -99,11 +124,19 @@ describe("sendWebhookMessageDiscord activity", () => {
99124threadId: "thread-1",
100125});
101126102-expect(fetch).toHaveBeenCalledWith(
127+const fetchMock = vi.mocked(fetch);
128+expect(fetchMock).toHaveBeenCalledTimes(1);
129+expect(fetchMock.mock.calls[0]).toEqual([
103130"https://discord.com/api/v10/webhooks/wh-1/tok-1?wait=true&thread_id=thread-1",
104-expect.objectContaining({
105-body: expect.stringContaining('"content":"hello <@123456789012345678>"'),
106-}),
107-);
131+{
132+method: "POST",
133+headers: {
134+"content-type": "application/json",
135+},
136+body: JSON.stringify({
137+content: "hello <@123456789012345678>",
138+}),
139+},
140+]);
108141});
109142});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。