Skip to content

Commit 624af62

Browse files
committed
test: tighten cron failure notification assertions
1 parent 4ec277c commit 624af62

1 file changed

Lines changed: 36 additions & 23 deletions

File tree

src/cron/delivery.failure-notify.test.ts

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,33 @@ describe("sendFailureNotificationAnnounce", () => {
7979
agentId: "main",
8080
sessionKey: "cron:job-1:failure",
8181
});
82-
expect(mocks.deliverOutboundPayloads).toHaveBeenCalledWith(
83-
expect.objectContaining({
84-
cfg,
85-
channel: "telegram",
86-
to: "123",
87-
accountId: "bot-a",
88-
threadId: 42,
89-
payloads: [{ text: "Cron failed" }],
90-
session: { kind: "session" },
91-
identity: { kind: "identity" },
92-
bestEffort: false,
93-
deps: { kind: "deps" },
94-
abortSignal: expect.any(AbortSignal),
95-
}),
96-
);
82+
expect(mocks.deliverOutboundPayloads).toHaveBeenCalledTimes(1);
83+
const [deliveryRequest] = mocks.deliverOutboundPayloads.mock.calls[0] as [
84+
{
85+
abortSignal?: unknown;
86+
accountId?: string;
87+
bestEffort?: boolean;
88+
cfg?: unknown;
89+
channel?: string;
90+
deps?: unknown;
91+
identity?: unknown;
92+
payloads?: unknown;
93+
session?: unknown;
94+
threadId?: number;
95+
to?: string;
96+
},
97+
];
98+
expect(deliveryRequest.cfg).toBe(cfg);
99+
expect(deliveryRequest.channel).toBe("telegram");
100+
expect(deliveryRequest.to).toBe("123");
101+
expect(deliveryRequest.accountId).toBe("bot-a");
102+
expect(deliveryRequest.threadId).toBe(42);
103+
expect(deliveryRequest.payloads).toEqual([{ text: "Cron failed" }]);
104+
expect(deliveryRequest.session).toEqual({ kind: "session" });
105+
expect(deliveryRequest.identity).toEqual({ kind: "identity" });
106+
expect(deliveryRequest.bestEffort).toBe(false);
107+
expect(deliveryRequest.deps).toEqual({ kind: "deps" });
108+
expect(deliveryRequest.abortSignal).toBeInstanceOf(AbortSignal);
97109
});
98110

99111
it("uses sessionKey for delivery-target resolution and outbound context", async () => {
@@ -158,13 +170,14 @@ describe("sendFailureNotificationAnnounce", () => {
158170
),
159171
).resolves.toBeUndefined();
160172

161-
expect(mocks.warn).toHaveBeenCalledWith(
162-
expect.objectContaining({
163-
err: "send failed",
164-
channel: "telegram",
165-
to: "123",
166-
}),
167-
"cron: failure destination announce failed",
168-
);
173+
expect(mocks.warn).toHaveBeenCalledTimes(1);
174+
const [warnMeta, warnMessage] = mocks.warn.mock.calls[0] as [
175+
{ channel?: string; err?: string; to?: string },
176+
string,
177+
];
178+
expect(warnMeta.err).toBe("send failed");
179+
expect(warnMeta.channel).toBe("telegram");
180+
expect(warnMeta.to).toBe("123");
181+
expect(warnMessage).toBe("cron: failure destination announce failed");
169182
});
170183
});

0 commit comments

Comments
 (0)