mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 06:21:26 +00:00
refactor(test): share web inbound access control setup
This commit is contained in:
40
src/web/inbound/access-control.test-harness.ts
Normal file
40
src/web/inbound/access-control.test-harness.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
|
||||
export const sendMessageMock = vi.fn();
|
||||
export const readAllowFromStoreMock = vi.fn();
|
||||
export const upsertPairingRequestMock = vi.fn();
|
||||
|
||||
let config: Record<string, unknown> = {};
|
||||
|
||||
export function setAccessControlTestConfig(next: Record<string, unknown>): void {
|
||||
config = next;
|
||||
}
|
||||
|
||||
export function setupAccessControlTestHarness(): void {
|
||||
beforeEach(() => {
|
||||
config = {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
dmPolicy: "pairing",
|
||||
allowFrom: [],
|
||||
},
|
||||
},
|
||||
};
|
||||
sendMessageMock.mockReset().mockResolvedValue(undefined);
|
||||
readAllowFromStoreMock.mockReset().mockResolvedValue([]);
|
||||
upsertPairingRequestMock.mockReset().mockResolvedValue({ code: "PAIRCODE", created: true });
|
||||
});
|
||||
}
|
||||
|
||||
vi.mock("../../config/config.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../../config/config.js")>();
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: () => config,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../../pairing/pairing-store.js", () => ({
|
||||
readChannelAllowFromStore: (...args: unknown[]) => readAllowFromStoreMock(...args),
|
||||
upsertChannelPairingRequest: (...args: unknown[]) => upsertPairingRequestMock(...args),
|
||||
}));
|
||||
Reference in New Issue
Block a user