summaryrefslogtreecommitdiff
path: root/internal/billing/operations_test.go
diff options
context:
space:
mode:
authorChia <Chia@93.nz>2026-08-05 22:01:29 +1200
committerChia <Chia@93.nz>2026-08-05 22:07:50 +1200
commiteadb2ffe85c43cf6fc741c9823cd28eedb4a844c (patch)
tree1aba2536d57360da403aa35c9ced58b615c7064e /internal/billing/operations_test.go
parentcd0dd91ab93653631904f2ea0e574ccde6d60339 (diff)
feat: harden prepaid billing and commercial operations
Diffstat (limited to 'internal/billing/operations_test.go')
-rw-r--r--internal/billing/operations_test.go36
1 files changed, 36 insertions, 0 deletions
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")
+ }
+}