feat(platform): expose source consistency

This commit is contained in:
lingniu
2026-07-04 04:01:33 +08:00
parent 353b71ebbb
commit db70f58a7c
6 changed files with 195 additions and 37 deletions

View File

@@ -227,6 +227,32 @@ func TestHandlerVehicleServiceIncludesUnifiedOverview(t *testing.T) {
}
}
func TestHandlerVehicleServiceIncludesSourceConsistency(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/vehicle-service?keyword=粤AG18312", 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 VehicleDetail `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.SourceConsistency == nil {
t.Fatalf("vehicle service should include sourceConsistency: %s", rec.Body.String())
}
consistency := body.Data.SourceConsistency
if consistency.SourceCount != 2 || consistency.OnlineSourceCount != 1 || consistency.LocatedSourceCount != 2 {
t.Fatalf("sourceConsistency should summarize source coverage, got %+v", consistency)
}
if consistency.MileageDeltaKm <= 0 || consistency.SourceTimeDeltaSeconds <= 0 {
t.Fatalf("sourceConsistency should expose mileage and source time deltas, got %+v", consistency)
}
}
func TestHandlerVehicleServiceOverviewEndpoint(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()