test(zalo): align open dm lifecycle fixtures

This commit is contained in:
Peter Steinberger
2026-04-29 07:15:29 +01:00
parent 4eba70b532
commit 2da2d506b5
2 changed files with 12 additions and 2 deletions

View File

@@ -559,6 +559,7 @@ describe("handleZaloWebhookRequest", () => {
...DEFAULT_ACCOUNT,
config: {
dmPolicy: "open",
allowFrom: ["*"],
},
},
});

View File

@@ -3,6 +3,13 @@ import { expect, vi } from "vitest";
import type { OpenClawConfig, PluginRuntime } from "../runtime-api.js";
import type { ResolvedZaloAccount } from "../types.js";
function resolveLifecycleAllowFrom(params: {
dmPolicy: "open" | "pairing";
allowFrom?: string[];
}): string[] | undefined {
return params.allowFrom ?? (params.dmPolicy === "open" ? ["*"] : undefined);
}
export function createLifecycleConfig(params: {
accountId: string;
dmPolicy: "open" | "pairing";
@@ -12,6 +19,7 @@ export function createLifecycleConfig(params: {
}): OpenClawConfig {
const webhookUrl = params.webhookUrl ?? "https://example.com/hooks/zalo";
const webhookSecret = params.webhookSecret ?? "supersecret";
const allowFrom = resolveLifecycleAllowFrom(params);
return {
channels: {
zalo: {
@@ -22,7 +30,7 @@ export function createLifecycleConfig(params: {
webhookUrl,
webhookSecret, // pragma: allowlist secret
dmPolicy: params.dmPolicy,
...(params.allowFrom ? { allowFrom: params.allowFrom } : {}),
...(allowFrom ? { allowFrom } : {}),
},
},
},
@@ -39,6 +47,7 @@ export function createLifecycleAccount(params: {
}): ResolvedZaloAccount {
const webhookUrl = params.webhookUrl ?? "https://example.com/hooks/zalo";
const webhookSecret = params.webhookSecret ?? "supersecret";
const allowFrom = resolveLifecycleAllowFrom(params);
return {
accountId: params.accountId,
enabled: true,
@@ -48,7 +57,7 @@ export function createLifecycleAccount(params: {
webhookUrl,
webhookSecret, // pragma: allowlist secret
dmPolicy: params.dmPolicy,
...(params.allowFrom ? { allowFrom: params.allowFrom } : {}),
...(allowFrom ? { allowFrom } : {}),
},
} as ResolvedZaloAccount;
}