refactored payment orchestration
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/tech/sendico/ledger/storage"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/model/account_role"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
)
|
||||
|
||||
@@ -21,14 +22,14 @@ type accountStoreStub struct {
|
||||
created []*pmodel.LedgerAccount
|
||||
existing *pmodel.LedgerAccount
|
||||
existingErr error
|
||||
existingByRole map[pmodel.AccountRole]*pmodel.LedgerAccount
|
||||
existingByRole map[account_role.AccountRole]*pmodel.LedgerAccount
|
||||
defaultSettlement *pmodel.LedgerAccount
|
||||
defaultErr error
|
||||
createErrs []error
|
||||
}
|
||||
|
||||
func (s *accountStoreStub) Create(_ context.Context, account *pmodel.LedgerAccount) error {
|
||||
if account.Role == pmodel.AccountRoleSettlement {
|
||||
if account.Role == account_role.AccountRoleSettlement {
|
||||
if s.createErrSettlement != nil {
|
||||
return s.createErrSettlement
|
||||
}
|
||||
@@ -66,7 +67,7 @@ func (s *accountStoreStub) Get(context.Context, bson.ObjectID) (*pmodel.LedgerAc
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
|
||||
func (s *accountStoreStub) GetByRole(_ context.Context, orgRef bson.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
func (s *accountStoreStub) GetByRole(_ context.Context, orgRef bson.ObjectID, currency string, role account_role.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
if s.existingByRole != nil {
|
||||
if acc, ok := s.existingByRole[role]; ok {
|
||||
return acc, nil
|
||||
@@ -190,14 +191,14 @@ func TestCreateAccountResponder_AutoCreatesSettlementAccount(t *testing.T) {
|
||||
var settlement *pmodel.LedgerAccount
|
||||
var operating *pmodel.LedgerAccount
|
||||
|
||||
roles := make(map[pmodel.AccountRole]bool)
|
||||
roles := make(map[account_role.AccountRole]bool)
|
||||
for _, acc := range accountStore.created {
|
||||
roles[acc.Role] = true
|
||||
|
||||
if acc.Role == pmodel.AccountRoleSettlement {
|
||||
if acc.Role == account_role.AccountRoleSettlement {
|
||||
settlement = acc
|
||||
}
|
||||
if acc.Role == pmodel.AccountRoleOperating {
|
||||
if acc.Role == account_role.AccountRoleOperating {
|
||||
operating = acc
|
||||
}
|
||||
|
||||
@@ -230,7 +231,7 @@ func TestCreateAccountResponder_AutoCreatesSettlementAccount(t *testing.T) {
|
||||
require.Equal(t, pmodel.LedgerAccountTypeAsset, settlement.AccountType)
|
||||
require.Equal(t, "USD", settlement.Currency)
|
||||
require.False(t, settlement.AllowNegative)
|
||||
require.Equal(t, pmodel.AccountRoleSettlement, settlement.Role)
|
||||
require.Equal(t, account_role.AccountRoleSettlement, settlement.Role)
|
||||
require.Equal(t, "true", settlement.Metadata["system"])
|
||||
}
|
||||
|
||||
@@ -265,7 +266,7 @@ func TestCreateAccountResponder_RetriesOnConflict(t *testing.T) {
|
||||
|
||||
var createdFee *pmodel.LedgerAccount
|
||||
for _, acc := range accountStore.created {
|
||||
if acc.Role == pmodel.AccountRoleFee {
|
||||
if acc.Role == account_role.AccountRoleFee {
|
||||
createdFee = acc
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user