test: guard discord webhook fetch mock call

This commit is contained in:
Peter Steinberger
2026-05-12 02:50:29 +01:00
parent e1cd9275dc
commit 6ebc6cad17

View File

@@ -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",