feat(platform): surface no-source quality issues

This commit is contained in:
lingniu
2026-07-04 04:34:32 +08:00
parent 40b55600c7
commit 669390e8bb
3 changed files with 115 additions and 26 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
)
@@ -586,6 +587,66 @@ func TestHandlerHistoryMileageQualityOps(t *testing.T) {
}
}
func TestHandlerQualityIncludesNoSourceVehicles(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/quality/issues?limit=20", 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 Page[QualityIssueRow] `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())
}
found := false
for _, item := range body.Data.Items {
if item.IssueType == "NO_SOURCE" {
found = true
if item.VIN == "" || item.Plate == "" || item.Protocol != "VEHICLE_SERVICE" {
t.Fatalf("NO_SOURCE issue should identify bound vehicle service, got %+v", item)
}
}
}
if !found {
t.Fatalf("quality issues should include NO_SOURCE vehicles, got %+v", body.Data.Items)
}
}
func TestHandlerQualitySummaryIncludesNoSourceBucket(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/quality/summary?limit=20", 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 QualitySummary `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())
}
found := false
for _, item := range body.Data.IssueTypes {
if item.Name == "NO_SOURCE" {
found = true
}
}
if !found {
t.Fatalf("quality summary should include NO_SOURCE bucket, got %+v", body.Data.IssueTypes)
}
}
func TestBuildQualityIssueWhereUsesMatchingArgs(t *testing.T) {
fromSQL, args := buildQualityIssueWhere(url.Values{"vin": {"VIN001"}, "protocol": {"VEHICLE_SERVICE"}, "keyword": {"粤A"}})
if strings.Count(fromSQL, "?") != len(args) {
t.Fatalf("quality issue SQL placeholders should match args: placeholders=%d args=%d sql=%s args=%#v", strings.Count(fromSQL, "?"), len(args), fromSQL, args)
}
}
func TestHandlerOpsHealthIncludesVehicleServiceRuntime(t *testing.T) {
handler := NewHandler(NewServiceWithRuntime(NewMockStore(), RuntimeInfo{RequestTimeoutMs: 1500}))
rec := httptest.NewRecorder()