Files
multica/server/internal/handler/config_test.go
devv-eve fbf41bde73 feat(selfhost): ship public GHCR deployment flow
Publish stable GHCR self-host images, switch self-host deploys to official image pulls with a source-build fallback, and move self-host signup / Google OAuth config onto runtime /api/config.
2026-04-22 16:58:42 +08:00

49 lines
1.3 KiB
Go

package handler
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetConfigIncludesRuntimeAuthConfig(t *testing.T) {
origStorage := testHandler.Storage
testHandler.Storage = &mockStorage{}
defer func() { testHandler.Storage = origStorage }()
t.Setenv("ALLOW_SIGNUP", "false")
t.Setenv("GOOGLE_CLIENT_ID", "google-client-id")
t.Setenv("POSTHOG_API_KEY", "phc_test")
t.Setenv("POSTHOG_HOST", "https://eu.i.posthog.com")
req := httptest.NewRequest(http.MethodGet, "/api/config", nil)
w := httptest.NewRecorder()
testHandler.GetConfig(w, req)
if w.Code != http.StatusOK {
t.Fatalf("GetConfig: expected 200, got %d: %s", w.Code, w.Body.String())
}
var cfg AppConfig
if err := json.Unmarshal(w.Body.Bytes(), &cfg); err != nil {
t.Fatalf("decode config: %v", err)
}
if cfg.CdnDomain != "cdn.example.com" {
t.Fatalf("cdn_domain: want cdn.example.com, got %q", cfg.CdnDomain)
}
if cfg.AllowSignup {
t.Fatalf("allow_signup: want false, got true")
}
if cfg.GoogleClientID != "google-client-id" {
t.Fatalf("google_client_id: want google-client-id, got %q", cfg.GoogleClientID)
}
if cfg.PosthogKey != "phc_test" {
t.Fatalf("posthog_key: want phc_test, got %q", cfg.PosthogKey)
}
if cfg.PosthogHost != "https://eu.i.posthog.com" {
t.Fatalf("posthog_host: want https://eu.i.posthog.com, got %q", cfg.PosthogHost)
}
}