Files
im_server/server/admin_internal_config_test.go
T
Austin e8804883fc feat: 新增群组成员数量统计功能并在接口中返回
实现了群组成员数量统计的接口,包含数据库层统计逻辑,在群组详情、设置等接口中返回实时成员数,同时修复了测试用例中参数空格问题。
2026-10-13 17:58:05 +08:00

49 lines
1.5 KiB
Go

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)
}
}