Fix: Preserve delivery settings when updating message via cron edit
- Add failing tests for delivery field preservation - Fix register.cron-edit to conditionally build payload object - Only include delivery fields (deliver, channel, to, bestEffortDeliver) when explicitly provided - Previously undefined values were included, wiping out existing delivery settings - Now --message alone preserves existing delivery config - Tests verify both preservation and explicit override scenarios
This commit is contained in:
committed by
Peter Steinberger
parent
e81ca7ab00
commit
0b2830470c
@@ -246,4 +246,85 @@ describe("cron cli", () => {
|
||||
expect(patch?.patch?.payload?.kind).toBe("agentTurn");
|
||||
expect(patch?.patch?.payload?.deliver).toBe(false);
|
||||
});
|
||||
|
||||
it("does not include undefined delivery fields when updating message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
|
||||
// Update message without delivery flags - should NOT include undefined delivery fields
|
||||
await program.parseAsync(
|
||||
["cron", "edit", "job-1", "--message", "Updated message"],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
|
||||
const patch = updateCall?.[2] as {
|
||||
patch?: {
|
||||
payload?: {
|
||||
message?: string;
|
||||
deliver?: boolean;
|
||||
channel?: string;
|
||||
to?: string;
|
||||
bestEffortDeliver?: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// Should include the new message
|
||||
expect(patch?.patch?.payload?.message).toBe("Updated message");
|
||||
|
||||
// Should NOT include delivery fields at all (to preserve existing values)
|
||||
expect(patch?.patch?.payload).not.toHaveProperty("deliver");
|
||||
expect(patch?.patch?.payload).not.toHaveProperty("channel");
|
||||
expect(patch?.patch?.payload).not.toHaveProperty("to");
|
||||
expect(patch?.patch?.payload).not.toHaveProperty("bestEffortDeliver");
|
||||
});
|
||||
|
||||
it("includes delivery fields when explicitly provided with message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
|
||||
// Update message AND delivery - should include both
|
||||
await program.parseAsync(
|
||||
[
|
||||
"cron",
|
||||
"edit",
|
||||
"job-1",
|
||||
"--message",
|
||||
"Updated message",
|
||||
"--deliver",
|
||||
"--channel",
|
||||
"telegram",
|
||||
"--to",
|
||||
"19098680",
|
||||
],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
|
||||
const patch = updateCall?.[2] as {
|
||||
patch?: {
|
||||
payload?: {
|
||||
message?: string;
|
||||
deliver?: boolean;
|
||||
channel?: string;
|
||||
to?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// Should include everything
|
||||
expect(patch?.patch?.payload?.message).toBe("Updated message");
|
||||
expect(patch?.patch?.payload?.deliver).toBe(true);
|
||||
expect(patch?.patch?.payload?.channel).toBe("telegram");
|
||||
expect(patch?.patch?.payload?.to).toBe("19098680");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user