diff --git a/services/big-data/get_user_profile_body_test.go b/services/big-data/get_user_profile_body_test.go new file mode 100644 index 0000000..4a5683e --- /dev/null +++ b/services/big-data/get_user_profile_body_test.go @@ -0,0 +1,38 @@ +package big_data + +import ( + "encoding/json" + "io" + "testing" +) + +// TestGetBodyReaderCarriesIPAndDeviceID 验证 ip / device_id 能被序列化进发往大数据的请求体。 +// 这两个字段此前在 SDK 里缺失,导致前端传的 IP/设备号被静默丢弃。 +func TestGetBodyReaderCarriesIPAndDeviceID(t *testing.T) { + req := CreateGetUserProfileRequest("token-x", GetUserProfileParam{ + IP: []string{"59.51.36.195"}, + DeviceId: []string{"dev-abc", "dev-def"}, + Page: 1, + PageSize: 50, + }) + + raw, err := io.ReadAll(req.GetBodyReader()) + if err != nil { + t.Fatalf("读取 body 失败: %v", err) + } + + var body struct { + IP []string `json:"ip"` + DeviceId []string `json:"device_id"` + } + if err := json.Unmarshal(raw, &body); err != nil { + t.Fatalf("反序列化 body 失败: %v, 原始=%s", err, raw) + } + + if len(body.IP) != 1 || body.IP[0] != "59.51.36.195" { + t.Errorf("ip 未正确透传, 期望 [59.51.36.195], 实际 %v, 原始=%s", body.IP, raw) + } + if len(body.DeviceId) != 2 || body.DeviceId[0] != "dev-abc" || body.DeviceId[1] != "dev-def" { + t.Errorf("device_id 未正确透传, 期望 [dev-abc dev-def], 实际 %v, 原始=%s", body.DeviceId, raw) + } +}