package integration import ( "context" "encoding/json" "net/http" "net/http/httptest" "testing" "time" "chatapp3-golang/internal/config" ) func TestUserTotalRechargeAcceptsNumericTimestamps(t *testing.T) { var item UserTotalRecharge raw := []byte(`{ "id":"2049097310624870401", "userId":"2042274349343506434", "type":"SHIPPING_AGENT", "amount":1.60, "createTime":1777377844000, "updateTime":1777556451000 }`) if err := json.Unmarshal(raw, &item); err != nil { t.Fatalf("json.Unmarshal() error = %v", err) } if item.CreateTime != "1777377844000" { t.Fatalf("CreateTime = %q, want numeric timestamp string", item.CreateTime) } if item.UpdateTime != "1777556451000" { t.Fatalf("UpdateTime = %q, want numeric timestamp string", item.UpdateTime) } if item.Amount != "1.60" { t.Fatalf("Amount = %q, want 1.60", item.Amount) } } func TestResolveRegionCodeByCountryCodeUsesRegionConfig(t *testing.T) { calls := 0 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { calls++ if r.Method != http.MethodPost || r.URL.Path != "/region-config/client/listByCondition" { t.Fatalf("request = %s %s, want POST /region-config/client/listByCondition", r.Method, r.URL.Path) } var payload map[string]string if err := json.NewDecoder(r.Body).Decode(&payload); err != nil { t.Fatalf("decode request: %v", err) } if payload["sysOrigin"] != "LIKEI" { t.Fatalf("sysOrigin = %q, want LIKEI", payload["sysOrigin"]) } w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(`{"body":[{"regionCode":"中东区","sysOrigin":"LIKEI","countryCodes":"JO, EG, KSA","del":false},{"regionCode":"US","sysOrigin":"LIKEI","countryCodes":"US","del":true}]}`)) })) defer server.Close() client := New(config.Config{ HTTP: config.HTTPConfig{Timeout: time.Second}, Java: config.JavaConfig{OtherBaseURL: server.URL}, }) got, err := client.ResolveRegionCodeByCountryCode(context.Background(), " likei ", " ksa ") if err != nil { t.Fatalf("ResolveRegionCodeByCountryCode() error = %v", err) } if got != "中东区" { t.Fatalf("region = %q, want 中东区", got) } got, err = client.ResolveRegionCodeByCountryCode(context.Background(), "LIKEI", "eg") if err != nil { t.Fatalf("ResolveRegionCodeByCountryCode() cached error = %v", err) } if got != "中东区" { t.Fatalf("cached region = %q, want 中东区", got) } if calls != 1 { t.Fatalf("region config calls = %d, want cached 1", calls) } }