package payment import "testing" func TestParsePlatform(t *testing.T) { testCases := []struct { name string input string expected Platform }{ {name: "exact AppleIAP", input: "AppleIAP", expected: AppleIAP}, {name: "snake apple_iap", input: "apple_iap", expected: AppleIAP}, {name: "kebab apple-iap", input: "apple-iap", expected: AppleIAP}, {name: "compact appleiap", input: "appleiap", expected: AppleIAP}, {name: "trimmed value", input: " apple_iap ", expected: AppleIAP}, {name: "legacy exact CryptoSaaS", input: "CryptoSaaS", expected: CryptoSaaS}, {name: "snake crypto_saas", input: "crypto_saas", expected: CryptoSaaS}, {name: "unsupported", input: "unknown_gateway", expected: UNSUPPORTED}, } for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { got := ParsePlatform(testCase.input) if got != testCase.expected { t.Fatalf("ParsePlatform(%q) = %v, expected %v", testCase.input, got, testCase.expected) } }) } } func TestPlatformStringIsCanonical(t *testing.T) { testCases := []struct { name string input Platform expected string }{ {name: "stripe", input: Stripe, expected: "Stripe"}, {name: "alipay", input: AlipayF2F, expected: "AlipayF2F"}, {name: "epay", input: EPay, expected: "EPay"}, {name: "balance", input: Balance, expected: "balance"}, {name: "crypto", input: CryptoSaaS, expected: "CryptoSaaS"}, {name: "apple", input: AppleIAP, expected: "AppleIAP"}, {name: "unsupported", input: UNSUPPORTED, expected: "unsupported"}, } for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { got := testCase.input.String() if got != testCase.expected { t.Fatalf("Platform.String() = %q, expected %q", got, testCase.expected) } }) } } func TestCanonicalPlatformName(t *testing.T) { canonical, ok := CanonicalPlatformName("apple_iap") if !ok { t.Fatalf("expected apple_iap to be supported") } if canonical != "AppleIAP" { t.Fatalf("canonical name mismatch: got %q", canonical) } _, ok = CanonicalPlatformName("not_exists") if ok { t.Fatalf("expected unsupported platform to return ok=false") } }