Files
sendico/api/payments/storage/model/rail_operations_test.go
2026-02-27 02:33:40 +01:00

69 lines
1.9 KiB
Go

package model
import (
"github.com/tech/sendico/pkg/discovery"
"testing"
)
func TestNormalizeRailOperations(t *testing.T) {
ops := NormalizeRailOperations([]RailOperation{
"send",
"SEND",
" external_credit ",
"unknown",
"",
})
if len(ops) != 2 {
t.Fatalf("unexpected operations count: got=%d want=2", len(ops))
}
if ops[0] != discovery.RailOperationSend {
t.Fatalf("unexpected first operation: got=%q want=%q", ops[0], discovery.RailOperationSend)
}
if ops[1] != discovery.RailOperationExternalCredit {
t.Fatalf("unexpected second operation: got=%q want=%q", ops[1], discovery.RailOperationExternalCredit)
}
}
func TestHasRailOperation(t *testing.T) {
ops := []RailOperation{discovery.RailOperationSend, discovery.RailOperationExternalCredit}
if !HasRailOperation(ops, discovery.RailOperationSend) {
t.Fatalf("expected send operation to be present")
}
if !HasRailOperation(ops, " external_credit ") {
t.Fatalf("expected external credit operation to be present")
}
if HasRailOperation(ops, discovery.RailOperationObserveConfirm) {
t.Fatalf("did not expect observe confirm operation to be present")
}
}
func TestRailCapabilitiesFromOperations(t *testing.T) {
cap := RailCapabilitiesFromOperations([]RailOperation{
discovery.RailOperationExternalDebit,
discovery.RailOperationExternalCredit,
discovery.RailOperationFee,
discovery.RailOperationObserveConfirm,
discovery.RailOperationBlock,
discovery.RailOperationRelease,
})
if !cap.CanPayIn {
t.Fatalf("expected can pay in to be true")
}
if !cap.CanPayOut {
t.Fatalf("expected can pay out to be true")
}
if !cap.CanSendFee {
t.Fatalf("expected can send fee to be true")
}
if !cap.RequiresObserveConfirm {
t.Fatalf("expected requires observe confirm to be true")
}
if !cap.CanBlock {
t.Fatalf("expected can block to be true")
}
if !cap.CanRelease {
t.Fatalf("expected can release to be true")
}
}