@@ -673,6 +673,47 @@ describe("deliverWebReply", () => {
|
673 | 673 | expect(replyText(msg)).not.toContain("boom"); |
674 | 674 | }); |
675 | 675 | |
| 676 | +it("notifies user when a non-first media send fails instead of dropping silently", async () => { |
| 677 | +vi.clearAllMocks(); |
| 678 | +const msg = makeMsg(); |
| 679 | +// Two media items: first load succeeds and sends, second load succeeds but send fails. |
| 680 | +(loadWebMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }).mockResolvedValueOnce({ |
| 681 | +buffer: Buffer.from("img1"), |
| 682 | +contentType: "image/jpeg", |
| 683 | +kind: "image", |
| 684 | +}); |
| 685 | +(loadWebMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }).mockResolvedValueOnce({ |
| 686 | +buffer: Buffer.from("img2"), |
| 687 | +contentType: "image/jpeg", |
| 688 | +kind: "image", |
| 689 | +}); |
| 690 | +// First sendMedia resolves; second sendMedia rejects. |
| 691 | +(msg.platform.sendMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }).mockResolvedValueOnce( |
| 692 | +createAcceptedWhatsAppSendResult("media", "media-first-ok"), |
| 693 | +); |
| 694 | +(msg.platform.sendMedia as unknown as { mockRejectedValueOnce: (v: unknown) => void }).mockRejectedValueOnce( |
| 695 | +new Error("upload failed"), |
| 696 | +); |
| 697 | + |
| 698 | +await deliverWebReply({ |
| 699 | +replyResult: { |
| 700 | +text: "caption", |
| 701 | +mediaUrls: ["http://example.com/img1.jpg", "http://example.com/img2.jpg"], |
| 702 | +}, |
| 703 | + msg, |
| 704 | +maxMediaBytes: 1024 * 1024, |
| 705 | +textLimit: 200, |
| 706 | + replyLogger, |
| 707 | +skipLog: true, |
| 708 | +}); |
| 709 | + |
| 710 | +// First media succeeded — no text reply for it. |
| 711 | +// Second media failed — user must be notified, not silently dropped. |
| 712 | +expect(msg.platform.reply).toHaveBeenCalledTimes(1); |
| 713 | +expect(replyText(msg)).toContain("⚠️ Media unavailable"); |
| 714 | +expect(replyText(msg)).not.toContain("upload failed"); |
| 715 | +}); |
| 716 | + |
676 | 717 | it("sanitizes XML tool-call blocks for outbound sendPayload delivery", async () => { |
677 | 718 | const sendWhatsApp = vi.fn(async (_to: string, _text: string) => ({ |
678 | 719 | messageId: "wa-1", |
|