test: add comprehensive automated test coverage
- Vitest multi-project setup (unit / integration / component) - Real-Postgres integration harness via in-process PGlite (TEST_DATABASE_URL override), migrations applied per worker; production code untouched - Unit: routing, locale, validation/Zod schemas, metadata, mail, site-theme, marquee, media, portfolio helpers, plus architecture-rule tests - Integration: Prisma data layer, API routes, and all server actions - Component: UI primitives and form components (jsdom + Testing Library) - 371 tests passing
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
getKindFromUploadFile,
|
||||
inferMediaKindFromFileName,
|
||||
inferMediaKindFromMimeType,
|
||||
} from "@/lib/media-service";
|
||||
|
||||
describe("inferMediaKindFromMimeType", () => {
|
||||
it("classifies image mime types as IMAGE", () => {
|
||||
expect(inferMediaKindFromMimeType("image/png")).toBe("IMAGE");
|
||||
expect(inferMediaKindFromMimeType("image/svg+xml")).toBe("IMAGE");
|
||||
expect(inferMediaKindFromMimeType("image/gif")).toBe("IMAGE");
|
||||
});
|
||||
|
||||
it("classifies everything else as DOCUMENT", () => {
|
||||
expect(inferMediaKindFromMimeType("application/pdf")).toBe("DOCUMENT");
|
||||
expect(inferMediaKindFromMimeType(null)).toBe("DOCUMENT");
|
||||
expect(inferMediaKindFromMimeType(undefined)).toBe("DOCUMENT");
|
||||
expect(inferMediaKindFromMimeType("")).toBe("DOCUMENT");
|
||||
});
|
||||
});
|
||||
|
||||
describe("inferMediaKindFromFileName", () => {
|
||||
it("treats known image extensions as IMAGE (case-insensitive)", () => {
|
||||
for (const name of ["a.gif", "a.jpg", "a.jpeg", "a.PNG", "a.webp", "a.SVG"]) {
|
||||
expect(inferMediaKindFromFileName(name)).toBe("IMAGE");
|
||||
}
|
||||
});
|
||||
|
||||
it("treats other extensions as DOCUMENT", () => {
|
||||
expect(inferMediaKindFromFileName("report.pdf")).toBe("DOCUMENT");
|
||||
expect(inferMediaKindFromFileName("noext")).toBe("DOCUMENT");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getKindFromUploadFile", () => {
|
||||
it("derives IMAGE from an image mime type", () => {
|
||||
const file = new File([new Uint8Array([1])], "logo.png", { type: "image/png" });
|
||||
expect(getKindFromUploadFile(file)).toBe("IMAGE");
|
||||
});
|
||||
|
||||
it("derives DOCUMENT from a pdf mime type", () => {
|
||||
const file = new File([new Uint8Array([1])], "doc.pdf", { type: "application/pdf" });
|
||||
expect(getKindFromUploadFile(file)).toBe("DOCUMENT");
|
||||
});
|
||||
|
||||
it("falls back to DOCUMENT for unknown mime types", () => {
|
||||
const file = new File([new Uint8Array([1])], "thing.bin", { type: "application/octet-stream" });
|
||||
expect(getKindFromUploadFile(file)).toBe("DOCUMENT");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user