1import { describe, expect, it } from "vitest";
2import {
3 effectiveMaxFileSize,
4 effectiveStorageQuota,
5 PLAN_USAGE_LIMITS,
6} from "../../modules/files/uploads.service.js";
7
8
13
14describe("effectiveMaxFileSize (plan × usageLimits)", () => {
15 it("free plan → 50 MB", () => {
16 expect(effectiveMaxFileSize("free", null)).toBe(50 * 1024 * 1024);
17 });
18
19 it("paid plan → 500 MB", () => {
20 expect(effectiveMaxFileSize("paid", null)).toBe(500 * 1024 * 1024);
21 });
22
23 it("unknown plan falls back to free", () => {
24 expect(effectiveMaxFileSize("enterprise", null)).toBe(50 * 1024 * 1024);
25 });
26
27 it("usageLimits may only TIGHTEN (min-rule)", () => {
28 expect(effectiveMaxFileSize("paid", { maxFileSize: 10 * 1024 * 1024 })).toBe(10 * 1024 * 1024);
29
30 expect(effectiveMaxFileSize("free", { maxFileSize: 999 * 1024 * 1024 })).toBe(
31 50 * 1024 * 1024,
32 );
33 });
34
35 it("non-positive/missing overrides are ignored", () => {
36 expect(effectiveMaxFileSize("paid", { maxFileSize: 0 })).toBe(500 * 1024 * 1024);
37 expect(effectiveMaxFileSize("paid", {})).toBe(500 * 1024 * 1024);
38 });
39
40 it("never exceeds the hard ceiling (500 MB)", () => {
41 expect(effectiveMaxFileSize("paid", {})).toBeLessThanOrEqual(500 * 1024 * 1024);
42 });
43});
44
45describe("effectiveStorageQuota (plan × usageLimits)", () => {
46 it("free 1 GB, paid 10 GB", () => {
47 expect(effectiveStorageQuota("free", null)).toBe(PLAN_USAGE_LIMITS.free!.storageQuota);
48 expect(effectiveStorageQuota("paid", null)).toBe(PLAN_USAGE_LIMITS.paid!.storageQuota);
49 });
50
51 it("tightening override wins; exceeding is ignored", () => {
52 expect(effectiveStorageQuota("paid", { storageQuota: 2 * 1024 ** 3 })).toBe(2 * 1024 ** 3);
53 expect(effectiveStorageQuota("free", { storageQuota: 99 * 1024 ** 3 })).toBe(
54 1 * 1024 ** 3,
55 );
56 });
57});
58