feat(osi): 优化人群分类查询接口(T-209)

This commit is contained in:
ila
2026-07-09 20:38:27 +08:00
parent ca16f61263
commit 561cd839e7
10 changed files with 108 additions and 16 deletions
+32
View File
@@ -39,6 +39,38 @@ func TestHealthRecordFindReturnsRawPlatformResponse(t *testing.T) {
}
}
func TestHealthRecordCrowdReturnsRawPlatformResponse(t *testing.T) {
var seenPath string
osiServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
seenPath = r.URL.Path
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":{"personSign":"LAO","idCard":"440100199001011234","phrId":"PHR001"}}`))
}))
defer osiServer.Close()
transport, err := osi.NewTransport(osi.TransportConfig{Timeout: time.Second})
if err != nil {
t.Fatalf("NewTransport: %v", err)
}
client := osi.NewClient(osi.ClientConfig{BaseURL: osiServer.URL, UserName: "dyytgw", Ask: "secret", Transport: transport})
h := NewHealthRecordHandler(client)
req := httptest.NewRequest(http.MethodGet, "/api/health-record/crowd?idCard=440100199001011234", nil)
rec := httptest.NewRecorder()
h.Crowd(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d", rec.Code)
}
if seenPath != "/osi/api/auto/jkda/findrqbj" {
t.Fatalf("upstream path = %q", seenPath)
}
body, _ := io.ReadAll(rec.Body)
if !strings.Contains(string(body), `"personSign":"LAO"`) || !strings.Contains(string(body), `"phrId":"PHR001"`) {
t.Fatalf("body missing crowd fields: %s", body)
}
}
func TestHealthRecordFindRequiresIdentifier(t *testing.T) {
h := NewHealthRecordHandler(nil) // 无标识符时在触达 client 前就返回 400
req := httptest.NewRequest(http.MethodGet, "/api/health-record/find", nil)