2026-06-09 11:04:31 +08:00

60 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package grpc
import (
"strings"
"testing"
gamedomain "hyapp/services/game-service/internal/domain/game"
)
func TestPlatformToProtoExposesCallbackSecretForAdmin(t *testing.T) {
const secret = "leadercc-admin-visible-key"
got := platformToProto(gamedomain.Platform{
PlatformCode: "lingxian",
CallbackSecretCiphertext: secret,
CallbackSecretConfigured: true,
})
if got.GetCallbackSecret() != secret {
t.Fatalf("callback_secret = %q, want %q", got.GetCallbackSecret(), secret)
}
if !got.GetCallbackSecretSet() {
t.Fatal("callback_secret_set = false, want true")
}
}
func TestNormalizePlatformAcceptsProviderAdapters(t *testing.T) {
// 平台创建入口会先规范化 adapter_type新增厂商必须在这里放行否则后台配置页会被 gRPC 直接拒绝。
for _, adapterType := range []string{gamedomain.AdapterVivaGamesV1, gamedomain.AdapterReyouV1} {
got, err := normalizePlatform(gamedomain.Platform{
PlatformCode: strings.TrimSuffix(adapterType, "_v1"),
PlatformName: adapterType,
Status: gamedomain.StatusActive,
AdapterType: adapterType,
AdapterConfigJSON: "{}",
})
if err != nil {
t.Fatalf("normalizePlatform(adapter=%s) error = %v", adapterType, err)
}
if got.AdapterType != adapterType {
t.Fatalf("adapter_type = %q, want %q", got.AdapterType, adapterType)
}
}
}
func TestNormalizePlatformRejectsDemoAdapter(t *testing.T) {
for _, adapterType := range []string{"", gamedomain.AdapterDemo} {
_, err := normalizePlatform(gamedomain.Platform{
PlatformCode: "demo",
PlatformName: "Demo",
Status: gamedomain.StatusActive,
AdapterType: adapterType,
AdapterConfigJSON: "{}",
})
if err == nil {
t.Fatalf("normalizePlatform(adapterType=%q) expected error", adapterType)
}
}
}