feat(platform): expose multi-source vehicle evidence

This commit is contained in:
lingniu
2026-07-16 16:35:04 +08:00
parent 196cfa018f
commit 17c4591040
21 changed files with 1129 additions and 11 deletions

View File

@@ -373,6 +373,53 @@ func TestHandlerVehicleDetail(t *testing.T) {
}
}
func TestHandlerVehicleSourceEvidence(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/v2/vehicles/LB9A32A24R0LS1426/source-evidence?date=2026-07-16", nil)
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
}
var body struct {
Data VehicleSourceEvidence `json:"data"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatalf("response JSON should decode: %v body=%s", err, rec.Body.String())
}
if body.Data.VIN != "LB9A32A24R0LS1426" || body.Data.MileageDate != "2026-07-16" {
t.Fatalf("unexpected source evidence identity: %+v", body.Data)
}
if len(body.Data.LocationSources) != 3 || len(body.Data.MileageSources) != 2 {
t.Fatalf("source evidence should expose all mock candidates: %+v", body.Data)
}
recommended := 0
for _, source := range body.Data.LocationSources {
if source.Recommended {
recommended++
}
if strings.Contains(source.TerminalLabel, "13307795425") {
t.Fatalf("source evidence must not expose a raw terminal identifier: %+v", source)
}
}
if recommended != 1 || body.Data.RecommendedLocationProtocol != "JT808" {
t.Fatalf("source evidence should align with realtime election: %+v", body.Data)
}
if body.Data.Comparison.LocationMaxDistanceM <= 0 || body.Data.Comparison.TotalMileageDeltaKm <= 0 {
t.Fatalf("source evidence should calculate cross-source deltas: %+v", body.Data.Comparison)
}
}
func TestHandlerVehicleSourceEvidenceRejectsInvalidDate(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/v2/vehicles/LB9A32A24R0LS1426/source-evidence?date=16-07-2026", nil)
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusBadRequest || !strings.Contains(rec.Body.String(), "INVALID_DATE") {
t.Fatalf("unexpected invalid date response: status=%d body=%s", rec.Code, rec.Body.String())
}
}
func TestHandlerVehicleServiceCanonicalEndpoint(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()