

























@@ -113,21 +113,37 @@ describe("Ghost reminder bug (issue #13317)", () => {
113113expect(calledCtx.Body).not.toContain("heartbeat poll");
114114};
115115116+const mockCallAt = (
117+mock: { mock: { calls: Array<readonly unknown[]> } },
118+index: number,
119+label: string,
120+): readonly unknown[] => {
121+const call = mock.mock.calls[index];
122+if (!call) {
123+throw new Error(`expected ${label} call`);
124+}
125+return call;
126+};
127+116128const getFirstReplyContext = (
117129replySpy: ReturnType<typeof vi.fn>,
118130): {
131+Provider?: string;
119132SessionKey?: string;
120133MessageThreadId?: number;
121134Body?: string;
135+ForceSenderIsOwnerFalse?: boolean;
122136} => {
123-const ctx = replySpy.mock.calls.at(0)?.at(0);
137+const [ctx] = mockCallAt(replySpy, 0, "heartbeat reply");
124138if (!ctx || typeof ctx !== "object") {
125139throw new Error("expected heartbeat reply context");
126140}
127141return ctx as {
142+Provider?: string;
128143SessionKey?: string;
129144MessageThreadId?: number;
130145Body?: string;
146+ForceSenderIsOwnerFalse?: boolean;
131147};
132148};
133149@@ -140,7 +156,7 @@ describe("Ghost reminder bug (issue #13317)", () => {
140156},
141157) => {
142158expect(sendTelegram).toHaveBeenCalledTimes(1);
143-const [to, text, options] = sendTelegram.mock.calls.at(0) ?? [];
159+const [to, text, options] = mockCallAt(sendTelegram, 0, "Telegram send");
144160expect(to).toBe(params.to);
145161expect(text).toBe(params.text);
146162expect((options as { messageThreadId?: number } | undefined)?.messageThreadId).toBe(
@@ -202,12 +218,8 @@ describe("Ghost reminder bug (issue #13317)", () => {
202218telegram: sendTelegram,
203219},
204220});
205-const calledCtx = (getReplySpy.mock.calls.at(0)?.at(0) ?? null) as {
206-Provider?: string;
207-Body?: string;
208-SessionKey?: string;
209-ForceSenderIsOwnerFalse?: boolean;
210-} | null;
221+const calledCtx =
222+getReplySpy.mock.calls.length === 0 ? null : getFirstReplyContext(getReplySpy);
211223return {
212224 result,
213225 sendTelegram,
@@ -352,11 +364,11 @@ describe("Ghost reminder bug (issue #13317)", () => {
352364expect(second.status).toBe("ran");
353365expect(getReplySpy).toHaveBeenCalledTimes(2);
354366355-const firstCtx = getReplySpy.mock.calls.at(0)?.at(0) as {
367+const firstCtx = mockCallAt(getReplySpy, 0, "first heartbeat reply")[0] as {
356368Provider?: string;
357369Body?: string;
358370};
359-const secondCtx = getReplySpy.mock.calls.at(1)?.at(0) as {
371+const secondCtx = mockCallAt(getReplySpy, 1, "second heartbeat reply")[0] as {
360372Provider?: string;
361373Body?: string;
362374};
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。