




















1+// Unit tests for failure-alert SQLite column codec roundtrip.
2+import { describe, expect, it } from "vitest";
3+import { bindFailureAlertColumns, failureAlertFromRow } from "./failure-alert-codec.js";
4+import type { CronJobRow } from "./schema.js";
5+6+function roundtrip(
7+input: Parameters<typeof bindFailureAlertColumns>[0],
8+): ReturnType<typeof failureAlertFromRow> {
9+const columns = bindFailureAlertColumns(input);
10+return failureAlertFromRow(columns as CronJobRow);
11+}
12+13+describe("failureAlertFromRow", () => {
14+it("round-trips disabled config (false)", () => {
15+expect(roundtrip(false)).toBe(false);
16+});
17+18+it("round-trips undefined (no alert config) as undefined", () => {
19+expect(roundtrip(undefined)).toBeUndefined();
20+});
21+22+it("round-trips enabled-with-defaults ({}) as {}", () => {
23+const result = roundtrip({});
24+expect(result).toEqual({});
25+});
26+27+it("round-trips populated config with all fields", () => {
28+const config = {
29+after: 3,
30+cooldownMs: 120_000,
31+channel: "telegram" as const,
32+to: "@user",
33+mode: "announce" as const,
34+accountId: "acc-1",
35+includeSkipped: true,
36+};
37+expect(roundtrip(config)).toEqual(config);
38+});
39+40+it("round-trips partial config (only after)", () => {
41+expect(roundtrip({ after: 5 })).toEqual({ after: 5 });
42+});
43+44+it("enabled-with-defaults does not collapse to undefined on read", () => {
45+const columns = bindFailureAlertColumns({});
46+const row = columns as CronJobRow;
47+expect(row.failure_alert_disabled).toBe(0);
48+expect(row.failure_alert_after).toBeNull();
49+const decoded = failureAlertFromRow(row);
50+expect(decoded).toEqual({});
51+expect(decoded).not.toBeUndefined();
52+expect(decoded).toBeTruthy();
53+});
54+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。