77 lines
2.6 KiB
TypeScript
77 lines
2.6 KiB
TypeScript
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import { FileUploadPluginOptionsSchema } from "./options.js";
|
|
|
|
describe("FileUploadPluginOptionsSchema", () => {
|
|
it("applies defaults for an empty object", { timeout: 5000 }, () => {
|
|
const parsed = FileUploadPluginOptionsSchema.parse({});
|
|
expect(parsed.basePath).toBe("/uploads");
|
|
expect(parsed.singleShotLimitBytes).toBeGreaterThan(0);
|
|
expect(parsed.maxFileSizeBytes).toBeGreaterThan(0);
|
|
expect(parsed.defaultChunkSize).toBeGreaterThan(0);
|
|
expect(parsed.sessionTtlMs).toBeGreaterThan(0);
|
|
expect(parsed.deniedMimeTypes.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("rejects malformed basePath (trailing slash)", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const r = FileUploadPluginOptionsSchema.safeParse({
|
|
basePath: "/uploads/",
|
|
});
|
|
expect(r.success).toBe(false);
|
|
});
|
|
|
|
it("rejects negative limits", { timeout: 5000 }, () => {
|
|
const r = FileUploadPluginOptionsSchema.safeParse({
|
|
singleShotLimitBytes: -1,
|
|
});
|
|
expect(r.success).toBe(false);
|
|
});
|
|
|
|
it("accepts a valid storage shape", { timeout: 5000 }, () => {
|
|
const r = FileUploadPluginOptionsSchema.safeParse({
|
|
storage: { put: () => undefined },
|
|
});
|
|
expect(r.success).toBe(true);
|
|
});
|
|
|
|
it("rejects a non-conforming storage", { timeout: 5000 }, () => {
|
|
const r = FileUploadPluginOptionsSchema.safeParse({
|
|
storage: { nope: 1 },
|
|
});
|
|
expect(r.success).toBe(false);
|
|
});
|
|
|
|
it("accepts a valid sessionStore + logger", { timeout: 5000 }, () => {
|
|
const r = FileUploadPluginOptionsSchema.safeParse({
|
|
sessionStore: { create: () => undefined },
|
|
logger: {
|
|
info: () => undefined,
|
|
debug: () => undefined,
|
|
warn: () => undefined,
|
|
error: () => undefined,
|
|
},
|
|
});
|
|
expect(r.success).toBe(true);
|
|
});
|
|
|
|
it("rejects malformed logger", { timeout: 5000 }, () => {
|
|
const r = FileUploadPluginOptionsSchema.safeParse({
|
|
logger: { not: "right" },
|
|
});
|
|
expect(r.success).toBe(false);
|
|
});
|
|
|
|
it("rejects malformed sessionStore", { timeout: 5000 }, () => {
|
|
const r = FileUploadPluginOptionsSchema.safeParse({
|
|
sessionStore: { not: "right" },
|
|
});
|
|
expect(r.success).toBe(false);
|
|
});
|
|
|
|
it("accepts root basePath '/'", { timeout: 5000 }, () => {
|
|
const r = FileUploadPluginOptionsSchema.safeParse({ basePath: "/" });
|
|
expect(r.success).toBe(true);
|
|
});
|
|
});
|