Files
Crussell/backend/handlers/payments/validators_test.go
T
popertots 738f6b6a51 Expand payment test coverage: lock contention, nonce-direct, provisional rows, GDPR scrub, validators
Close the coverage-gap round: terminal CreateCheckout-failure marks the provisional row failed, GetCheckoutStatus reference_id mismatch 400, deadline wire shape, concurrent loyalty redemption 409, delete_guest_user + stale-guest saved-card scrubbing, ValidateAmount and isTokenLike direct units, bounded try-lock timeout, buildSplitRecords tip-overflow, and concurrent same-key dedup for gift card / booking / tip / checkout.
2026-08-22 00:34:49 +01:00

36 lines
1.0 KiB
Go

//go:build test && dev
package payments
import (
"testing"
"github.com/stretchr/testify/require"
)
// TestValidateAmount covers the amount validator used by every payment
// handler: positive and within the £10,000 (1,000,000 pence) cap. Amounts are
// integer pence, so sub-penny "precision" is impossible by construction.
func TestValidateAmount(t *testing.T) {
t.Parallel()
valid := []int64{1, 500, 10000, 999999, 1000000}
for _, amount := range valid {
require.NoErrorf(t, ValidateAmount(amount), "expected %d to be a valid amount", amount)
}
invalid := []int64{0, -1, -500, 1000001}
for _, amount := range invalid {
require.Errorf(t, ValidateAmount(amount), "expected %d to be rejected", amount)
}
// The cap is exclusive: exactly £10,000 (1,000,000 pence) is allowed, one
// penny more is rejected.
if err := ValidateAmount(1000001); err == nil {
t.Error("expected amount above £10,000 cap to be rejected")
}
if err := ValidateAmount(1000000); err != nil {
t.Errorf("expected exactly £10,000 to be allowed, got %v", err)
}
}