diff --git a/vehicle-data-platform/apps/api/internal/platform/mock_store.go b/vehicle-data-platform/apps/api/internal/platform/mock_store.go index 2800c218..ccd1f140 100644 --- a/vehicle-data-platform/apps/api/internal/platform/mock_store.go +++ b/vehicle-data-platform/apps/api/internal/platform/mock_store.go @@ -239,6 +239,10 @@ func (m *MockStore) VehicleServiceSummary(ctx context.Context) (VehicleServiceSu summary.IdentityRequiredVehicles++ } } + onlineByProtocol := map[string]bool{} + for _, status := range row.SourceStatus { + onlineByProtocol[status.Protocol] = status.Online + } for _, protocol := range row.Protocols { current := protocolCounts[protocol] if current == nil { @@ -246,7 +250,7 @@ func (m *MockStore) VehicleServiceSummary(ctx context.Context) (VehicleServiceSu protocolCounts[protocol] = current } current.Total++ - if row.Online { + if onlineByProtocol[protocol] { current.Online++ } } diff --git a/vehicle-data-platform/apps/api/internal/platform/service_test.go b/vehicle-data-platform/apps/api/internal/platform/service_test.go index 43b4e95c..c0b18ec8 100644 --- a/vehicle-data-platform/apps/api/internal/platform/service_test.go +++ b/vehicle-data-platform/apps/api/internal/platform/service_test.go @@ -64,3 +64,22 @@ func TestVehicleServiceOverviewsUsesBatchDataPath(t *testing.T) { t.Fatalf("batch overview should avoid per-keyword store calls, vehicles=%d realtime=%d", store.vehiclesCalls, store.vehicleRealtimeCalls) } } + +func TestVehicleServiceSummaryCountsProtocolOnlineByProtocolSlot(t *testing.T) { + service := NewService(NewMockStore()) + summary, err := service.VehicleServiceSummary(context.Background()) + if err != nil { + t.Fatalf("VehicleServiceSummary returned error: %v", err) + } + byProtocol := map[string]ProtocolStat{} + for _, protocol := range summary.Protocols { + byProtocol[protocol.Protocol] = protocol + } + gb32960 := byProtocol["GB32960"] + if gb32960.Total != 2 { + t.Fatalf("expected two GB32960 source slots, got %+v", gb32960) + } + if gb32960.Online != 1 { + t.Fatalf("GB32960 online count must use GB32960 source status only, got %+v", gb32960) + } +}