package domain import "testing" func TestThresholdsBand(t *testing.T) { tt := DefaultThresholds() // 30/60/85 cases := map[int]string{ 0: "low", 15: "low", 29: "low", 30: "medium", 45: "medium", 59: "medium", 60: "high", 70: "high", 84: "high", 85: "block", 99: "block", 100: "block", } for score, want := range cases { if got := tt.Band(score); got != want { t.Errorf("Band(%d) = %q, want %q", score, got, want) } } } func TestThresholdsValid(t *testing.T) { ok := []FraudThresholds{ {0, 0, 0}, {30, 60, 85}, {10, 50, 90}, {50, 50, 50}, // equality at every boundary is allowed {100, 100, 100}, } for _, th := range ok { if err := th.Valid(); err != nil { t.Errorf("expected %+v to be valid, got %v", th, err) } } bad := []FraudThresholds{ {60, 30, 85}, // medium > high {30, 85, 60}, // high > block {-1, 30, 60}, // negative {30, 60, 101}, } for _, th := range bad { if err := th.Valid(); err == nil { t.Errorf("expected %+v to be invalid", th) } } } func TestParseAllowlistCIDR(t *testing.T) { cases := []struct { in, want string ok bool }{ {"203.0.113.0/24", "203.0.113.0/24", true}, {"203.0.113.42", "203.0.113.42/32", true}, // bare IPv4 → /32 {"2001:db8::/32", "2001:db8::/32", true}, {"::1", "::1/128", true}, // bare IPv6 → /128 {"not-an-ip", "", false}, {"", "", false}, {"999.0.0.0/24", "", false}, } for _, tc := range cases { got, _, err := ParseAllowlistCIDR(tc.in) if tc.ok { if err != nil { t.Errorf("ParseAllowlistCIDR(%q) unexpected err: %v", tc.in, err) continue } if got != tc.want { t.Errorf("ParseAllowlistCIDR(%q) = %q, want %q", tc.in, got, tc.want) } } else if err == nil { t.Errorf("ParseAllowlistCIDR(%q) should have rejected", tc.in) } } } func TestFraudFeedbackValid(t *testing.T) { for _, v := range []string{"legitimate", "suspicious"} { if err := (FraudFeedback{Verdict: v}).Valid(); err != nil { t.Errorf("verdict %q should be valid: %v", v, err) } } for _, v := range []string{"", "fraud", "ok", "LEGITIMATE"} { if err := (FraudFeedback{Verdict: v}).Valid(); err == nil { t.Errorf("verdict %q should be invalid", v) } } }