| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH, dailyCap, freeMonthlyBytes, overCap, overCapMessage, sizeOf } from "./quota.ts"; |
| 5 | |
| 6 | test("a free workspace's project sends a thirtieth of 1 GB a day", () => { |
| 7 | assert.equal(freeMonthlyBytes(undefined), DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH); |
| 8 | assert.equal(freeMonthlyBytes(" "), DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH); |
| 9 | assert.equal(freeMonthlyBytes("3000"), 3000); |
| 10 | assert.equal(freeMonthlyBytes("0"), 0); |
| 11 | assert.equal(dailyCap(3000), 100); |
| 12 | assert.equal(dailyCap(0), null); |
| 13 | assert.equal(dailyCap(DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH), 35_791_395); |
| 14 | }); |
| 15 | |
| 16 | test("past the day's share is over, and no cap never is", () => { |
| 17 | assert.equal(overCap(90, 10, 100), false); |
| 18 | assert.equal(overCap(90, 11, 100), true); |
| 19 | assert.equal(overCap(1e12, 1e12, null), false); |
| 20 | assert.match(overCapMessage(35_791_395), /its 34 MB for today/); |
| 21 | // A held workspace's projects take nothing. |
| 22 | assert.equal(overCap(0, 1, 0), true); |
| 23 | assert.match(overCapMessage(0), /put a hold on/); |
| 24 | }); |
| 25 | |
| 26 | test("a row counts as what is kept of it", () => { |
| 27 | assert.equal(sizeOf({ body: "hello" }), '{"body":"hello"}'.length); |
| 28 | assert.equal(sizeOf(undefined), 0); |
| 29 | }); |