| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import type { WorkspaceDetach } from "@g1t/contracts"; |
| 5 | |
| 6 | import { detachChanges, parseExclude } from "./test-detach.ts"; |
| 7 | |
| 8 | const nothing: WorkspaceDetach = { |
| 9 | workspace: "acme", |
| 10 | done: false, |
| 11 | customer: false, |
| 12 | card: null, |
| 13 | card_cached: false, |
| 14 | subscriptions: 0, |
| 15 | card_checks: 0, |
| 16 | checkouts: 0, |
| 17 | ai_reload: false, |
| 18 | autopay_cleared: false, |
| 19 | invoices_voided: 0, |
| 20 | months_skipped: [], |
| 21 | credit_grants_closed: 0, |
| 22 | credit_closed_micros: 0, |
| 23 | payments_reversed_micros: 0, |
| 24 | plan_payments_reversed_micros: 0, |
| 25 | written_off_micros: 0, |
| 26 | balance_before_micros: 0, |
| 27 | balance_after_micros: 0, |
| 28 | stripe_canceled: 0, |
| 29 | stripe_errors: [], |
| 30 | pending_months_marked: 0, |
| 31 | pending_marked_micros: 0, |
| 32 | pending_baselined: 0, |
| 33 | pending_baselined_micros: 0, |
| 34 | plan_credit_cleared_micros: 0, |
| 35 | dispute_owed_cleared_micros: 0, |
| 36 | disputes_closed: 0, |
| 37 | }; |
| 38 | |
| 39 | test("the exclusion list reads commas, spaces and case alike, once each", () => { |
| 40 | assert.deepEqual(parseExclude(" Syntaqx, flagon-io syntaqx\nacme "), ["syntaqx", "flagon-io", "acme"]); |
| 41 | assert.deepEqual(parseExclude(""), []); |
| 42 | }); |
| 43 | |
| 44 | test("a detach says each change it makes, and nothing when there is none", () => { |
| 45 | assert.deepEqual(detachChanges(nothing), []); |
| 46 | const lines = detachChanges({ |
| 47 | ...nothing, |
| 48 | customer: true, |
| 49 | card: "visa 4242", |
| 50 | card_cached: true, |
| 51 | subscriptions: 1, |
| 52 | card_checks: 1, |
| 53 | months_skipped: ["2026-08", "2026-09"], |
| 54 | credit_grants_closed: 1, |
| 55 | credit_closed_micros: 15_000_000, |
| 56 | payments_reversed_micros: 55_000_000, |
| 57 | written_off_micros: 35_000_000, |
| 58 | stripe_errors: ["sub_1: no such subscription"], |
| 59 | }); |
| 60 | assert.deepEqual(lines, [ |
| 61 | "Customer and card visa 4242 forgotten", |
| 62 | "1 plan canceled", |
| 63 | "1 card check removed (trial kept)", |
| 64 | "2026-08, 2026-09 closed as skipped", |
| 65 | "1 AI credit grant closed ($15.00 unused)", |
| 66 | "$55.00 of test payments reversed", |
| 67 | "$35.00 owed written off as goodwill", |
| 68 | "Stripe refused: sub_1: no such subscription", |
| 69 | ]); |
| 70 | }); |
| 71 | |
| 72 | test("a detach says what metered usage, included usage and test disputes it let go", () => { |
| 73 | const lines = detachChanges({ |
| 74 | ...nothing, |
| 75 | pending_months_marked: 2, |
| 76 | pending_marked_micros: 1_200_000, |
| 77 | pending_baselined: 1, |
| 78 | pending_baselined_micros: 300_000, |
| 79 | plan_credit_cleared_micros: 4_000_000, |
| 80 | dispute_owed_cleared_micros: 46_400_000, |
| 81 | disputes_closed: 1, |
| 82 | }); |
| 83 | assert.deepEqual(lines, [ |
| 84 | "2 metered figures of past months never charged ($1.20)", |
| 85 | "This month's 1 metered figure so far never charged ($0.30)", |
| 86 | "$4.00 of this month's included usage restored", |
| 87 | "$46.40 owed for lost test disputes cleared", |
| 88 | "1 open test dispute closed", |
| 89 | ]); |
| 90 | }); |