mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 03:25:13 +00:00
test: guard discord webhook fetch mock call
This commit is contained in:
@@ -26,6 +26,16 @@ vi.mock("openclaw/plugin-sdk/channel-activity-runtime", async () => {
|
||||
|
||||
let sendWebhookMessageDiscord: typeof import("./send.webhook.js").sendWebhookMessageDiscord;
|
||||
|
||||
type MockWithCalls = { mock: { calls: unknown[][] } };
|
||||
|
||||
function firstMockCall(mock: MockWithCalls, label: string): unknown[] {
|
||||
const call = mock.mock.calls.at(0);
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label} call`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
describe("sendWebhookMessageDiscord activity", () => {
|
||||
beforeAll(async () => {
|
||||
({ sendWebhookMessageDiscord } = await import("./send.webhook.js"));
|
||||
@@ -126,7 +136,7 @@ describe("sendWebhookMessageDiscord activity", () => {
|
||||
|
||||
const fetchMock = vi.mocked(fetch);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
expect(fetchMock.mock.calls[0]).toEqual([
|
||||
expect(firstMockCall(fetchMock, "fetch")).toEqual([
|
||||
"https://discord.com/api/v10/webhooks/wh-1/tok-1?wait=true&thread_id=thread-1",
|
||||
{
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user