package platform import ( "net/http" "net/http/httptest" "strings" "testing" ) func TestHandlerDashboardSummary(t *testing.T) { handler := NewHandler(NewService(NewMockStore())) rec := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "/api/dashboard/summary", nil) handler.ServeHTTP(rec, req) if rec.Code != http.StatusOK { t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String()) } if !strings.Contains(rec.Body.String(), "onlineVehicles") { t.Fatalf("response missing onlineVehicles: %s", rec.Body.String()) } } func TestHandlerVehicles(t *testing.T) { handler := NewHandler(NewService(NewMockStore())) rec := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "/api/vehicles?limit=10", nil) handler.ServeHTTP(rec, req) if rec.Code != http.StatusOK { t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String()) } if !strings.Contains(rec.Body.String(), "LB9A32A24R0LS1426") { t.Fatalf("response missing vehicle: %s", rec.Body.String()) } } func TestHandlerRealtimeLocations(t *testing.T) { handler := NewHandler(NewService(NewMockStore())) rec := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "/api/realtime/locations?limit=10", nil) handler.ServeHTTP(rec, req) if rec.Code != http.StatusOK { t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String()) } if !strings.Contains(rec.Body.String(), "LB9A32A24R0LS1426") { t.Fatalf("response missing vehicle: %s", rec.Body.String()) } } func TestHandlerHistoryMileageQualityOps(t *testing.T) { cases := []struct { path string want string }{ {"/api/history/locations?limit=10", "totalMileageKm"}, {"/api/history/raw-frames?protocol=GB32960&vin=LB9A32A24R0LS1426&limit=1&includeFields=true", "rawSizeBytes"}, {"/api/mileage/daily?limit=10", "dailyMileageKm"}, {"/api/quality/issues?limit=10", "issueType"}, {"/api/ops/health", "linkHealth"}, } handler := NewHandler(NewService(NewMockStore())) for _, tc := range cases { t.Run(tc.path, func(t *testing.T) { rec := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, tc.path, nil) handler.ServeHTTP(rec, req) if rec.Code != http.StatusOK { t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String()) } if !strings.Contains(rec.Body.String(), tc.want) { t.Fatalf("response missing %q: %s", tc.want, rec.Body.String()) } }) } }