feat(platform): expose missing sources per vehicle
This commit is contained in:
@@ -92,6 +92,18 @@ func TestHandlerVehicleCoverage(t *testing.T) {
|
||||
if body.Data.Items[0].ServiceStatus.Status != "degraded" {
|
||||
t.Fatalf("coverage row should expose degraded status, got %+v", body.Data.Items[0].ServiceStatus)
|
||||
}
|
||||
var rawBody struct {
|
||||
Data Page[struct {
|
||||
VIN string `json:"vin"`
|
||||
MissingProtocols []string `json:"missingProtocols"`
|
||||
}] `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &rawBody); err != nil {
|
||||
t.Fatalf("response JSON should decode missing source evidence: %v body=%s", err, rec.Body.String())
|
||||
}
|
||||
if len(rawBody.Data.Items) == 0 || !containsString(rawBody.Data.Items[0].MissingProtocols, "YUTONG_MQTT") {
|
||||
t.Fatalf("coverage row should expose missing canonical protocols, got %+v body=%s", rawBody.Data.Items, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerVehicleCoverageFiltersServiceStatus(t *testing.T) {
|
||||
|
||||
@@ -132,6 +132,7 @@ func (m *MockStore) VehicleCoverage(_ context.Context, query url.Values) (Page[V
|
||||
}
|
||||
items := make([]VehicleCoverageRow, 0, len(byVIN))
|
||||
for _, row := range byVIN {
|
||||
row.MissingProtocols = missingCanonicalProtocols(row.Protocols)
|
||||
row.ServiceStatus = buildVehicleCoverageServiceStatus(*row)
|
||||
if keepCoverageRow(*row, query) {
|
||||
items = append(items, *row)
|
||||
|
||||
@@ -55,6 +55,7 @@ type VehicleCoverageRow struct {
|
||||
Phone string `json:"phone"`
|
||||
OEM string `json:"oem"`
|
||||
Protocols []string `json:"protocols"`
|
||||
MissingProtocols []string `json:"missingProtocols"`
|
||||
SourceCount int `json:"sourceCount"`
|
||||
OnlineSourceCount int `json:"onlineSourceCount"`
|
||||
Online bool `json:"online"`
|
||||
|
||||
@@ -268,6 +268,7 @@ func (s *ProductionStore) VehicleCoverage(ctx context.Context, query url.Values)
|
||||
return Page[VehicleCoverageRow]{}, err
|
||||
}
|
||||
row.Protocols = splitCSV(protocols)
|
||||
row.MissingProtocols = missingCanonicalProtocols(row.Protocols)
|
||||
row.Online = online == 1
|
||||
row.ServiceStatus = buildVehicleCoverageServiceStatus(row)
|
||||
items = append(items, row)
|
||||
|
||||
@@ -58,6 +58,16 @@ type Service struct {
|
||||
|
||||
var canonicalVehicleProtocols = []string{"GB32960", "JT808", "YUTONG_MQTT"}
|
||||
|
||||
func missingCanonicalProtocols(protocols []string) []string {
|
||||
missing := make([]string, 0, len(canonicalVehicleProtocols))
|
||||
for _, protocol := range canonicalVehicleProtocols {
|
||||
if !containsString(protocols, protocol) {
|
||||
missing = append(missing, protocol)
|
||||
}
|
||||
}
|
||||
return missing
|
||||
}
|
||||
|
||||
func NewService(store Store) *Service {
|
||||
return &Service{store: store}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user