refactor(auto-reply): share discord auth registry test fixture
This commit is contained in:
@@ -1,26 +1,10 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import { createOutboundTestPlugin, createTestRegistry } from "../test-utils/channel-plugins.js";
|
||||
import { resolveCommandAuthorization } from "./command-auth.js";
|
||||
import type { MsgContext } from "./templating.js";
|
||||
import { installDiscordRegistryHooks } from "./test-helpers/command-auth-registry-fixture.js";
|
||||
|
||||
const createRegistry = () =>
|
||||
createTestRegistry([
|
||||
{
|
||||
pluginId: "discord",
|
||||
plugin: createOutboundTestPlugin({ id: "discord", outbound: { deliveryMode: "direct" } }),
|
||||
source: "test",
|
||||
},
|
||||
]);
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePluginRegistry(createRegistry());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setActivePluginRegistry(createRegistry());
|
||||
});
|
||||
installDiscordRegistryHooks();
|
||||
|
||||
describe("senderIsOwner only reflects explicit owner authorization", () => {
|
||||
it("does not treat direct-message senders as owners when no ownerAllowFrom is configured", () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import { createOutboundTestPlugin, createTestRegistry } from "../test-utils/channel-plugins.js";
|
||||
@@ -8,23 +8,9 @@ import { listChatCommands } from "./commands-registry.js";
|
||||
import { parseActivationCommand } from "./group-activation.js";
|
||||
import { parseSendPolicyCommand } from "./send-policy.js";
|
||||
import type { MsgContext } from "./templating.js";
|
||||
import { installDiscordRegistryHooks } from "./test-helpers/command-auth-registry-fixture.js";
|
||||
|
||||
const createRegistry = () =>
|
||||
createTestRegistry([
|
||||
{
|
||||
pluginId: "discord",
|
||||
plugin: createOutboundTestPlugin({ id: "discord", outbound: { deliveryMode: "direct" } }),
|
||||
source: "test",
|
||||
},
|
||||
]);
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePluginRegistry(createRegistry());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setActivePluginRegistry(createRegistry());
|
||||
});
|
||||
installDiscordRegistryHooks();
|
||||
|
||||
describe("resolveCommandAuthorization", () => {
|
||||
function resolveWhatsAppAuthorization(params: {
|
||||
|
||||
22
src/auto-reply/test-helpers/command-auth-registry-fixture.ts
Normal file
22
src/auto-reply/test-helpers/command-auth-registry-fixture.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { afterEach, beforeEach } from "vitest";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import { createOutboundTestPlugin, createTestRegistry } from "../../test-utils/channel-plugins.js";
|
||||
|
||||
export const createDiscordRegistry = () =>
|
||||
createTestRegistry([
|
||||
{
|
||||
pluginId: "discord",
|
||||
plugin: createOutboundTestPlugin({ id: "discord", outbound: { deliveryMode: "direct" } }),
|
||||
source: "test",
|
||||
},
|
||||
]);
|
||||
|
||||
export function installDiscordRegistryHooks() {
|
||||
beforeEach(() => {
|
||||
setActivePluginRegistry(createDiscordRegistry());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setActivePluginRegistry(createDiscordRegistry());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user