





















@@ -111,18 +111,42 @@ describe("createWebSendApi", () => {
111111});
112112});
113113114-it("falls back to default document filename when fileName is absent", async () => {
114+it("falls back to a MIME-aware document filename when fileName is absent", async () => {
115115const payload = Buffer.from("pdf");
116116await api.sendMessage("+1555", "doc", payload, "application/pdf");
117117expectFirstSendJid("1555@s.whatsapp.net");
118118expectSendContentFields(0, {
119119document: payload,
120-fileName: "file",
120+fileName: "file.pdf",
121121caption: "doc",
122122mimetype: "application/pdf",
123123});
124124});
125125126+it("uses MIME mappings for text document filename fallbacks", async () => {
127+const payload = Buffer.from("a,b\n1,2\n");
128+await api.sendMessage("+1555", "doc", payload, "text/csv");
129+130+expectSendContentFields(0, {
131+document: payload,
132+fileName: "file.csv",
133+caption: "doc",
134+mimetype: "text/csv",
135+});
136+});
137+138+it("keeps the plain default document filename when MIME has no extension mapping", async () => {
139+const payload = Buffer.from("unknown");
140+await api.sendMessage("+1555", "doc", payload, "application/x-custom");
141+142+expectSendContentFields(0, {
143+document: payload,
144+fileName: "file",
145+caption: "doc",
146+mimetype: "application/x-custom",
147+});
148+});
149+126150it("sends visual media as document when sendOptions.asDocument is true", async () => {
127151const payload = Buffer.from("img");
128152await api.sendMessage("+1555", "promo", payload, "image/png", {
@@ -140,6 +164,23 @@ describe("createWebSendApi", () => {
140164);
141165});
142166167+it("uses MIME-aware filename fallback for forced visual documents", async () => {
168+const payload = Buffer.from("img");
169+await api.sendMessage("+1555", "promo", payload, "image/png", {
170+asDocument: true,
171+});
172+173+expect(sendMessage).toHaveBeenCalledWith(
174+"1555@s.whatsapp.net",
175+expect.objectContaining({
176+document: payload,
177+fileName: "file.png",
178+caption: "promo",
179+mimetype: "image/png",
180+}),
181+);
182+});
183+143184it("does not force audio media onto the document branch", async () => {
144185const payload = Buffer.from("aud");
145186await api.sendMessage("+1555", "voice", payload, "audio/ogg", {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。