mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
31 lines
912 B
Go
31 lines
912 B
Go
package referrer
|
|
|
|
import "testing"
|
|
|
|
// A referral code must be unique on sight, because the create handler reissues
|
|
// any code already taken in the namespace. A fixture that draws from a small
|
|
// dictionary satisfies "looks like a code" and not that, which is how the
|
|
// api/referrer spec asserting the server kept the code it was sent came to fail
|
|
// about one run in twenty for reasons entirely on the client side.
|
|
func TestNewCodeIsUnique(t *testing.T) {
|
|
const n = 10000
|
|
|
|
seen := make(map[string]bool, n)
|
|
for i := 0; i < n; i++ {
|
|
code := NewCode()
|
|
|
|
if len(code) != 8 {
|
|
t.Fatalf("NewCode() = %q, want 8 characters", code)
|
|
}
|
|
for _, r := range code {
|
|
if !(r >= 'A' && r <= 'Z' || r >= '0' && r <= '9') {
|
|
t.Fatalf("NewCode() = %q, want uppercase alphanumerics only", code)
|
|
}
|
|
}
|
|
if seen[code] {
|
|
t.Fatalf("NewCode() repeated %q within %d draws", code, n)
|
|
}
|
|
seen[code] = true
|
|
}
|
|
}
|