test: isolate qa network fetches

This commit is contained in:
Peter Steinberger
2026-04-10 23:45:59 +01:00
parent ac13b09b74
commit 22c2af0065
2 changed files with 35 additions and 0 deletions

View File

@@ -10,10 +10,22 @@ import {
} from "./targets.js";
const mocks = vi.hoisted(() => ({
fetchWithSsrFGuard: vi.fn(async (params: { url: string; init?: RequestInit }) => ({
response: await fetch(params.url, params.init),
release: async () => {},
})),
verifyIdToken: vi.fn(),
getGoogleChatAccessToken: vi.fn().mockResolvedValue("token"),
}));
vi.mock("../runtime-api.js", async () => {
const actual = await vi.importActual<typeof import("../runtime-api.js")>("../runtime-api.js");
return {
...actual,
fetchWithSsrFGuard: mocks.fetchWithSsrFGuard,
};
});
vi.mock("google-auth-library", () => ({
GoogleAuth: class {},
OAuth2Client: class {
@@ -126,6 +138,7 @@ describe("isSenderAllowed", () => {
describe("downloadGoogleChatMedia", () => {
afterEach(() => {
mocks.fetchWithSsrFGuard.mockClear();
vi.unstubAllGlobals();
});
@@ -165,6 +178,7 @@ describe("downloadGoogleChatMedia", () => {
describe("sendGoogleChatMessage", () => {
afterEach(() => {
mocks.fetchWithSsrFGuard.mockClear();
vi.unstubAllGlobals();
});

View File

@@ -2,8 +2,29 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
import { afterEach, describe, expect, it, vi } from "vitest";
import { __testing } from "./telegram-live.runtime.js";
const fetchWithSsrFGuardMock = vi.hoisted(() =>
vi.fn(async (params: { url: string; init?: RequestInit; signal?: AbortSignal }) => ({
response: await fetch(params.url, {
...params.init,
signal: params.signal,
}),
release: async () => {},
})),
);
vi.mock("openclaw/plugin-sdk/ssrf-runtime", async () => {
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/ssrf-runtime")>(
"openclaw/plugin-sdk/ssrf-runtime",
);
return {
...actual,
fetchWithSsrFGuard: fetchWithSsrFGuardMock,
};
});
describe("telegram live qa runtime", () => {
afterEach(() => {
fetchWithSsrFGuardMock.mockClear();
vi.unstubAllGlobals();
});