package main import ( "encoding/json" "net/http" "net/http/httptest" "testing" ) func TestAdminInternalClientLatestAppRelease(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/internal/im-config/app/releases/latest" { t.Errorf("unexpected path: %s", r.URL.Path) return } if r.URL.Query().Get("platform") != "ios" || r.URL.Query().Get("channel") != "stable" { t.Errorf("unexpected query: %s", r.URL.RawQuery) return } if r.Header.Get(internalHeaderSignature) == "" { t.Error("internal request must be signed") return } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(map[string]any{ "code": 0, "data": map[string]any{ "id": 1, "platform": "ios", "channel": "stable", "latest_version": "2.0.0", "min_supported_version": "1.5.0", "update_type": "recommended", "store_url": "https://apps.apple.com/app/id123", "published_at": "2026-09-12T10:00:00Z", }, }) })) defer server.Close() client := &adminInternalClient{ config: adminInternalAPIConfig{BaseURL: server.URL, ServiceName: "im-server", Secret: "test-secret"}, http: server.Client(), } release, err := client.LatestAppRelease(" IM ", " IOS ", "STABLE") if err != nil { t.Fatal(err) } if release.LatestVersion != "2.0.0" || release.StoreURL != "https://apps.apple.com/app/id123" || release.PublishedAt.IsZero() { t.Fatalf("unexpected release: %#v", release) } }