Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/util/licenses/purchase/compute-cost.test.ts
Views: 687
import { compute_cost } from "./compute-cost";1import { round2up } from "@cocalc/util/misc";23describe("use the compute-cost function with v1 pricing, no version, and a test version to compute the price of a license", () => {4// This is a monthly business subscription for 3 projects with 1 cpu, 2 GB ram and 3 GB disk,5// using v1 pricing. On the website right now it says this should cost:6// "Cost: USD $27.15 monthly USD $9.05 per project"7const monthly1 = 27.15;8const info1 = {9version: "1",10end: new Date("2024-01-06T22:00:02.582Z"),11type: "quota",12user: "business",13boost: false,14start: new Date("2023-12-05T17:15:55.781Z"),15upgrade: "custom",16quantity: 3,17account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede",18custom_cpu: 1,19custom_ram: 2,20custom_disk: 3,21subscription: "monthly",22custom_member: true,23custom_uptime: "short",24custom_dedicated_cpu: 0,25custom_dedicated_ram: 0,26} as const;2728it("computes the cost", () => {29const cost1 = compute_cost(info1);30expect(round2up(cost1.cost_sub_month * cost1.quantity)).toBe(monthly1);31});3233it("computes correct cost when version not given (since version 1 is the default)", () => {34const info = { ...info1 };35// @ts-ignore36delete info["version"];37const cost = compute_cost(info);38expect(round2up(cost.cost_sub_month * cost.quantity)).toBe(monthly1);39});4041it("computes correct cost with a different version of pricing params", () => {42const info = { ...info1 };43// @ts-ignore44info.version = "test_1";45const cost = compute_cost(info);46expect(round2up(cost.cost_sub_month * cost.quantity)).toBe(54.29);47});48});4950describe("a couple more consistency checks with prod", () => {51// each price below comes from just configuring this on prod5253it("computes the cost of a yearly academic license sub", () => {54const yearly = 306.98; // from prod store55const info = {56version: "1",57end: new Date("2024-01-06T22:00:02.582Z"),58type: "quota",59user: "academic",60boost: false,61start: new Date("2023-12-05T17:15:55.781Z"),62upgrade: "custom",63quantity: 3,64account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede",65custom_cpu: 2,66custom_ram: 2,67custom_disk: 3,68subscription: "yearly",69custom_member: true,70custom_uptime: "short",71custom_dedicated_cpu: 0,72custom_dedicated_ram: 0,73} as const;74const cost = compute_cost(info);75expect(round2up(cost.cost_sub_year * cost.quantity)).toBe(yearly);76});7778it("computes the cost of a specific period academic license", () => {79const amount = 29.61; // from prod store80const info = {81version: "1",82start: new Date("2024-08-01T00:00:00.000Z"),83type: "quota",84user: "academic",85boost: false,86end: new Date("2024-08-31T00:00:00.000Z"),87upgrade: "custom",88quantity: 3,89account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede",90custom_cpu: 2,91custom_ram: 2,92custom_disk: 3,93subscription: "no",94custom_member: true,95custom_uptime: "short",96custom_dedicated_cpu: 0,97custom_dedicated_ram: 0,98} as const;99const cost = compute_cost(info);100expect(round2up(cost.cost)).toBe(amount);101});102});103104105