package api import "testing" func TestFingerprintsSimilar(t *testing.T) { const ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_2) AppleWebKit/605" other := "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537" tests := []struct { name string stored, current map[string]any want bool }{ { name: "identical UA, different IPs counts as same device", stored: map[string]any{"user_agent": ua, "accept_language": "en"}, current: map[string]any{"user_agent": ua, "accept_language": "fr"}, want: true, }, { name: "different UA never matches", stored: map[string]any{"user_agent": ua}, current: map[string]any{"user_agent": other}, want: false, }, { name: "missing UA on current side is treated as mismatch", stored: map[string]any{"user_agent": ua}, current: map[string]any{}, want: false, }, { name: "missing UA on stored side is treated as mismatch", stored: map[string]any{}, current: map[string]any{"user_agent": ua}, want: false, }, { name: "both nil is mismatch (conservative default)", stored: nil, current: nil, want: false, }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { if got := fingerprintsSimilar(tc.stored, tc.current); got != tc.want { t.Errorf("fingerprintsSimilar = %v, want %v", got, tc.want) } }) } }