fix(media): preserve outbound attachment filenames

(cherry picked from commit fcc86f043b)
This commit is contained in:
Ayaan Zaidi
2026-04-21 13:59:21 +05:30
committed by Peter Steinberger
parent 542086ccea
commit 79840c9fdf
2 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { describe, expect, it, vi } from "vitest";
const loadWebMedia = vi.hoisted(() => vi.fn());
const saveMediaBuffer = vi.hoisted(() => vi.fn());
vi.mock("./web-media.js", () => ({
loadWebMedia,
}));
vi.mock("./store.js", () => ({
saveMediaBuffer,
}));
const { resolveOutboundAttachmentFromUrl } = await import("./outbound-attachment.js");
describe("resolveOutboundAttachmentFromUrl", () => {
it("preserves the loaded file name when staging outbound media", async () => {
const buffer = Buffer.from("pdf");
loadWebMedia.mockResolvedValueOnce({
buffer,
contentType: "application/pdf",
fileName: "report.pdf",
});
saveMediaBuffer.mockResolvedValueOnce({
path: "/tmp/media/outbound/report---uuid.pdf",
contentType: "application/pdf",
});
await resolveOutboundAttachmentFromUrl("./report.pdf", 1024);
expect(saveMediaBuffer).toHaveBeenCalledWith(
buffer,
"application/pdf",
"outbound",
1024,
"report.pdf",
);
});
});

View File

@@ -25,6 +25,7 @@ export async function resolveOutboundAttachmentFromUrl(
media.contentType ?? undefined,
"outbound",
maxBytes,
media.fileName,
);
return { path: saved.path, contentType: saved.contentType };
}