mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 00:04:32 +00:00
test: share channels command mock harness
This commit is contained in:
@@ -1,34 +1,8 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js";
|
import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js";
|
||||||
import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js";
|
|
||||||
|
|
||||||
const configMocks = vi.hoisted(() => ({
|
|
||||||
readConfigFileSnapshot: vi.fn(),
|
|
||||||
writeConfigFile: vi.fn().mockResolvedValue(undefined),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const offsetMocks = vi.hoisted(() => ({
|
|
||||||
deleteTelegramUpdateOffset: vi.fn().mockResolvedValue(undefined),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("../config/config.js", async (importOriginal) => {
|
|
||||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
|
||||||
return {
|
|
||||||
...actual,
|
|
||||||
readConfigFileSnapshot: configMocks.readConfigFileSnapshot,
|
|
||||||
writeConfigFile: configMocks.writeConfigFile,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock("../telegram/update-offset-store.js", async (importOriginal) => {
|
|
||||||
const actual = await importOriginal<typeof import("../telegram/update-offset-store.js")>();
|
|
||||||
return {
|
|
||||||
...actual,
|
|
||||||
deleteTelegramUpdateOffset: offsetMocks.deleteTelegramUpdateOffset,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
import { channelsAddCommand } from "./channels.js";
|
import { channelsAddCommand } from "./channels.js";
|
||||||
|
import { configMocks, offsetMocks } from "./channels.mock-harness.js";
|
||||||
|
import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js";
|
||||||
|
|
||||||
const runtime = createTestRuntime();
|
const runtime = createTestRuntime();
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,12 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js";
|
import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js";
|
||||||
|
import { configMocks, offsetMocks } from "./channels.mock-harness.js";
|
||||||
import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js";
|
import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js";
|
||||||
|
|
||||||
const configMocks = vi.hoisted(() => ({
|
|
||||||
readConfigFileSnapshot: vi.fn(),
|
|
||||||
writeConfigFile: vi.fn().mockResolvedValue(undefined),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const authMocks = vi.hoisted(() => ({
|
const authMocks = vi.hoisted(() => ({
|
||||||
loadAuthProfileStore: vi.fn(),
|
loadAuthProfileStore: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const offsetMocks = vi.hoisted(() => ({
|
|
||||||
deleteTelegramUpdateOffset: vi.fn().mockResolvedValue(undefined),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("../config/config.js", async (importOriginal) => {
|
|
||||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
|
||||||
return {
|
|
||||||
...actual,
|
|
||||||
readConfigFileSnapshot: configMocks.readConfigFileSnapshot,
|
|
||||||
writeConfigFile: configMocks.writeConfigFile,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock("../agents/auth-profiles.js", async (importOriginal) => {
|
vi.mock("../agents/auth-profiles.js", async (importOriginal) => {
|
||||||
const actual = await importOriginal<typeof import("../agents/auth-profiles.js")>();
|
const actual = await importOriginal<typeof import("../agents/auth-profiles.js")>();
|
||||||
return {
|
return {
|
||||||
@@ -32,14 +15,6 @@ vi.mock("../agents/auth-profiles.js", async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.mock("../telegram/update-offset-store.js", async (importOriginal) => {
|
|
||||||
const actual = await importOriginal<typeof import("../telegram/update-offset-store.js")>();
|
|
||||||
return {
|
|
||||||
...actual,
|
|
||||||
deleteTelegramUpdateOffset: offsetMocks.deleteTelegramUpdateOffset,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
channelsAddCommand,
|
channelsAddCommand,
|
||||||
channelsListCommand,
|
channelsListCommand,
|
||||||
|
|||||||
27
src/commands/channels.mock-harness.ts
Normal file
27
src/commands/channels.mock-harness.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { vi } from "vitest";
|
||||||
|
|
||||||
|
export const configMocks = {
|
||||||
|
readConfigFileSnapshot: vi.fn(),
|
||||||
|
writeConfigFile: vi.fn().mockResolvedValue(undefined),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const offsetMocks = {
|
||||||
|
deleteTelegramUpdateOffset: vi.fn().mockResolvedValue(undefined),
|
||||||
|
};
|
||||||
|
|
||||||
|
vi.mock("../config/config.js", async (importOriginal) => {
|
||||||
|
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
readConfigFileSnapshot: configMocks.readConfigFileSnapshot,
|
||||||
|
writeConfigFile: configMocks.writeConfigFile,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
vi.mock("../telegram/update-offset-store.js", async (importOriginal) => {
|
||||||
|
const actual = await importOriginal<typeof import("../telegram/update-offset-store.js")>();
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
deleteTelegramUpdateOffset: offsetMocks.deleteTelegramUpdateOffset,
|
||||||
|
};
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user