Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/src/packages/util/licenses/purchase/compute-cost.test.ts
Views: 923
import { compute_cost } from "./compute-cost";1import { decimalMultiply } from "@cocalc/util/stripe/calc";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(decimalMultiply(cost1.cost_sub_month, cost1.quantity)).toBe(31monthly1,32);33});3435it("computes correct cost when version not given (since version 1 is the default)", () => {36const info = { ...info1 };37// @ts-ignore38delete info["version"];39const cost = compute_cost(info);40expect(decimalMultiply(cost.cost_sub_month, cost.quantity)).toBe(monthly1);41});4243it("computes correct cost with a different version of pricing params", () => {44const info = { ...info1 };45// @ts-ignore46info.version = "test_1";47const cost = compute_cost(info);48expect(decimalMultiply(cost.cost_sub_month, cost.quantity)).toBe(54.3);49});50});5152describe("a couple more consistency checks with prod", () => {53// each price below comes from just configuring this on prod5455it("computes the cost of a yearly academic license sub", () => {56const yearly = 307.08; // from prod store57const info = {58version: "1",59end: new Date("2024-01-06T22:00:02.582Z"),60type: "quota",61user: "academic",62boost: false,63start: new Date("2023-12-05T17:15:55.781Z"),64upgrade: "custom",65quantity: 3,66account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede",67custom_cpu: 2,68custom_ram: 2,69custom_disk: 3,70subscription: "yearly",71custom_member: true,72custom_uptime: "short",73custom_dedicated_cpu: 0,74custom_dedicated_ram: 0,75} as const;76const cost = compute_cost(info);77expect(decimalMultiply(cost.cost_sub_year, cost.quantity)).toBe(yearly);78});7980it("computes the cost of a specific period academic license", () => {81const amount = 29.64; // from prod store82const info = {83version: "1",84start: new Date("2024-08-01T00:00:00.000Z"),85type: "quota",86user: "academic",87boost: false,88end: new Date("2024-08-31T00:00:00.000Z"),89upgrade: "custom",90quantity: 3,91account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede",92custom_cpu: 2,93custom_ram: 2,94custom_disk: 3,95subscription: "no",96custom_member: true,97custom_uptime: "short",98custom_dedicated_cpu: 0,99custom_dedicated_ram: 0,100} as const;101const cost = compute_cost(info);102expect(cost.cost).toBe(amount);103});104});105106107