86 lines
2.4 KiB
TypeScript
86 lines
2.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { calculateStorageCapacity, STORAGE_BYTES_PER_GB } from "./storage-capacity.js";
|
|
|
|
describe("calculateStorageCapacity", () => {
|
|
it("combines base, extra-seat, and recurring add-on storage", () => {
|
|
expect(
|
|
calculateStorageCapacity({
|
|
planCode: "starter",
|
|
officeSeatQuantity: 4,
|
|
fieldSeatQuantity: 6,
|
|
storageAddOnCodes: ["storage_100gb", "storage_500gb"],
|
|
}),
|
|
).toEqual({
|
|
planCode: "starter",
|
|
includedStorageGb: 100,
|
|
additionalSeatStorageGb: 30,
|
|
addOnStorageGb: 600,
|
|
totalStorageGb: 730,
|
|
totalStorageBytes: 730 * STORAGE_BYTES_PER_GB,
|
|
});
|
|
});
|
|
|
|
it("does not grant extra storage for seats already included in the package", () => {
|
|
expect(
|
|
calculateStorageCapacity({
|
|
planCode: "pro",
|
|
officeSeatQuantity: 5,
|
|
fieldSeatQuantity: 15,
|
|
}),
|
|
).toMatchObject({
|
|
includedStorageGb: 500,
|
|
additionalSeatStorageGb: 0,
|
|
addOnStorageGb: 0,
|
|
totalStorageGb: 500,
|
|
});
|
|
});
|
|
|
|
it("grows the shared pool with every additional paid license at the plan rate", () => {
|
|
expect(
|
|
calculateStorageCapacity({
|
|
planCode: "pro",
|
|
officeSeatQuantity: 6,
|
|
fieldSeatQuantity: 16,
|
|
}),
|
|
).toMatchObject({
|
|
includedStorageGb: 500,
|
|
additionalSeatStorageGb: 40,
|
|
totalStorageGb: 540,
|
|
});
|
|
expect(
|
|
calculateStorageCapacity({
|
|
planCode: "business",
|
|
officeSeatQuantity: 11,
|
|
fieldSeatQuantity: 31,
|
|
}),
|
|
).toMatchObject({
|
|
includedStorageGb: 2_000,
|
|
additionalSeatStorageGb: 80,
|
|
totalStorageGb: 2_080,
|
|
});
|
|
});
|
|
|
|
it("rejects unknown plans, add-ons, and duplicate add-ons", () => {
|
|
expect(() =>
|
|
calculateStorageCapacity({ planCode: "unknown", officeSeatQuantity: 1, fieldSeatQuantity: 0 }),
|
|
).toThrow("Unknown billing plan");
|
|
expect(() =>
|
|
calculateStorageCapacity({
|
|
planCode: "starter",
|
|
officeSeatQuantity: 1,
|
|
fieldSeatQuantity: 0,
|
|
storageAddOnCodes: ["storage_unknown"],
|
|
}),
|
|
).toThrow("Unknown storage add-on");
|
|
expect(() =>
|
|
calculateStorageCapacity({
|
|
planCode: "starter",
|
|
officeSeatQuantity: 1,
|
|
fieldSeatQuantity: 0,
|
|
storageAddOnCodes: ["storage_100gb", "storage_100gb"],
|
|
}),
|
|
).toThrow("must be unique");
|
|
});
|
|
});
|