feat(platform): integrate runtime amap vehicle maps

This commit is contained in:
lingniu
2026-07-04 10:52:11 +08:00
parent bb1b2f1c46
commit adb9d146d9
12 changed files with 402 additions and 51 deletions

View File

@@ -2,8 +2,10 @@ package app
import (
"encoding/json"
"lingniu/vehicle-data-platform/apps/api/internal/config"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
@@ -56,3 +58,28 @@ func TestWithRequestTimeoutReturnsEnvelopeWithTraceID(t *testing.T) {
t.Fatalf("unexpected timeout envelope: %+v body=%s", body, rec.Body.String())
}
}
func TestAppConfigScriptIsRuntimeRendered(t *testing.T) {
handler := withAppConfig(http.NotFoundHandler(), config.Config{
AMapWebJSKey: "web-key",
AMapSecurityCode: "security-code",
AMapServiceHost: "/_AMapService",
})
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/app-config.js", nil)
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
}
if got := rec.Header().Get("Cache-Control"); got != "no-store" {
t.Fatalf("Cache-Control = %q, want no-store", got)
}
body := rec.Body.String()
for _, want := range []string{"window.__LINGNIU_APP_CONFIG__=", `"amapWebJsKey":"web-key"`, `"amapSecurityJsCode":"security-code"`, `"amapSecurityServiceHost":"/_AMapService"`} {
if !strings.Contains(body, want) {
t.Fatalf("app config script missing %q: %s", want, body)
}
}
}