import { describe, expect, test } from "bun:test";
import { METERS } from "./meters";
import { DEFAULT_PLANS } from "./plans";
import {
CONTAINER_SPECS,
MARKUP,
METER_PRICES,
PACKS,
PRO_PRICE_CENTS,
containerCostPerHour,
containerPricePerHour,
creditPoolFor,
meterPriceDollars,
} from "./pricing";
describe("pricing", () => {
test("every meter has exactly one price", () => {
expect(Object.keys(METER_PRICES).toSorted()).toEqual(METERS.map((meter) => meter.id).toSorted());
for (const meter of METERS) expect(meter.microCentsPerUnit).toBe(METER_PRICES[meter.id]);
});
test("runner tiers are priced by their resources at the target markup", () => {
for (const spec of Object.values(CONTAINER_SPECS)) {
expect(containerPricePerHour(spec) / containerCostPerHour(spec)).toBeCloseTo(MARKUP, 9);
}
expect(meterPriceDollars("compute.runner", 3600)).toBeCloseTo(
containerPricePerHour(CONTAINER_SPECS["standard-1"]),
9,
);
expect(meterPriceDollars("compute.runner_xlarge", 3600)).toBeCloseTo(
containerPricePerHour(CONTAINER_SPECS["standard-4"]),
9,
);
});
test("a Pro month that uses every allowance in full still keeps the margin", () => {
let cost = 0;
for (const [meter, quantity] of Object.entries(DEFAULT_PLANS.pro.included)) {
cost += meterPriceDollars(meter as keyof typeof METER_PRICES, quantity ?? 0) / MARKUP;
}