From a5f0f664277ea8fa3bdd9f0983c6ccd811f4c3a7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 19:00:05 +0000 Subject: [PATCH] refactor: share zalouser group auth setup --- .../zalouser/src/monitor.group-gating.test.ts | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/extensions/zalouser/src/monitor.group-gating.test.ts b/extensions/zalouser/src/monitor.group-gating.test.ts index f6723cad3d7..379c7a354b3 100644 --- a/extensions/zalouser/src/monitor.group-gating.test.ts +++ b/extensions/zalouser/src/monitor.group-gating.test.ts @@ -187,6 +187,31 @@ function installRuntime(params: { }; } +function installGroupCommandAuthRuntime() { + return installRuntime({ + resolveCommandAuthorizedFromAuthorizers: ({ useAccessGroups, authorizers }) => + useAccessGroups && authorizers.some((entry) => entry.configured && entry.allowed), + }); +} + +async function processGroupControlCommand(params: { + account: ResolvedZalouserAccount; + content?: string; + commandContent?: string; +}) { + await __testing.processMessage({ + message: createGroupMessage({ + content: params.content ?? "/new", + commandContent: params.commandContent ?? "/new", + hasAnyMention: true, + wasExplicitlyMentioned: true, + }), + account: params.account, + config: createConfig(), + runtime: createRuntimeEnv(), + }); +} + function createGroupMessage(overrides: Partial = {}): ZaloInboundMessage { return { threadId: "g-1", @@ -369,17 +394,8 @@ describe("zalouser monitor group mention gating", () => { it("allows group control commands when only allowFrom is configured", async () => { const { dispatchReplyWithBufferedBlockDispatcher, resolveCommandAuthorizedFromAuthorizers } = - installRuntime({ - resolveCommandAuthorizedFromAuthorizers: ({ useAccessGroups, authorizers }) => - useAccessGroups && authorizers.some((entry) => entry.configured && entry.allowed), - }); - await __testing.processMessage({ - message: createGroupMessage({ - content: "/new", - commandContent: "/new", - hasAnyMention: true, - wasExplicitlyMentioned: true, - }), + installGroupCommandAuthRuntime(); + await processGroupControlCommand({ account: { ...createAccount(), config: { @@ -387,8 +403,6 @@ describe("zalouser monitor group mention gating", () => { allowFrom: ["123"], }, }, - config: createConfig(), - runtime: createRuntimeEnv(), }); expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(1); @@ -493,17 +507,8 @@ describe("zalouser monitor group mention gating", () => { it("allows group control commands when sender is in groupAllowFrom", async () => { const { dispatchReplyWithBufferedBlockDispatcher, resolveCommandAuthorizedFromAuthorizers } = - installRuntime({ - resolveCommandAuthorizedFromAuthorizers: ({ useAccessGroups, authorizers }) => - useAccessGroups && authorizers.some((entry) => entry.configured && entry.allowed), - }); - await __testing.processMessage({ - message: createGroupMessage({ - content: "/new", - commandContent: "/new", - hasAnyMention: true, - wasExplicitlyMentioned: true, - }), + installGroupCommandAuthRuntime(); + await processGroupControlCommand({ account: { ...createAccount(), config: { @@ -512,8 +517,6 @@ describe("zalouser monitor group mention gating", () => { groupAllowFrom: ["123"], }, }, - config: createConfig(), - runtime: createRuntimeEnv(), }); expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(1);