mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 01:28:27 +00:00
test(cron): dedupe webhook patch validation cases
This commit is contained in:
@@ -32,6 +32,13 @@ describe("applyJobPatch", () => {
|
|||||||
payload: { kind: "systemEvent", text: "ping" },
|
payload: { kind: "systemEvent", text: "ping" },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createMainSystemEventJob = (id: string, delivery: CronJob["delivery"]): CronJob => {
|
||||||
|
return createIsolatedAgentTurnJob(id, delivery, {
|
||||||
|
sessionTarget: "main",
|
||||||
|
payload: { kind: "systemEvent", text: "ping" },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
it("clears delivery when switching to main session", () => {
|
it("clears delivery when switching to main session", () => {
|
||||||
const job = createIsolatedAgentTurnJob("job-1", {
|
const job = createIsolatedAgentTurnJob("job-1", {
|
||||||
mode: "announce",
|
mode: "announce",
|
||||||
@@ -109,50 +116,36 @@ describe("applyJobPatch", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("rejects webhook delivery without a valid http(s) target URL", () => {
|
it("rejects webhook delivery without a valid http(s) target URL", () => {
|
||||||
const now = Date.now();
|
const expectedError = "cron webhook delivery requires delivery.to to be a valid http(s) URL";
|
||||||
const job: CronJob = {
|
const cases = [
|
||||||
id: "job-webhook-invalid",
|
{ name: "no delivery update", patch: { enabled: true } satisfies CronJobPatch },
|
||||||
name: "job-webhook-invalid",
|
{
|
||||||
enabled: true,
|
name: "blank webhook target",
|
||||||
createdAtMs: now,
|
patch: { delivery: { mode: "webhook", to: "" } } satisfies CronJobPatch,
|
||||||
updatedAtMs: now,
|
},
|
||||||
schedule: { kind: "every", everyMs: 60_000 },
|
{
|
||||||
sessionTarget: "main",
|
name: "non-http protocol",
|
||||||
wakeMode: "now",
|
patch: {
|
||||||
payload: { kind: "systemEvent", text: "ping" },
|
delivery: { mode: "webhook", to: "ftp://example.invalid" },
|
||||||
delivery: { mode: "webhook" },
|
} satisfies CronJobPatch,
|
||||||
state: {},
|
},
|
||||||
};
|
{
|
||||||
|
name: "invalid URL",
|
||||||
|
patch: { delivery: { mode: "webhook", to: "not-a-url" } } satisfies CronJobPatch,
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
expect(() => applyJobPatch(job, { enabled: true })).toThrow(
|
for (const testCase of cases) {
|
||||||
"cron webhook delivery requires delivery.to to be a valid http(s) URL",
|
const job = createMainSystemEventJob("job-webhook-invalid", { mode: "webhook" });
|
||||||
);
|
expect(() => applyJobPatch(job, testCase.patch), testCase.name).toThrow(expectedError);
|
||||||
expect(() => applyJobPatch(job, { delivery: { mode: "webhook", to: "" } })).toThrow(
|
}
|
||||||
"cron webhook delivery requires delivery.to to be a valid http(s) URL",
|
|
||||||
);
|
|
||||||
expect(() =>
|
|
||||||
applyJobPatch(job, { delivery: { mode: "webhook", to: "ftp://example.invalid" } }),
|
|
||||||
).toThrow("cron webhook delivery requires delivery.to to be a valid http(s) URL");
|
|
||||||
expect(() => applyJobPatch(job, { delivery: { mode: "webhook", to: "not-a-url" } })).toThrow(
|
|
||||||
"cron webhook delivery requires delivery.to to be a valid http(s) URL",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("trims webhook delivery target URLs", () => {
|
it("trims webhook delivery target URLs", () => {
|
||||||
const now = Date.now();
|
const job = createMainSystemEventJob("job-webhook-trim", {
|
||||||
const job: CronJob = {
|
mode: "webhook",
|
||||||
id: "job-webhook-trim",
|
to: "https://example.invalid/original",
|
||||||
name: "job-webhook-trim",
|
});
|
||||||
enabled: true,
|
|
||||||
createdAtMs: now,
|
|
||||||
updatedAtMs: now,
|
|
||||||
schedule: { kind: "every", everyMs: 60_000 },
|
|
||||||
sessionTarget: "main",
|
|
||||||
wakeMode: "now",
|
|
||||||
payload: { kind: "systemEvent", text: "ping" },
|
|
||||||
delivery: { mode: "webhook", to: "https://example.invalid/original" },
|
|
||||||
state: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(() =>
|
expect(() =>
|
||||||
applyJobPatch(job, { delivery: { mode: "webhook", to: " https://example.invalid/trim " } }),
|
applyJobPatch(job, { delivery: { mode: "webhook", to: " https://example.invalid/trim " } }),
|
||||||
|
|||||||
Reference in New Issue
Block a user