CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/licenses/purchase/compute-cost.test.ts
Views: 923
1
import { compute_cost } from "./compute-cost";
2
import { decimalMultiply } from "@cocalc/util/stripe/calc";
3
4
describe("use the compute-cost function with v1 pricing, no version, and a test version to compute the price of a license", () => {
5
// This is a monthly business subscription for 3 projects with 1 cpu, 2 GB ram and 3 GB disk,
6
// using v1 pricing. On the website right now it says this should cost:
7
// "Cost: USD $27.15 monthly USD $9.05 per project"
8
const monthly1 = 27.15;
9
const info1 = {
10
version: "1",
11
end: new Date("2024-01-06T22:00:02.582Z"),
12
type: "quota",
13
user: "business",
14
boost: false,
15
start: new Date("2023-12-05T17:15:55.781Z"),
16
upgrade: "custom",
17
quantity: 3,
18
account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede",
19
custom_cpu: 1,
20
custom_ram: 2,
21
custom_disk: 3,
22
subscription: "monthly",
23
custom_member: true,
24
custom_uptime: "short",
25
custom_dedicated_cpu: 0,
26
custom_dedicated_ram: 0,
27
} as const;
28
29
it("computes the cost", () => {
30
const cost1 = compute_cost(info1);
31
expect(decimalMultiply(cost1.cost_sub_month, cost1.quantity)).toBe(
32
monthly1,
33
);
34
});
35
36
it("computes correct cost when version not given (since version 1 is the default)", () => {
37
const info = { ...info1 };
38
// @ts-ignore
39
delete info["version"];
40
const cost = compute_cost(info);
41
expect(decimalMultiply(cost.cost_sub_month, cost.quantity)).toBe(monthly1);
42
});
43
44
it("computes correct cost with a different version of pricing params", () => {
45
const info = { ...info1 };
46
// @ts-ignore
47
info.version = "test_1";
48
const cost = compute_cost(info);
49
expect(decimalMultiply(cost.cost_sub_month, cost.quantity)).toBe(54.3);
50
});
51
});
52
53
describe("a couple more consistency checks with prod", () => {
54
// each price below comes from just configuring this on prod
55
56
it("computes the cost of a yearly academic license sub", () => {
57
const yearly = 307.08; // from prod store
58
const info = {
59
version: "1",
60
end: new Date("2024-01-06T22:00:02.582Z"),
61
type: "quota",
62
user: "academic",
63
boost: false,
64
start: new Date("2023-12-05T17:15:55.781Z"),
65
upgrade: "custom",
66
quantity: 3,
67
account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede",
68
custom_cpu: 2,
69
custom_ram: 2,
70
custom_disk: 3,
71
subscription: "yearly",
72
custom_member: true,
73
custom_uptime: "short",
74
custom_dedicated_cpu: 0,
75
custom_dedicated_ram: 0,
76
} as const;
77
const cost = compute_cost(info);
78
expect(decimalMultiply(cost.cost_sub_year, cost.quantity)).toBe(yearly);
79
});
80
81
it("computes the cost of a specific period academic license", () => {
82
const amount = 29.64; // from prod store
83
const info = {
84
version: "1",
85
start: new Date("2024-08-01T00:00:00.000Z"),
86
type: "quota",
87
user: "academic",
88
boost: false,
89
end: new Date("2024-08-31T00:00:00.000Z"),
90
upgrade: "custom",
91
quantity: 3,
92
account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede",
93
custom_cpu: 2,
94
custom_ram: 2,
95
custom_disk: 3,
96
subscription: "no",
97
custom_member: true,
98
custom_uptime: "short",
99
custom_dedicated_cpu: 0,
100
custom_dedicated_ram: 0,
101
} as const;
102
const cost = compute_cost(info);
103
expect(cost.cost).toBe(amount);
104
});
105
});
106
107