feat(platform): expose missing vehicle source slots
This commit is contained in:
@@ -201,7 +201,7 @@ func TestHandlerVehicleServiceIncludesVehicleLevelStatus(t *testing.T) {
|
||||
if body.Data.ServiceStatus.Status != "degraded" || body.Data.ServiceStatus.Title != "部分来源离线" {
|
||||
t.Fatalf("vehicle service should summarize partial source health, got %+v body=%s", body.Data.ServiceStatus, rec.Body.String())
|
||||
}
|
||||
if body.Data.ServiceStatus.OnlineSourceCount != 1 || body.Data.ServiceStatus.SourceCount != 2 {
|
||||
if body.Data.ServiceStatus.OnlineSourceCount != 1 || body.Data.ServiceStatus.SourceCount != 3 {
|
||||
t.Fatalf("vehicle service should expose source counts, got %+v body=%s", body.Data.ServiceStatus, rec.Body.String())
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func TestHandlerVehicleServiceIncludesUnifiedOverview(t *testing.T) {
|
||||
if overview.VIN != "LB9A32A24R0LS1426" || overview.Plate != "粤AG18312" {
|
||||
t.Fatalf("overview should expose canonical vehicle identity, got %+v", overview)
|
||||
}
|
||||
if overview.SourceCount != 2 || overview.OnlineSourceCount != 1 || overview.CoverageStatus != "partial" {
|
||||
if overview.SourceCount != 3 || overview.OnlineSourceCount != 1 || overview.CoverageStatus != "partial" {
|
||||
t.Fatalf("overview should summarize source coverage, got %+v", overview)
|
||||
}
|
||||
if overview.LastSeen == "" || overview.PrimaryProtocol == "" {
|
||||
@@ -256,7 +256,7 @@ func TestHandlerVehicleServiceIncludesSourceConsistency(t *testing.T) {
|
||||
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 {
|
||||
if consistency.SourceCount != 3 || consistency.OnlineSourceCount != 1 || consistency.LocatedSourceCount != 2 {
|
||||
t.Fatalf("sourceConsistency should summarize source coverage, got %+v", consistency)
|
||||
}
|
||||
if consistency.MileageDeltaKm <= 0 || consistency.SourceTimeDeltaSeconds <= 0 {
|
||||
@@ -270,6 +270,35 @@ func TestHandlerVehicleServiceIncludesSourceConsistency(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerVehicleServiceExposesMissingSourceSlots(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())
|
||||
}
|
||||
byProtocol := map[string]VehicleSourceStatus{}
|
||||
for _, source := range body.Data.SourceStatus {
|
||||
byProtocol[source.Protocol] = source
|
||||
}
|
||||
for _, protocol := range []string{"GB32960", "JT808", "YUTONG_MQTT"} {
|
||||
if _, ok := byProtocol[protocol]; !ok {
|
||||
t.Fatalf("vehicle service should expose expected source slot %s, got %+v", protocol, body.Data.SourceStatus)
|
||||
}
|
||||
}
|
||||
mqtt := byProtocol["YUTONG_MQTT"]
|
||||
if mqtt.Online || mqtt.HasRealtime || mqtt.HasHistory || mqtt.HasRaw || mqtt.HasMileage || mqtt.LastSeen != "" {
|
||||
t.Fatalf("missing MQTT source should be an empty coverage slot, got %+v", mqtt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerVehicleServiceOverviewEndpoint(t *testing.T) {
|
||||
handler := NewHandler(NewService(NewMockStore()))
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
Reference in New Issue
Block a user