79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { normalizeCronJobCreate } from "./normalize.js";
|
|
|
|
describe("normalizeCronJobCreate", () => {
|
|
it("maps legacy payload.channel to payload.provider and strips channel", () => {
|
|
const normalized = normalizeCronJobCreate({
|
|
name: "legacy",
|
|
enabled: true,
|
|
schedule: { kind: "cron", expr: "* * * * *" },
|
|
sessionTarget: "isolated",
|
|
wakeMode: "now",
|
|
payload: {
|
|
kind: "agentTurn",
|
|
message: "hi",
|
|
deliver: true,
|
|
channel: " TeLeGrAm ",
|
|
to: "7200373102",
|
|
},
|
|
}) as unknown as Record<string, unknown>;
|
|
|
|
const payload = normalized.payload as Record<string, unknown>;
|
|
expect(payload.provider).toBe("telegram");
|
|
expect("channel" in payload).toBe(false);
|
|
});
|
|
|
|
it("normalizes agentId and drops null", () => {
|
|
const normalized = normalizeCronJobCreate({
|
|
name: "agent-set",
|
|
enabled: true,
|
|
schedule: { kind: "cron", expr: "* * * * *" },
|
|
sessionTarget: "isolated",
|
|
wakeMode: "now",
|
|
agentId: " Ops ",
|
|
payload: {
|
|
kind: "agentTurn",
|
|
message: "hi",
|
|
},
|
|
}) as unknown as Record<string, unknown>;
|
|
|
|
expect(normalized.agentId).toBe("Ops");
|
|
|
|
const cleared = normalizeCronJobCreate({
|
|
name: "agent-clear",
|
|
enabled: true,
|
|
schedule: { kind: "cron", expr: "* * * * *" },
|
|
sessionTarget: "isolated",
|
|
wakeMode: "now",
|
|
agentId: null,
|
|
payload: {
|
|
kind: "agentTurn",
|
|
message: "hi",
|
|
},
|
|
}) as unknown as Record<string, unknown>;
|
|
|
|
expect(cleared.agentId).toBeNull();
|
|
});
|
|
|
|
it("canonicalizes payload.provider casing", () => {
|
|
const normalized = normalizeCronJobCreate({
|
|
name: "legacy provider",
|
|
enabled: true,
|
|
schedule: { kind: "cron", expr: "* * * * *" },
|
|
sessionTarget: "isolated",
|
|
wakeMode: "now",
|
|
payload: {
|
|
kind: "agentTurn",
|
|
message: "hi",
|
|
deliver: true,
|
|
provider: "Telegram",
|
|
to: "7200373102",
|
|
},
|
|
}) as unknown as Record<string, unknown>;
|
|
|
|
const payload = normalized.payload as Record<string, unknown>;
|
|
expect(payload.provider).toBe("telegram");
|
|
});
|
|
});
|