//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) } }