|
| 1 | +import { compute_cost } from "./compute-cost"; |
| 2 | +import { round2up } from "@cocalc/util/misc"; |
| 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(round2up(cost1.cost_sub_month * cost1.quantity)).toBe(monthly1); |
| 32 | + }); |
| 33 | + |
| 34 | + it("computes correct cost when version not given (since version 1 is the default)", () => { |
| 35 | + const info = { ...info1 }; |
| 36 | + // @ts-ignore |
| 37 | + delete info["version"]; |
| 38 | + const cost = compute_cost(info); |
| 39 | + expect(round2up(cost.cost_sub_month * cost.quantity)).toBe(monthly1); |
| 40 | + }); |
| 41 | + |
| 42 | + it("computes correct cost with a different version of pricing params", () => { |
| 43 | + const info = { ...info1 }; |
| 44 | + // @ts-ignore |
| 45 | + info.version = "test_1"; |
| 46 | + const cost = compute_cost(info); |
| 47 | + expect(round2up(cost.cost_sub_month * cost.quantity)).toBe(54.29); |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +describe("a couple more consistency checks with prod", () => { |
| 52 | + // each price below comes from just configuring this on prod |
| 53 | + |
| 54 | + it("computes the cost of a yearly academic license sub", () => { |
| 55 | + const yearly = 306.98; // from prod store |
| 56 | + const info = { |
| 57 | + version: "1", |
| 58 | + end: new Date("2024-01-06T22:00:02.582Z"), |
| 59 | + type: "quota", |
| 60 | + user: "academic", |
| 61 | + boost: false, |
| 62 | + start: new Date("2023-12-05T17:15:55.781Z"), |
| 63 | + upgrade: "custom", |
| 64 | + quantity: 3, |
| 65 | + account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede", |
| 66 | + custom_cpu: 2, |
| 67 | + custom_ram: 2, |
| 68 | + custom_disk: 3, |
| 69 | + subscription: "yearly", |
| 70 | + custom_member: true, |
| 71 | + custom_uptime: "short", |
| 72 | + custom_dedicated_cpu: 0, |
| 73 | + custom_dedicated_ram: 0, |
| 74 | + } as const; |
| 75 | + const cost = compute_cost(info); |
| 76 | + expect(round2up(cost.cost_sub_year * cost.quantity)).toBe(yearly); |
| 77 | + }); |
| 78 | + |
| 79 | + it("computes the cost of a specific period academic license", () => { |
| 80 | + const amount = 29.61; // from prod store |
| 81 | + const info = { |
| 82 | + version: "1", |
| 83 | + start: new Date("2024-08-01T00:00:00.000Z"), |
| 84 | + type: "quota", |
| 85 | + user: "academic", |
| 86 | + boost: false, |
| 87 | + end: new Date("2024-08-31T00:00:00.000Z"), |
| 88 | + upgrade: "custom", |
| 89 | + quantity: 3, |
| 90 | + account_id: "6aae57c6-08f1-4bb5-848b-3ceb53e61ede", |
| 91 | + custom_cpu: 2, |
| 92 | + custom_ram: 2, |
| 93 | + custom_disk: 3, |
| 94 | + subscription: "no", |
| 95 | + custom_member: true, |
| 96 | + custom_uptime: "short", |
| 97 | + custom_dedicated_cpu: 0, |
| 98 | + custom_dedicated_ram: 0, |
| 99 | + } as const; |
| 100 | + const cost = compute_cost(info); |
| 101 | + expect(round2up(cost.cost)).toBe(amount); |
| 102 | + }); |
| 103 | +}); |
0 commit comments