mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-24 08:49:49 +00:00
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { WizardPrompter } from "../runtime-api.js";
|
|
import { installMatrixTestRuntime } from "./test-runtime.js";
|
|
import type { CoreConfig } from "./types.js";
|
|
|
|
const resolveMatrixTargetsMock = vi.hoisted(() =>
|
|
vi.fn(async () => [{ input: "Alice", resolved: true, id: "@alice:example.org" }]),
|
|
);
|
|
|
|
vi.mock("./resolve-targets.js", () => ({
|
|
resolveMatrixTargets: resolveMatrixTargetsMock,
|
|
}));
|
|
|
|
let promptMatrixAllowFrom: typeof import("./onboarding.js").__testing.promptMatrixAllowFrom;
|
|
|
|
describe("matrix onboarding account-scoped resolution", () => {
|
|
beforeAll(async () => {
|
|
({ promptMatrixAllowFrom } = (await import("./onboarding.js")).__testing);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
installMatrixTestRuntime();
|
|
resolveMatrixTargetsMock.mockClear();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("passes accountId into Matrix allowlist target resolution during onboarding", async () => {
|
|
const prompter = {
|
|
note: vi.fn(async () => {}),
|
|
text: vi.fn(async () => "Alice"),
|
|
} as unknown as WizardPrompter;
|
|
const cfg = {
|
|
channels: {
|
|
matrix: {
|
|
accounts: {
|
|
default: {
|
|
homeserver: "https://matrix.main.example.org",
|
|
accessToken: "main-token",
|
|
},
|
|
ops: {
|
|
homeserver: "https://matrix.ops.example.org",
|
|
accessToken: "ops-token",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} as CoreConfig;
|
|
const result = await promptMatrixAllowFrom({
|
|
cfg,
|
|
prompter,
|
|
accountId: "ops",
|
|
});
|
|
|
|
expect(result.channels?.matrix?.accounts?.ops?.dm?.allowFrom).toEqual(["@alice:example.org"]);
|
|
expect(resolveMatrixTargetsMock).toHaveBeenCalledWith({
|
|
cfg,
|
|
accountId: "ops",
|
|
inputs: ["Alice"],
|
|
kind: "user",
|
|
});
|
|
});
|
|
});
|