feat(platform): filter quality issues by type
This commit is contained in:
@@ -647,6 +647,40 @@ func TestBuildQualityIssueWhereUsesMatchingArgs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildQualityIssueWhereFiltersIssueType(t *testing.T) {
|
||||
fromSQL, args := buildQualityIssueWhere(url.Values{"issueType": {"NO_SOURCE"}})
|
||||
if !strings.Contains(fromSQL, "q.issue_type = ?") {
|
||||
t.Fatalf("quality issue SQL should filter issue type: %s", fromSQL)
|
||||
}
|
||||
if len(args) != 1 || args[0] != "NO_SOURCE" {
|
||||
t.Fatalf("args = %#v", args)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerQualityIssuesFiltersIssueType(t *testing.T) {
|
||||
handler := NewHandler(NewService(NewMockStore()))
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/quality/issues?issueType=NO_SOURCE&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.NewDecoder(rec.Body).Decode(&body); err != nil {
|
||||
t.Fatalf("response JSON should decode: %v body=%s", err, rec.Body.String())
|
||||
}
|
||||
if body.Data.Total == 0 {
|
||||
t.Fatalf("expected at least one NO_SOURCE issue")
|
||||
}
|
||||
for _, item := range body.Data.Items {
|
||||
if item.IssueType != "NO_SOURCE" {
|
||||
t.Fatalf("expected only NO_SOURCE issues, got %+v", body.Data.Items)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerOpsHealthIncludesVehicleServiceRuntime(t *testing.T) {
|
||||
handler := NewHandler(NewServiceWithRuntime(NewMockStore(), RuntimeInfo{RequestTimeoutMs: 1500}))
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
@@ -527,6 +527,9 @@ func (m *MockStore) QualityIssues(_ context.Context, query url.Values) (Page[Qua
|
||||
if protocol := strings.TrimSpace(query.Get("protocol")); protocol != "" {
|
||||
rows = keep(rows, func(row QualityIssueRow) bool { return row.Protocol == protocol })
|
||||
}
|
||||
if issueType := strings.TrimSpace(query.Get("issueType")); issueType != "" {
|
||||
rows = keep(rows, func(row QualityIssueRow) bool { return row.IssueType == issueType })
|
||||
}
|
||||
return page(rows, query), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -713,6 +713,10 @@ func buildQualityIssueWhere(query url.Values) (string, []any) {
|
||||
where = append(where, "q.protocol = ?")
|
||||
args = append(args, protocol)
|
||||
}
|
||||
if issueType := strings.TrimSpace(query.Get("issueType")); issueType != "" {
|
||||
where = append(where, "q.issue_type = ?")
|
||||
args = append(args, issueType)
|
||||
}
|
||||
if keyword := strings.TrimSpace(query.Get("keyword")); keyword != "" {
|
||||
where = append(where, "(q.vin LIKE ? OR q.plate LIKE ? OR q.phone LIKE ? OR q.source_endpoint LIKE ?)")
|
||||
like := "%" + keyword + "%"
|
||||
|
||||
Reference in New Issue
Block a user