mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 04:40:43 +00:00
test: dedupe gateway hooks assertions
This commit is contained in:
@@ -41,10 +41,10 @@ const createIMessageAliasPlugin = () => ({
|
||||
describe("gateway hooks helpers", () => {
|
||||
const resolveHooksConfigOrThrow = (cfg: OpenClawConfig) => {
|
||||
const resolved = resolveHooksConfig(cfg);
|
||||
expect(resolved).not.toBeNull();
|
||||
if (!resolved) {
|
||||
throw new Error("hooks config missing");
|
||||
}
|
||||
expect(resolved.token).toBe(cfg.hooks?.token);
|
||||
return resolved;
|
||||
};
|
||||
|
||||
@@ -188,11 +188,7 @@ describe("gateway hooks helpers", () => {
|
||||
list: [{ id: "main", default: true }, { id: "hooks" }],
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveHooksConfig(cfg);
|
||||
expect(resolved).not.toBeNull();
|
||||
if (!resolved) {
|
||||
return;
|
||||
}
|
||||
const resolved = resolveHooksConfigOrThrow(cfg);
|
||||
expect(resolveHookTargetAgentId(resolved, "hooks")).toBe("hooks");
|
||||
expect(resolveHookTargetAgentId(resolved, "missing-agent")).toBe("main");
|
||||
expect(resolveHookTargetAgentId(resolved, undefined)).toBeUndefined();
|
||||
@@ -223,11 +219,7 @@ describe("gateway hooks helpers", () => {
|
||||
const cfg = {
|
||||
hooks: { enabled: true, token: "secret" },
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveHooksConfig(cfg);
|
||||
expect(resolved).not.toBeNull();
|
||||
if (!resolved) {
|
||||
return;
|
||||
}
|
||||
const resolved = resolveHooksConfigOrThrow(cfg);
|
||||
const denied = resolveHookSessionKey({
|
||||
hooksConfig: resolved,
|
||||
source: "request",
|
||||
@@ -240,11 +232,7 @@ describe("gateway hooks helpers", () => {
|
||||
const cfg = {
|
||||
hooks: { enabled: true, token: "secret", allowRequestSessionKey: true },
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveHooksConfig(cfg);
|
||||
expect(resolved).not.toBeNull();
|
||||
if (!resolved) {
|
||||
return;
|
||||
}
|
||||
const resolved = resolveHooksConfigOrThrow(cfg);
|
||||
const allowed = resolveHookSessionKey({
|
||||
hooksConfig: resolved,
|
||||
source: "request",
|
||||
@@ -262,11 +250,7 @@ describe("gateway hooks helpers", () => {
|
||||
allowedSessionKeyPrefixes: ["hook:"],
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveHooksConfig(cfg);
|
||||
expect(resolved).not.toBeNull();
|
||||
if (!resolved) {
|
||||
return;
|
||||
}
|
||||
const resolved = resolveHooksConfigOrThrow(cfg);
|
||||
|
||||
const blocked = resolveHookSessionKey({
|
||||
hooksConfig: resolved,
|
||||
@@ -291,11 +275,7 @@ describe("gateway hooks helpers", () => {
|
||||
allowedSessionKeyPrefixes: ["hook:", "hook:gmail:"],
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveHooksConfig(cfg);
|
||||
expect(resolved).not.toBeNull();
|
||||
if (!resolved) {
|
||||
return;
|
||||
}
|
||||
const resolved = resolveHooksConfigOrThrow(cfg);
|
||||
|
||||
const denied = resolveHookSessionKey({
|
||||
hooksConfig: resolved,
|
||||
@@ -313,11 +293,7 @@ describe("gateway hooks helpers", () => {
|
||||
allowedSessionKeyPrefixes: ["hook:", "hook:gmail:"],
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveHooksConfig(cfg);
|
||||
expect(resolved).not.toBeNull();
|
||||
if (!resolved) {
|
||||
return;
|
||||
}
|
||||
const resolved = resolveHooksConfigOrThrow(cfg);
|
||||
|
||||
const allowed = resolveHookSessionKey({
|
||||
hooksConfig: resolved,
|
||||
@@ -335,11 +311,7 @@ describe("gateway hooks helpers", () => {
|
||||
defaultSessionKey: "hook:ingress",
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveHooksConfig(cfg);
|
||||
expect(resolved).not.toBeNull();
|
||||
if (!resolved) {
|
||||
return;
|
||||
}
|
||||
const resolved = resolveHooksConfigOrThrow(cfg);
|
||||
|
||||
const resolvedKey = resolveHookSessionKey({
|
||||
hooksConfig: resolved,
|
||||
|
||||
Reference in New Issue
Block a user