feat: support background_color background_image_url

This commit is contained in:
line-6000
2026-05-11 16:03:32 +08:00
parent 84972ea0f0
commit 1c805ed061
178 changed files with 278 additions and 242 deletions
+16 -8
View File
@@ -775,19 +775,21 @@ func TestAdminConfig_ExposesOkPayCredentials(t *testing.T) {
func TestAdminSettings_UpsertBrandReflectsInConfig(t *testing.T) {
e, token := setupAdminTestEnv(t)
updateBrand := func(cashier, logo, title, support string) {
updateBrand := func(cashier, logo, title, support, bgColor, bgImage 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},
{"group": mdb.SettingGroupBrand, "key": mdb.SettingKeyBrandBackgroundColor, "value": bgColor, "type": mdb.SettingTypeString},
{"group": mdb.SettingGroupBrand, "key": mdb.SettingKeyBrandBackgroundImageUrl, "value": bgImage, "type": mdb.SettingTypeString},
},
}, token)
assertOK(t, rec)
}
assertSite := func(path, wantCashier, wantLogo, wantTitle, wantSupport string) {
assertSite := func(path, wantCashier, wantLogo, wantTitle, wantSupport, wantBgColor, wantBgImage string) {
rec := doGet(e, path)
if strings.HasPrefix(path, "/admin/") {
rec = doGetAdmin(e, path, token)
@@ -810,15 +812,21 @@ func TestAdminSettings_UpsertBrandReflectsInConfig(t *testing.T) {
if site["support_link"] != wantSupport {
t.Fatalf("%s support_link=%v, want %s", path, site["support_link"], wantSupport)
}
if site["background_color"] != wantBgColor {
t.Fatalf("%s background_color=%v, want %s", path, site["background_color"], wantBgColor)
}
if site["background_image_url"] != wantBgImage {
t.Fatalf("%s background_image_url=%v, want %s", path, site["background_image_url"], wantBgImage)
}
}
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-v1", "https://cdn.example.com/v1.png", "title-v1", "https://example.com/help-v1", "#111111", "https://cdn.example.com/bg-v1.png")
assertSite("/payments/gmpay/v1/config", "cashier-v1", "https://cdn.example.com/v1.png", "title-v1", "https://example.com/help-v1", "#111111", "https://cdn.example.com/bg-v1.png")
assertSite("/admin/api/v1/config", "cashier-v1", "https://cdn.example.com/v1.png", "title-v1", "https://example.com/help-v1", "#111111", "https://cdn.example.com/bg-v1.png")
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")
updateBrand("cashier-v2", "https://cdn.example.com/v2.png", "title-v2", "https://example.com/help-v2", "#222222", "https://cdn.example.com/bg-v2.png")
assertSite("/payments/gmpay/v1/config", "cashier-v2", "https://cdn.example.com/v2.png", "title-v2", "https://example.com/help-v2", "#222222", "https://cdn.example.com/bg-v2.png")
assertSite("/admin/api/v1/config", "cashier-v2", "https://cdn.example.com/v2.png", "title-v2", "https://example.com/help-v2", "#222222", "https://cdn.example.com/bg-v2.png")
}
// ─── Notification Channels ───────────────────────────────────────────────────
+12
View File
@@ -495,6 +495,12 @@ func TestGetPublicConfig(t *testing.T) {
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandSupportUrl, "https://example.com/support", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.support_url: %v", err)
}
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandBackgroundColor, "#123456", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.background_color: %v", err)
}
if err := data.SetSetting(mdb.SettingGroupBrand, mdb.SettingKeyBrandBackgroundImageUrl, "https://cdn.example.com/bg.png", mdb.SettingTypeString); err != nil {
t.Fatalf("seed brand.background_image_url: %v", err)
}
req := httptest.NewRequest(http.MethodGet, "/payments/gmpay/v1/config", nil)
rec := httptest.NewRecorder()
@@ -536,6 +542,12 @@ func TestGetPublicConfig(t *testing.T) {
if site["support_link"] != "https://example.com/support" {
t.Fatalf("site.support_link = %v", site["support_link"])
}
if site["background_color"] != "#123456" {
t.Fatalf("site.background_color = %v, want #123456", site["background_color"])
}
if site["background_image_url"] != "https://cdn.example.com/bg.png" {
t.Fatalf("site.background_image_url = %v", site["background_image_url"])
}
epay, ok := respData["epay"].(map[string]interface{})
if !ok {
t.Fatalf("expected epay object, got %T", respData["epay"])