




























@@ -107,6 +107,7 @@ describe("web outbound", () => {
107107};
108108mediaLocalRoots?: readonly string[];
109109mediaReadFile?: (filePath: string) => Promise<Buffer>;
110+optimizeImages?: boolean;
110111},
111112) =>
112113await loadWebMediaMock(mediaUrl, {
@@ -451,6 +452,89 @@ describe("web outbound", () => {
451452});
452453});
453454455+it("forces document branch when forceDocument is true with image media", async () => {
456+const buf = Buffer.from("img");
457+loadWebMediaMock.mockResolvedValueOnce({
458+buffer: buf,
459+contentType: "image/jpeg",
460+kind: "image",
461+fileName: "promo.jpg",
462+});
463+await sendMessageWhatsApp("+1555", "look", {
464+verbose: false,
465+cfg: WHATSAPP_TEST_CFG,
466+mediaUrl: "/tmp/pic.jpg",
467+forceDocument: true,
468+});
469+expect(sendMessage).toHaveBeenLastCalledWith("+1555", "look", buf, "image/jpeg", {
470+asDocument: true,
471+fileName: "promo.jpg",
472+});
473+expect(hoisted.loadOutboundMediaFromUrl).toHaveBeenCalledWith(
474+"/tmp/pic.jpg",
475+expect.objectContaining({ optimizeImages: false }),
476+);
477+});
478+479+it("forces document branch when forceDocument is true with video media", async () => {
480+const buf = Buffer.from("video");
481+loadWebMediaMock.mockResolvedValueOnce({
482+buffer: buf,
483+contentType: "video/mp4",
484+kind: "video",
485+fileName: "clip.mp4",
486+});
487+await sendMessageWhatsApp("+1555", "watch", {
488+verbose: false,
489+cfg: WHATSAPP_TEST_CFG,
490+mediaUrl: "/tmp/clip.mp4",
491+forceDocument: true,
492+});
493+expect(sendMessage).toHaveBeenLastCalledWith("+1555", "watch", buf, "video/mp4", {
494+asDocument: true,
495+fileName: "clip.mp4",
496+});
497+});
498+499+it("falls back to a default filename when forceDocument media has no fileName", async () => {
500+const buf = Buffer.from("img");
501+loadWebMediaMock.mockResolvedValueOnce({
502+buffer: buf,
503+contentType: "image/png",
504+kind: "image",
505+});
506+await sendMessageWhatsApp("+1555", "promo", {
507+verbose: false,
508+cfg: WHATSAPP_TEST_CFG,
509+mediaUrl: "/tmp/pic.png",
510+forceDocument: true,
511+});
512+expect(sendMessage).toHaveBeenLastCalledWith("+1555", "promo", buf, "image/png", {
513+asDocument: true,
514+fileName: "file",
515+});
516+});
517+518+it("keeps audio on the voice-note path when forceDocument is true", async () => {
519+const buf = Buffer.from("audio");
520+loadWebMediaMock.mockResolvedValueOnce({
521+buffer: buf,
522+contentType: "audio/ogg",
523+kind: "audio",
524+fileName: "voice.ogg",
525+});
526+527+await sendMessageWhatsApp("+1555", "voice note", {
528+verbose: false,
529+cfg: WHATSAPP_TEST_CFG,
530+mediaUrl: "/tmp/voice.ogg",
531+forceDocument: true,
532+});
533+534+expect(sendMessage).toHaveBeenNthCalledWith(1, "+1555", "", buf, "audio/ogg; codecs=opus");
535+expect(sendMessage).toHaveBeenNthCalledWith(2, "+1555", "voice note", undefined, undefined);
536+});
537+454538it("uses account-aware WhatsApp media caps for outbound uploads", async () => {
455539hoisted.controllerListeners.set("work", {
456540 sendComposingTo,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。