108 lines
2.5 KiB
Go
108 lines
2.5 KiB
Go
package discovery
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeRailOperations(t *testing.T) {
|
|
got := NormalizeRailOperations([]string{
|
|
"send",
|
|
"observe.confirm",
|
|
"external.credit",
|
|
"fx.convert",
|
|
"payout.crypto",
|
|
"unknown",
|
|
})
|
|
|
|
want := []string{
|
|
RailOperationSend,
|
|
RailOperationObserveConfirm,
|
|
RailOperationExternalCredit,
|
|
RailOperationFXConvert,
|
|
}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("unexpected operations count: got=%d want=%d", len(got), len(want))
|
|
}
|
|
for i := range want {
|
|
if got[i] != want[i] {
|
|
t.Fatalf("unexpected operation[%d]: got=%q want=%q", i, got[i], want[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestExpandRailOperationRejectsLegacyAliases(t *testing.T) {
|
|
if got := ExpandRailOperation("payout.fiat"); len(got) != 0 {
|
|
t.Fatalf("expected no expansion for legacy alias, got=%v", got)
|
|
}
|
|
}
|
|
|
|
func TestIsKnownRail(t *testing.T) {
|
|
if !IsKnownRail("crypto") {
|
|
t.Fatalf("expected crypto rail to be known")
|
|
}
|
|
if IsKnownRail("telegram") {
|
|
t.Fatalf("did not expect telegram rail to be known")
|
|
}
|
|
}
|
|
|
|
func TestNormalizeRailRejectsLegacyAliases(t *testing.T) {
|
|
if IsKnownRail("provider_settlement") {
|
|
t.Fatalf("did not expect provider_settlement alias to be known")
|
|
}
|
|
if IsKnownRail("card_payout") {
|
|
t.Fatalf("did not expect card_payout alias to be known")
|
|
}
|
|
if IsKnownRail("RAIL_SETTLEMENT") {
|
|
t.Fatalf("did not expect RAIL_SETTLEMENT alias to be known")
|
|
}
|
|
}
|
|
|
|
func TestGatewayOperationSetsAreCanonicalOnly(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
got []string
|
|
want []string
|
|
}{
|
|
{
|
|
name: "crypto rail gateway operations",
|
|
got: CryptoRailGatewayOperations(),
|
|
want: []string{
|
|
OperationBalanceRead,
|
|
OperationSend,
|
|
OperationExternalDebit,
|
|
OperationExternalCredit,
|
|
OperationFee,
|
|
OperationObserveConfirm,
|
|
},
|
|
},
|
|
{
|
|
name: "card payout rail gateway operations",
|
|
got: CardPayoutRailGatewayOperations(),
|
|
want: []string{
|
|
OperationSend,
|
|
OperationExternalCredit,
|
|
OperationObserveConfirm,
|
|
},
|
|
},
|
|
{
|
|
name: "provider settlement rail gateway operations",
|
|
got: ProviderSettlementRailGatewayOperations(),
|
|
want: []string{
|
|
OperationFXConvert,
|
|
OperationObserveConfirm,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if len(tt.got) != len(tt.want) {
|
|
t.Fatalf("unexpected operations count: got=%d want=%d", len(tt.got), len(tt.want))
|
|
}
|
|
for i := range tt.want {
|
|
if tt.got[i] != tt.want[i] {
|
|
t.Fatalf("unexpected operation[%d]: got=%q want=%q", i, tt.got[i], tt.want[i])
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|