diff options
Diffstat (limited to 'internal/billing/operations_test.go')
| -rw-r--r-- | internal/billing/operations_test.go | 36 |
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") + } +} |
