fixed rail & operation names
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"github.com/tech/sendico/pkg/payments/rail"
|
||||
accountrolev1 "github.com/tech/sendico/pkg/proto/common/account_role/v1"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
|
||||
@@ -156,3 +157,36 @@ func TestPostExternalDebitWithCharges_SubmitsExternalOperation(t *testing.T) {
|
||||
assert.Equal(t, "op-ext-debit", resp.GetJournalEntryRef())
|
||||
assert.Equal(t, ledgerv1.EntryType_ENTRY_DEBIT, resp.GetEntryType())
|
||||
}
|
||||
|
||||
func TestCreateTransaction_NormalizesRailsForDirectionAndMetadata(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
var captured *connectorv1.Operation
|
||||
stub := &stubConnector{
|
||||
submitFn: func(ctx context.Context, req *connectorv1.SubmitOperationRequest) (*connectorv1.SubmitOperationResponse, error) {
|
||||
captured = req.GetOperation()
|
||||
return &connectorv1.SubmitOperationResponse{Receipt: &connectorv1.OperationReceipt{OperationId: "op-tx"}}, nil
|
||||
},
|
||||
}
|
||||
|
||||
client := NewWithClient(Config{}, stub)
|
||||
ref, err := client.CreateTransaction(ctx, rail.LedgerTx{
|
||||
IdempotencyKey: "idem-tx",
|
||||
OrganizationRef: "org-1",
|
||||
LedgerAccountRef: "acct-1",
|
||||
Currency: "USD",
|
||||
Amount: "10",
|
||||
FromRail: "rail_ledger",
|
||||
ToRail: "crypto",
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "op-tx", ref)
|
||||
require.NotNil(t, captured)
|
||||
assert.Equal(t, connectorv1.OperationType_DEBIT, captured.GetType())
|
||||
|
||||
metadata, ok := captured.GetParams().AsMap()["metadata"].(map[string]interface{})
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, discovery.RailLedger, metadata["from_rail"])
|
||||
assert.Equal(t, discovery.RailCrypto, metadata["to_rail"])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user