feat: expose site config in public/admin config responses

This commit is contained in:
mcmc
2026-05-09 19:01:53 +08:00
parent 377176a0f2
commit 3623a543bb
180 changed files with 408 additions and 233 deletions
+59
View File
@@ -731,6 +731,9 @@ func TestAdminSettings_DeleteNonExistent(t *testing.T) {
func TestAdminConfig_ExposesOkPayCredentials(t *testing.T) {
e, token := setupAdminTestEnv(t)
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandCheckoutName, "admin cashier", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.checkout_name: %v", err)
}
if err := data.SetSetting(mdb.SettingGroupOkPay, mdb.SettingKeyOkPayEnabled, "true", mdb.SettingTypeBool); err != nil {
t.Fatalf("seed okpay.enabled: %v", err)
}
@@ -747,6 +750,13 @@ func TestAdminConfig_ExposesOkPayCredentials(t *testing.T) {
rec := doGetAdmin(e, "/admin/api/v1/config", token)
resp := assertOK(t, rec)
dataObj, _ := resp["data"].(map[string]interface{})
site, ok := dataObj["site"].(map[string]interface{})
if !ok {
t.Fatalf("expected site object, got %T", dataObj["site"])
}
if site["cashier_name"] != "admin cashier" {
t.Fatalf("cashier_name = %v, want admin cashier", site["cashier_name"])
}
okpay, ok := dataObj["okpay"].(map[string]interface{})
if !ok {
t.Fatalf("expected okpay object, got %T", dataObj["okpay"])
@@ -762,6 +772,55 @@ func TestAdminConfig_ExposesOkPayCredentials(t *testing.T) {
}
}
func TestAdminSettings_UpsertBrandReflectsInConfig(t *testing.T) {
e, token := setupAdminTestEnv(t)
updateBrand := func(cashier, logo, title, support string) {
rec := doPutAdmin(e, "/admin/api/v1/settings", map[string]interface{}{
"items": []map[string]interface{}{
{"group": mdb.SettingGroupBrand, "key": mdb.SettingKeyBrandCheckoutName, "value": cashier, "type": mdb.SettingTypeString},
{"group": mdb.SettingGroupBrand, "key": mdb.SettingKeyBrandLogoUrl, "value": logo, "type": mdb.SettingTypeString},
{"group": mdb.SettingGroupBrand, "key": mdb.SettingKeyBrandSiteTitle, "value": title, "type": mdb.SettingTypeString},
{"group": mdb.SettingGroupBrand, "key": mdb.SettingKeyBrandSupportUrl, "value": support, "type": mdb.SettingTypeString},
},
}, token)
assertOK(t, rec)
}
assertSite := func(path, wantCashier, wantLogo, wantTitle, wantSupport string) {
rec := doGet(e, path)
if strings.HasPrefix(path, "/admin/") {
rec = doGetAdmin(e, path, token)
}
resp := assertOK(t, rec)
dataObj, _ := resp["data"].(map[string]interface{})
site, ok := dataObj["site"].(map[string]interface{})
if !ok {
t.Fatalf("%s expected site object, got %T", path, dataObj["site"])
}
if site["cashier_name"] != wantCashier {
t.Fatalf("%s cashier_name=%v, want %s", path, site["cashier_name"], wantCashier)
}
if site["logo_url"] != wantLogo {
t.Fatalf("%s logo_url=%v, want %s", path, site["logo_url"], wantLogo)
}
if site["website_title"] != wantTitle {
t.Fatalf("%s website_title=%v, want %s", path, site["website_title"], wantTitle)
}
if site["support_link"] != wantSupport {
t.Fatalf("%s support_link=%v, want %s", path, site["support_link"], wantSupport)
}
}
updateBrand("cashier-v1", "https://cdn.example.com/v1.png", "title-v1", "https://example.com/help-v1")
assertSite("/payments/gmpay/v1/config", "cashier-v1", "https://cdn.example.com/v1.png", "title-v1", "https://example.com/help-v1")
assertSite("/admin/api/v1/config", "cashier-v1", "https://cdn.example.com/v1.png", "title-v1", "https://example.com/help-v1")
updateBrand("cashier-v2", "https://cdn.example.com/v2.png", "title-v2", "https://example.com/help-v2")
assertSite("/payments/gmpay/v1/config", "cashier-v2", "https://cdn.example.com/v2.png", "title-v2", "https://example.com/help-v2")
assertSite("/admin/api/v1/config", "cashier-v2", "https://cdn.example.com/v2.png", "title-v2", "https://example.com/help-v2")
}
// ─── Notification Channels ───────────────────────────────────────────────────
// TestAdminNotificationChannels_CRUD verifies notification channel routes.
+68
View File
@@ -483,6 +483,18 @@ func TestGetSupportedAssets_WalletAddressToggle(t *testing.T) {
func TestGetPublicConfig(t *testing.T) {
e := setupTestEnv(t)
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandCheckoutName, "asd", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.checkout_name: %v", err)
}
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandLogoUrl, "https://cdn.example.com/logo.png", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.logo_url: %v", err)
}
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandSiteTitle, "asd title", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.site_title: %v", err)
}
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandSupportUrl, "https://example.com/support", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.support_url: %v", err)
}
req := httptest.NewRequest(http.MethodGet, "/payments/gmpay/v1/config", nil)
rec := httptest.NewRecorder()
@@ -508,6 +520,22 @@ func TestGetPublicConfig(t *testing.T) {
if len(supports) < 2 {
t.Fatalf("expected >= 2 network supports, got %d", len(supports))
}
site, ok := respData["site"].(map[string]interface{})
if !ok {
t.Fatalf("expected site object, got %T", respData["site"])
}
if site["cashier_name"] != "asd" {
t.Fatalf("site.cashier_name = %v, want asd", site["cashier_name"])
}
if site["logo_url"] != "https://cdn.example.com/logo.png" {
t.Fatalf("site.logo_url = %v", site["logo_url"])
}
if site["website_title"] != "asd title" {
t.Fatalf("site.website_title = %v, want asd title", site["website_title"])
}
if site["support_link"] != "https://example.com/support" {
t.Fatalf("site.support_link = %v", site["support_link"])
}
epay, ok := respData["epay"].(map[string]interface{})
if !ok {
t.Fatalf("expected epay object, got %T", respData["epay"])
@@ -550,6 +578,46 @@ func TestGetPublicConfig(t *testing.T) {
}
}
func TestGetPublicConfig_BrandLegacyFallback(t *testing.T) {
e := setupTestEnv(t)
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandSiteName, "legacy cashier", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.site_name: %v", err)
}
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandPageTitle, "legacy title", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.page_title: %v", err)
}
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandSupportUrl, "https://legacy.example.com/help", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.support_url: %v", err)
}
req := httptest.NewRequest(http.MethodGet, "/payments/gmpay/v1/config", nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("expected 200, got %d, body=%s", rec.Code, rec.Body.String())
}
resp := parseResp(t, rec)
respData, ok := resp["data"].(map[string]interface{})
if !ok {
t.Fatalf("expected object data, got %T", resp["data"])
}
site, ok := respData["site"].(map[string]interface{})
if !ok {
t.Fatalf("expected site object, got %T", respData["site"])
}
if site["cashier_name"] != "legacy cashier" {
t.Fatalf("site.cashier_name = %v, want legacy cashier", site["cashier_name"])
}
if site["website_title"] != "legacy title" {
t.Fatalf("site.website_title = %v, want legacy title", site["website_title"])
}
if site["support_link"] != "https://legacy.example.com/help" {
t.Fatalf("site.support_link = %v", site["support_link"])
}
}
func TestOkPayNotifyRouteExists(t *testing.T) {
e := setupTestEnv(t)