import { describe, expect, it } from "vitest"; import { effectiveMaxFileSize, effectiveStorageQuota, PLAN_USAGE_LIMITS, } from "../../modules/files/uploads.service.js"; /** * TASK-0101 — effective-limit resolver (plan × usageLimits) + sniff * matching, pure functions (the acceptance criterion "a 60 MB file is 413 * on free, 201 on paid" rests on these). */ describe("effectiveMaxFileSize (plan × usageLimits)", () => { it("free plan → 50 MB", () => { expect(effectiveMaxFileSize("free", null)).toBe(50 * 1024 * 1024); }); it("paid plan → 500 MB", () => { expect(effectiveMaxFileSize("paid", null)).toBe(500 * 1024 * 1024); }); it("unknown plan falls back to free", () => { expect(effectiveMaxFileSize("enterprise", null)).toBe(50 * 1024 * 1024); }); it("usageLimits may only TIGHTEN (min-rule)", () => { expect(effectiveMaxFileSize("paid", { maxFileSize: 10 * 1024 * 1024 })).toBe(10 * 1024 * 1024); // an override ABOVE the plan default is ignored (never exceeds the plan) expect(effectiveMaxFileSize("free", { maxFileSize: 999 * 1024 * 1024 })).toBe( 50 * 1024 * 1024, ); }); it("non-positive/missing overrides are ignored", () => { expect(effectiveMaxFileSize("paid", { maxFileSize: 0 })).toBe(500 * 1024 * 1024); expect(effectiveMaxFileSize("paid", {})).toBe(500 * 1024 * 1024); }); it("never exceeds the hard ceiling (500 MB)", () => { expect(effectiveMaxFileSize("paid", {})).toBeLessThanOrEqual(500 * 1024 * 1024); }); }); describe("effectiveStorageQuota (plan × usageLimits)", () => { it("free 1 GB, paid 10 GB", () => { expect(effectiveStorageQuota("free", null)).toBe(PLAN_USAGE_LIMITS.free!.storageQuota); expect(effectiveStorageQuota("paid", null)).toBe(PLAN_USAGE_LIMITS.paid!.storageQuota); }); it("tightening override wins; exceeding is ignored", () => { expect(effectiveStorageQuota("paid", { storageQuota: 2 * 1024 ** 3 })).toBe(2 * 1024 ** 3); expect(effectiveStorageQuota("free", { storageQuota: 99 * 1024 ** 3 })).toBe( 1 * 1024 ** 3, ); }); });