yumi-golang/internal/service/luckygift/runtime_config_test.go
2026-04-23 12:24:32 +08:00

79 lines
2.2 KiB
Go

package luckygift
import (
"chatapp3-golang/internal/config"
"chatapp3-golang/internal/model"
"testing"
)
func TestMergeLuckyGiftProviderConfigPrefersRuntimeAccount(t *testing.T) {
base := config.LuckyGiftProviderConfig{
StandardID: 18816,
URL: "https://provider.example.com/lucky_gift/start_game",
AppID: "base-app-id",
AppChannel: "base-app-channel",
AppKey: "base-app-key",
}
merged := mergeLuckyGiftProviderConfig(base, luckyGiftRuntimeAccount{
AppID: "runtime-app-id",
AppChannel: "runtime-app-channel",
AppKey: "runtime-app-key",
})
if merged.URL != base.URL {
t.Fatalf("expected url to keep base value, got %q", merged.URL)
}
if merged.AppID != "runtime-app-id" {
t.Fatalf("expected runtime app id, got %q", merged.AppID)
}
if merged.AppChannel != "runtime-app-channel" {
t.Fatalf("expected runtime app channel, got %q", merged.AppChannel)
}
if merged.AppKey != "runtime-app-key" {
t.Fatalf("expected runtime app key, got %q", merged.AppKey)
}
}
func TestApplyLuckyGiftRuntimeAccountUsesProviderConfigRow(t *testing.T) {
account := applyLuckyGiftRuntimeAccount(luckyGiftRuntimeAccount{
AppID: "fallback-app-id",
AppChannel: "fallback-app-channel",
AppKey: "fallback-app-key",
}, model.BaishunProviderConfig{
AppID: 4581045902,
AppChannel: "yumiparty",
AppKey: "test-key",
})
if account.AppID != "4581045902" {
t.Fatalf("expected row app id, got %q", account.AppID)
}
if account.AppChannel != "yumiparty" {
t.Fatalf("expected row app channel, got %q", account.AppChannel)
}
if account.AppKey != "test-key" {
t.Fatalf("expected row app key, got %q", account.AppKey)
}
}
func TestDefaultLuckyGiftRuntimeAccountUsesBaishunConfig(t *testing.T) {
account := defaultLuckyGiftRuntimeAccount(config.Config{
Baishun: config.BaishunConfig{
AppID: 7485318192,
AppChannel: "yumiparty",
AppKey: "shared-key",
},
})
if account.AppID != "7485318192" {
t.Fatalf("expected baishun app id, got %q", account.AppID)
}
if account.AppChannel != "yumiparty" {
t.Fatalf("expected baishun app channel, got %q", account.AppChannel)
}
if account.AppKey != "shared-key" {
t.Fatalf("expected baishun app key, got %q", account.AppKey)
}
}