

























@@ -75,13 +75,29 @@ describe("web auto-reply", () => {
75757676function getSingleImagePayload(sendMedia: ReturnType<typeof vi.fn>) {
7777expect(sendMedia).toHaveBeenCalledTimes(1);
78-return sendMedia.mock.calls[0][0] as {
78+return imagePayloadAt(sendMedia, 0);
79+}
80+81+function imagePayloadAt(sendMedia: ReturnType<typeof vi.fn>, callIndex: number) {
82+const call = sendMedia.mock.calls.at(callIndex);
83+if (!call) {
84+throw new Error(`Expected sendMedia call ${callIndex}`);
85+}
86+return call[0] as {
7987image: Buffer;
8088caption?: string;
8189mimetype?: string;
8290};
8391}
849293+function replyText(reply: ReturnType<typeof vi.fn>): string {
94+const call = reply.mock.calls.at(0);
95+if (!call || typeof call[0] !== "string") {
96+throw new Error("Expected text reply call");
97+}
98+return call[0];
99+}
100+85101async function withMediaCap<T>(mediaMaxMb: number, run: () => Promise<T>): Promise<T> {
86102setLoadConfigMock(() => ({
87103channels: {
@@ -215,11 +231,7 @@ describe("web auto-reply", () => {
215231chatId: `conv-${index}`,
216232});
217233expect(sendMedia).toHaveBeenCalledTimes(beforeCalls + 1);
218-const payload = sendMedia.mock.calls[beforeCalls]?.[0] as {
219-image: Buffer;
220-caption?: string;
221-mimetype?: string;
222-};
234+const payload = imagePayloadAt(sendMedia, beforeCalls);
223235expect(payload.image.length).toBeLessThanOrEqual(SMALL_MEDIA_CAP_BYTES);
224236expect(payload.mimetype).toBe("image/jpeg");
225237}
@@ -310,7 +322,7 @@ describe("web auto-reply", () => {
310322await dispatch("msg-pdf");
311323312324expect(sendMedia).toHaveBeenCalledTimes(1);
313-const payload = sendMedia.mock.calls[0][0] as {
325+const payload = imagePayloadAt(sendMedia, 0) as {
314326document?: Buffer;
315327caption?: string;
316328fileName?: string;
@@ -355,7 +367,7 @@ describe("web auto-reply", () => {
355367await dispatch("msg1");
356368357369expect(sendMedia).toHaveBeenCalledTimes(1);
358-const fallback = reply.mock.calls[0]?.[0] as string;
370+const fallback = replyText(reply);
359371expect(fallback).toContain("hi");
360372expect(fallback).toContain("Media failed");
361373fetchMock.mockRestore();
@@ -381,7 +393,7 @@ describe("web auto-reply", () => {
381393await dispatch("msg1");
382394383395expect(sendMedia).not.toHaveBeenCalled();
384-const fallback = reply.mock.calls[0]?.[0] as string;
396+const fallback = replyText(reply);
385397expect(fallback).toContain("caption");
386398expect(fallback).toContain("Media failed");
387399expect(fallback).not.toContain("404");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。