refactor(cron-cli): share enable-disable command wiring

This commit is contained in:
Peter Steinberger
2026-02-18 22:49:28 +00:00
parent 8369913c7a
commit bdb13d6c4c
2 changed files with 61 additions and 39 deletions

View File

@@ -79,6 +79,18 @@ async function runCronAddAndGetParams(addArgs: string[]): Promise<CronAddParams>
return (addCall?.[2] ?? {}) as CronAddParams;
}
async function runCronSimpleAndGetUpdatePatch(
command: "enable" | "disable",
): Promise<{ enabled?: boolean }> {
resetGatewayMock();
const program = buildProgram();
await program.parseAsync(["cron", command, "job-1"], { from: "user" });
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
return ((updateCall?.[2] as { patch?: { enabled?: boolean } } | undefined)?.patch ?? {}) as {
enabled?: boolean;
};
}
describe("cron cli", () => {
it("trims model and thinking on cron add", { timeout: 60_000 }, async () => {
resetGatewayMock();
@@ -196,6 +208,16 @@ describe("cron cli", () => {
expect(params?.deleteAfterRun).toBe(false);
});
it("cron enable sets enabled=true patch", async () => {
const patch = await runCronSimpleAndGetUpdatePatch("enable");
expect(patch.enabled).toBe(true);
});
it("cron disable sets enabled=false patch", async () => {
const patch = await runCronSimpleAndGetUpdatePatch("disable");
expect(patch.enabled).toBe(false);
});
it("sends agent id on cron add", async () => {
resetGatewayMock();