mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
feat: fix PDF mime type detection and enhance filename handling tests
Updated the mime types to include "pdf" in the application category. Enhanced the test suite for media mime types to validate filename handling for PDF files, ensuring correct extensions are maintained based on file type and name. This improves the robustness of the file handling logic in the application.
This commit is contained in:
@@ -71,6 +71,7 @@ describe("media/mime-types", () => {
|
||||
["application/zip", "zip"],
|
||||
["text/tab-separated-values", "tsv"],
|
||||
["application/zip", "zip"],
|
||||
["application/pdf", "pdf"],
|
||||
] as const;
|
||||
|
||||
for (const [mime, ext] of tests) {
|
||||
@@ -88,6 +89,7 @@ describe("media/mime-types", () => {
|
||||
["image.jpeg", "jpeg"],
|
||||
["-473Wx593H-466453554-black-MODEL.jpg", "jpg"],
|
||||
["-473Wx593H-466453554-black-MODEL.avif", "avif"],
|
||||
["file.pdf", "pdf"],
|
||||
] as const;
|
||||
|
||||
for (const [filename, ext] of tests) {
|
||||
@@ -102,4 +104,28 @@ describe("media/mime-types", () => {
|
||||
const [, ext] = getRandomizedFilename(file).split(".");
|
||||
expect(ext).toBe("jpg");
|
||||
});
|
||||
|
||||
test("getRandomizedFilename with body", async () => {
|
||||
// should keep "pdf"
|
||||
const [, ext] = getRandomizedFilename(
|
||||
new File([""], "file.pdf", { type: "application/pdf" }),
|
||||
).split(".");
|
||||
expect(ext).toBe("pdf");
|
||||
|
||||
{
|
||||
// no ext, should use "pdf" only for known formats
|
||||
const [, ext] = getRandomizedFilename(
|
||||
new File([""], "file", { type: "application/pdf" }),
|
||||
).split(".");
|
||||
expect(ext).toBe("pdf");
|
||||
}
|
||||
|
||||
{
|
||||
// wrong ext, should keep the wrong one
|
||||
const [, ext] = getRandomizedFilename(
|
||||
new File([""], "file.what", { type: "application/pdf" }),
|
||||
).split(".");
|
||||
expect(ext).toBe("what");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user