feat(platform): separate vehicle lookup key from VIN

This commit is contained in:
lingniu
2026-07-04 00:16:04 +08:00
parent 52b3040506
commit cb1a3097d8
5 changed files with 66 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
package platform
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
@@ -56,7 +57,7 @@ func TestHandlerVehicleDetail(t *testing.T) {
if rec.Code != http.StatusOK {
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
}
for _, want := range []string{"identity", "realtimeSummary", "realtime", "history", "raw", "mileage", "quality", "sources", "sourceStatus"} {
for _, want := range []string{"lookupKey", "lookupResolved", "identity", "realtimeSummary", "realtime", "history", "raw", "mileage", "quality", "sources", "sourceStatus"} {
if !strings.Contains(rec.Body.String(), want) {
t.Fatalf("response missing %q: %s", want, rec.Body.String())
}
@@ -89,6 +90,30 @@ func TestHandlerVehicleDetailAcceptsKeyword(t *testing.T) {
}
}
func TestHandlerVehicleDetailKeepsUnresolvedLookupOutOfVIN(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/vehicles/detail?keyword=64646848247", nil)
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
}
for _, want := range []string{`"lookupKey":"64646848247"`, `"lookupResolved":false`, `"vin":""`} {
if !strings.Contains(rec.Body.String(), want) {
t.Fatalf("response missing %q: %s", want, rec.Body.String())
}
}
var body struct {
Data VehicleDetail `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())
}
if body.Data.VIN == "64646848247" {
t.Fatalf("unresolved lookup should not be returned as top-level VIN: %s", rec.Body.String())
}
}
func TestHandlerRealtimeLocations(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()