|
1 | 1 | import { compute_cost } from "./compute-cost"; |
2 | 2 | import { decimalMultiply } from "@cocalc/util/stripe/calc"; |
3 | 3 |
|
4 | | -describe("use the compute-cost function with v1 pricing, no version, and a test version to compute the price of a license", () => { |
| 4 | +const MONTHLY_V1 = 27.15; |
| 5 | + |
| 6 | +describe("compute-cost v1 pricing", () => { |
5 | 7 | // This is a monthly business subscription for 3 projects with 1 cpu, 2 GB ram and 3 GB disk, |
6 | 8 | // using v1 pricing. On the website right now it says this should cost: |
7 | 9 | // "Cost: USD $27.15 monthly USD $9.05 per project" |
8 | | - const monthly1 = 27.15; |
| 10 | + const monthly1 = MONTHLY_V1; |
9 | 11 | const info1 = { |
10 | 12 | version: "1", |
11 | 13 | end: new Date("2024-01-06T22:00:02.582Z"), |
@@ -103,3 +105,53 @@ describe("a couple more consistency checks with prod", () => { |
103 | 105 | expect(cost.cost).toBe(amount); |
104 | 106 | }); |
105 | 107 | }); |
| 108 | + |
| 109 | +describe("compute-cost v3 pricing", () => { |
| 110 | + // This is a monthly business subscription for 3 projects with 1 cpu, 2 GB ram and 3 GB disk, |
| 111 | + // using v3 pricing. |
| 112 | + const monthly3 = 31.5; |
| 113 | + const info1 = { |
| 114 | + version: "3", |
| 115 | + end: new Date("2024-01-06T22:00:02.582Z"), |
| 116 | + type: "quota", |
| 117 | + user: "business", |
| 118 | + boost: false, |
| 119 | + start: new Date("2023-12-05T17:15:55.781Z"), |
| 120 | + upgrade: "custom", |
| 121 | + quantity: 3, |
| 122 | + account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede", |
| 123 | + custom_cpu: 1, |
| 124 | + custom_ram: 2, |
| 125 | + custom_disk: 3, |
| 126 | + subscription: "monthly", |
| 127 | + custom_member: true, |
| 128 | + custom_uptime: "short", |
| 129 | + custom_dedicated_cpu: 0, |
| 130 | + custom_dedicated_ram: 0, |
| 131 | + } as const; |
| 132 | + |
| 133 | + it("computes the cost", () => { |
| 134 | + const cost1 = compute_cost(info1); |
| 135 | + expect(decimalMultiply(cost1.cost_sub_month, cost1.quantity)).toBe( |
| 136 | + monthly3, |
| 137 | + ); |
| 138 | + }); |
| 139 | + |
| 140 | + it("version 1 is the default", () => { |
| 141 | + const info = { ...info1 }; |
| 142 | + // @ts-ignore |
| 143 | + delete info["version"]; |
| 144 | + const cost = compute_cost(info); |
| 145 | + expect(decimalMultiply(cost.cost_sub_month, cost.quantity)).toBe( |
| 146 | + MONTHLY_V1, |
| 147 | + ); |
| 148 | + }); |
| 149 | + |
| 150 | + it("computes correct cost with a different version of pricing params", () => { |
| 151 | + const info = { ...info1 }; |
| 152 | + // @ts-ignore |
| 153 | + info.version = "test_1"; |
| 154 | + const cost = compute_cost(info); |
| 155 | + expect(decimalMultiply(cost.cost_sub_month, cost.quantity)).toBe(54.3); |
| 156 | + }); |
| 157 | +}); |
0 commit comments