From eadb2ffe85c43cf6fc741c9823cd28eedb4a844c Mon Sep 17 00:00:00 2001 From: Chia Date: Wed, 5 Aug 2026 22:01:29 +1200 Subject: feat: harden prepaid billing and commercial operations --- internal/billing/operations_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 internal/billing/operations_test.go (limited to 'internal/billing/operations_test.go') diff --git a/internal/billing/operations_test.go b/internal/billing/operations_test.go new file mode 100644 index 0000000..46bedeb --- /dev/null +++ b/internal/billing/operations_test.go @@ -0,0 +1,36 @@ +package billing + +import ( + "testing" + "time" +) + +func TestOperationalStatusReadiness(t *testing.T) { + now := time.Now().UTC() + recent := now.Add(-time.Minute) + clean := OperationalStatus{ + StripeEnabled: true, ReconciliationStatus: "clean", ReconciliationCompletedAt: &recent, + } + if !clean.Ready(now) { + t.Fatal("clean operational state should be ready") + } + oldWebhook := now.Add(-6 * time.Minute) + stuckWebhook := clean + stuckWebhook.UnprocessedWebhooks = 1 + stuckWebhook.OldestUnprocessedWebhook = &oldWebhook + if stuckWebhook.Ready(now) { + t.Fatal("stuck webhook should fail readiness") + } + freshRefund := now.Add(-time.Minute) + processingRefund := clean + processingRefund.RefundBacklog = 1 + processingRefund.OldestRefund = &freshRefund + if !processingRefund.Ready(now) { + t.Fatal("fresh refund operation should remain ready during its processing window") + } + unmetered := clean + unmetered.UnmeteredSuccesses = 1 + if unmetered.Ready(now) { + t.Fatal("unmetered success must fail readiness") + } +} -- cgit v1.2.3