scan-flow: geolocation scan, location-aware SMS throttle (log sender), finder contact, sms_enabled toggle, branding — 19/19 phase-2 scenarios pass

This commit is contained in:
2026-08-05 18:23:34 +10:00
parent 4666751e92
commit c2fa04afd0
26 changed files with 698 additions and 43 deletions

View File

@@ -0,0 +1,52 @@
package sms
import (
"math"
"testing"
)
func TestHaversineMeters(t *testing.T) {
cases := []struct {
name string
lat1, lng1 float64
lat2, lng2 float64
wantMeters float64
tolerancePct float64
}{
{"same point", -33.86, 151.21, -33.86, 151.21, 0, 0},
{"Sydney CBD to Parramatta (~20km)", -33.8688, 151.2093, -33.8125, 151.0011, 20200, 0.02},
{"~250m at Sydney latitude", -33.86, 151.21, -33.86, 151.2128, 250, 0.20},
{"antipodal-ish long distance", 0, 0, 0, 180, 20037500, 0.01},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := HaversineMeters(tc.lat1, tc.lng1, tc.lat2, tc.lng2)
if tc.wantMeters == 0 {
if got > 1 {
t.Fatalf("same point: got %.1f m, want ~0", got)
}
return
}
diff := math.Abs(got-tc.wantMeters) / tc.wantMeters
if diff > tc.tolerancePct {
t.Fatalf("got %.1f m, want ~%.1f m (error %.1f%%)", got, tc.wantMeters, diff*100)
}
})
}
}
func TestNormalizeAU(t *testing.T) {
cases := []struct{ in, want string }{
{"+61432374487", "61432374487"},
{"0432374487", "61432374487"},
{"61432374487", "61432374487"},
{"+61 432 374 487", "61432374487"},
{"(04) 3237 4487", "61432374487"},
{"", ""},
}
for _, tc := range cases {
if got := NormalizeAU(tc.in); got != tc.want {
t.Errorf("NormalizeAU(%q) = %q, want %q", tc.in, got, tc.want)
}
}
}