mirror of https://github.com/openclaw/openclaw.git
test: share matrix sdk test mocks
This commit is contained in:
parent
4df8722edf
commit
b6c297af8c
|
|
@ -2,26 +2,12 @@ import type { PluginRuntime, RuntimeEnv } from "openclaw/plugin-sdk/matrix";
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { matrixPlugin } from "./channel.js";
|
||||
import { setMatrixRuntime } from "./runtime.js";
|
||||
import { createMatrixBotSdkMock } from "./test-mocks.js";
|
||||
import type { CoreConfig } from "./types.js";
|
||||
|
||||
vi.mock("@vector-im/matrix-bot-sdk", () => ({
|
||||
ConsoleLogger: class {
|
||||
trace = vi.fn();
|
||||
debug = vi.fn();
|
||||
info = vi.fn();
|
||||
warn = vi.fn();
|
||||
error = vi.fn();
|
||||
},
|
||||
MatrixClient: class {},
|
||||
LogService: {
|
||||
setLogger: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
info: vi.fn(),
|
||||
debug: vi.fn(),
|
||||
},
|
||||
SimpleFsStorageProvider: class {},
|
||||
RustSdkCryptoStorageProvider: class {},
|
||||
}));
|
||||
vi.mock("@vector-im/matrix-bot-sdk", () =>
|
||||
createMatrixBotSdkMock({ includeVerboseLogService: true }),
|
||||
);
|
||||
|
||||
describe("matrix directory", () => {
|
||||
const runtimeEnv: RuntimeEnv = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { PluginRuntime } from "openclaw/plugin-sdk/matrix";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { setMatrixRuntime } from "../runtime.js";
|
||||
import { createMatrixBotSdkMock } from "../test-mocks.js";
|
||||
|
||||
vi.mock("music-metadata", () => ({
|
||||
// `resolveMediaDurationMs` lazily imports `music-metadata`; in tests we don't
|
||||
|
|
@ -8,21 +9,13 @@ vi.mock("music-metadata", () => ({
|
|||
parseBuffer: vi.fn().mockResolvedValue({ format: {} }),
|
||||
}));
|
||||
|
||||
vi.mock("@vector-im/matrix-bot-sdk", () => ({
|
||||
ConsoleLogger: class {
|
||||
trace = vi.fn();
|
||||
debug = vi.fn();
|
||||
info = vi.fn();
|
||||
warn = vi.fn();
|
||||
error = vi.fn();
|
||||
},
|
||||
LogService: {
|
||||
setLogger: vi.fn(),
|
||||
},
|
||||
MatrixClient: vi.fn(),
|
||||
SimpleFsStorageProvider: vi.fn(),
|
||||
RustSdkCryptoStorageProvider: vi.fn(),
|
||||
}));
|
||||
vi.mock("@vector-im/matrix-bot-sdk", () =>
|
||||
createMatrixBotSdkMock({
|
||||
matrixClient: vi.fn(),
|
||||
simpleFsStorageProvider: vi.fn(),
|
||||
rustSdkCryptoStorageProvider: vi.fn(),
|
||||
}),
|
||||
);
|
||||
|
||||
vi.mock("./send-queue.js", () => ({
|
||||
enqueueSend: async <T>(_roomId: string, fn: () => Promise<T>) => await fn(),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
import { vi } from "vitest";
|
||||
|
||||
type MatrixBotSdkMockParams = {
|
||||
matrixClient?: unknown;
|
||||
simpleFsStorageProvider?: unknown;
|
||||
rustSdkCryptoStorageProvider?: unknown;
|
||||
includeVerboseLogService?: boolean;
|
||||
};
|
||||
|
||||
export function createMatrixBotSdkMock(params: MatrixBotSdkMockParams = {}) {
|
||||
return {
|
||||
ConsoleLogger: class {
|
||||
trace = vi.fn();
|
||||
debug = vi.fn();
|
||||
info = vi.fn();
|
||||
warn = vi.fn();
|
||||
error = vi.fn();
|
||||
},
|
||||
MatrixClient: params.matrixClient ?? class {},
|
||||
LogService: {
|
||||
setLogger: vi.fn(),
|
||||
...(params.includeVerboseLogService
|
||||
? {
|
||||
warn: vi.fn(),
|
||||
info: vi.fn(),
|
||||
debug: vi.fn(),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
SimpleFsStorageProvider: params.simpleFsStorageProvider ?? class {},
|
||||
RustSdkCryptoStorageProvider: params.rustSdkCryptoStorageProvider ?? class {},
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue