mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:00:54 +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_GRACE_MS = 1_000;
|
||||||
const HTTP_CLOSE_FORCE_WAIT_MS = 5_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: () => [],
|
listChannelPlugins: () => [],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const mocks = vi.hoisted(() => ({
|
|||||||
...a,
|
...a,
|
||||||
})),
|
})),
|
||||||
getChannelPlugin: vi.fn(() => undefined),
|
getChannelPlugin: vi.fn(() => undefined),
|
||||||
normalizeChannelId: vi.fn((channel: string) => channel),
|
normalizeChannelId: vi.fn<(channel?: string | null) => string | null>(),
|
||||||
resolveOutboundTarget: vi.fn((_params?: { to?: string }) => ({
|
resolveOutboundTarget: vi.fn((_params?: { to?: string }) => ({
|
||||||
ok: true as const,
|
ok: true as const,
|
||||||
to: "+15550002",
|
to: "+15550002",
|
||||||
@@ -74,10 +74,23 @@ vi.mock("../utils/delivery-context.shared.js", () => ({
|
|||||||
mergeDeliveryContext: mocks.mergeDeliveryContext,
|
mergeDeliveryContext: mocks.mergeDeliveryContext,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../channels/plugins/index.js", () => ({
|
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,
|
getChannelPlugin: mocks.getChannelPlugin,
|
||||||
normalizeChannelId: mocks.normalizeChannelId,
|
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", () => ({
|
vi.mock("../infra/outbound/targets.js", () => ({
|
||||||
resolveOutboundTarget: mocks.resolveOutboundTarget,
|
resolveOutboundTarget: mocks.resolveOutboundTarget,
|
||||||
@@ -139,6 +152,7 @@ describe("scheduleRestartSentinelWake", () => {
|
|||||||
mocks.loadSessionEntry.mockReturnValue({ cfg: {}, entry: {} });
|
mocks.loadSessionEntry.mockReturnValue({ cfg: {}, entry: {} });
|
||||||
mocks.deliveryContextFromSession.mockReset();
|
mocks.deliveryContextFromSession.mockReset();
|
||||||
mocks.deliveryContextFromSession.mockReturnValue(undefined);
|
mocks.deliveryContextFromSession.mockReturnValue(undefined);
|
||||||
|
mocks.normalizeChannelId.mockClear();
|
||||||
mocks.resolveOutboundTarget.mockReset();
|
mocks.resolveOutboundTarget.mockReset();
|
||||||
mocks.resolveOutboundTarget.mockReturnValue({ ok: true as const, to: "+15550002" });
|
mocks.resolveOutboundTarget.mockReturnValue({ ok: true as const, to: "+15550002" });
|
||||||
mocks.deliverOutboundPayloads.mockReset();
|
mocks.deliverOutboundPayloads.mockReset();
|
||||||
|
|||||||
Reference in New Issue
Block a user