mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:40:44 +00:00
test(gateway): harden non-isolated channel mocks
This commit is contained in:
@@ -9,7 +9,10 @@ const WEBSOCKET_CLOSE_FORCE_CONTINUE_MS = 250;
|
||||
const HTTP_CLOSE_GRACE_MS = 1_000;
|
||||
const HTTP_CLOSE_FORCE_WAIT_MS = 5_000;
|
||||
|
||||
vi.mock("../channels/plugins/index.js", () => ({
|
||||
vi.mock("../channels/plugins/index.js", async () => ({
|
||||
...(await vi.importActual<typeof import("../channels/plugins/index.js")>(
|
||||
"../channels/plugins/index.js",
|
||||
)),
|
||||
listChannelPlugins: () => [],
|
||||
}));
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ const mocks = vi.hoisted(() => ({
|
||||
...a,
|
||||
})),
|
||||
getChannelPlugin: vi.fn(() => undefined),
|
||||
normalizeChannelId: vi.fn((channel: string) => channel),
|
||||
normalizeChannelId: vi.fn<(channel?: string | null) => string | null>(),
|
||||
resolveOutboundTarget: vi.fn((_params?: { to?: string }) => ({
|
||||
ok: true as const,
|
||||
to: "+15550002",
|
||||
@@ -74,10 +74,23 @@ vi.mock("../utils/delivery-context.shared.js", () => ({
|
||||
mergeDeliveryContext: mocks.mergeDeliveryContext,
|
||||
}));
|
||||
|
||||
vi.mock("../channels/plugins/index.js", () => ({
|
||||
getChannelPlugin: mocks.getChannelPlugin,
|
||||
normalizeChannelId: mocks.normalizeChannelId,
|
||||
}));
|
||||
vi.mock("../channels/plugins/index.js", async () => {
|
||||
return await mergeMockedModule(
|
||||
await vi.importActual<typeof import("../channels/plugins/index.js")>(
|
||||
"../channels/plugins/index.js",
|
||||
),
|
||||
(actual) => ({
|
||||
getChannelPlugin: mocks.getChannelPlugin,
|
||||
normalizeChannelId: mocks.normalizeChannelId.mockImplementation(
|
||||
(channel?: string | null) =>
|
||||
actual.normalizeChannelId(channel) ??
|
||||
(typeof channel === "string" && channel.trim().length > 0
|
||||
? channel.trim().toLowerCase()
|
||||
: null),
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
vi.mock("../infra/outbound/targets.js", () => ({
|
||||
resolveOutboundTarget: mocks.resolveOutboundTarget,
|
||||
@@ -139,6 +152,7 @@ describe("scheduleRestartSentinelWake", () => {
|
||||
mocks.loadSessionEntry.mockReturnValue({ cfg: {}, entry: {} });
|
||||
mocks.deliveryContextFromSession.mockReset();
|
||||
mocks.deliveryContextFromSession.mockReturnValue(undefined);
|
||||
mocks.normalizeChannelId.mockClear();
|
||||
mocks.resolveOutboundTarget.mockReset();
|
||||
mocks.resolveOutboundTarget.mockReturnValue({ ok: true as const, to: "+15550002" });
|
||||
mocks.deliverOutboundPayloads.mockReset();
|
||||
|
||||
Reference in New Issue
Block a user