fixed doc env vars + mongo v2 migration
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/tech/sendico/ledger/storage/model"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -31,7 +31,7 @@ func (s *stubRepository) Balances() storage.BalancesStore { return s
|
||||
func (s *stubRepository) Outbox() storage.OutboxStore { return s.outbox }
|
||||
|
||||
type stubAccountsStore struct {
|
||||
getByID map[primitive.ObjectID]*pmodel.LedgerAccount
|
||||
getByID map[bson.ObjectID]*pmodel.LedgerAccount
|
||||
defaultSettlement *pmodel.LedgerAccount
|
||||
getErr error
|
||||
defaultErr error
|
||||
@@ -40,7 +40,7 @@ type stubAccountsStore struct {
|
||||
func (s *stubAccountsStore) Create(context.Context, *pmodel.LedgerAccount) error {
|
||||
return merrors.NotImplemented("create")
|
||||
}
|
||||
func (s *stubAccountsStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) Get(ctx context.Context, accountRef bson.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
if s.getErr != nil {
|
||||
return nil, s.getErr
|
||||
}
|
||||
@@ -49,16 +49,16 @@ func (s *stubAccountsStore) Get(ctx context.Context, accountRef primitive.Object
|
||||
}
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
func (s *stubAccountsStore) GetByAccountCode(context.Context, primitive.ObjectID, string, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) GetByAccountCode(context.Context, bson.ObjectID, string, string) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get by code")
|
||||
}
|
||||
func (s *stubAccountsStore) GetByRole(context.Context, primitive.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) GetByRole(context.Context, bson.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get by role")
|
||||
}
|
||||
func (s *stubAccountsStore) GetSystemAccount(context.Context, pmodel.SystemAccountPurpose, string) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get system account")
|
||||
}
|
||||
func (s *stubAccountsStore) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
if s.defaultErr != nil {
|
||||
return nil, s.defaultErr
|
||||
}
|
||||
@@ -67,21 +67,21 @@ func (s *stubAccountsStore) GetDefaultSettlement(context.Context, primitive.Obje
|
||||
}
|
||||
return s.defaultSettlement, nil
|
||||
}
|
||||
func (s *stubAccountsStore) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("list")
|
||||
}
|
||||
func (s *stubAccountsStore) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
func (s *stubAccountsStore) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
return merrors.NotImplemented("update status")
|
||||
}
|
||||
|
||||
type stubBalancesStore struct {
|
||||
records map[primitive.ObjectID]*model.AccountBalance
|
||||
records map[bson.ObjectID]*model.AccountBalance
|
||||
upserts []*model.AccountBalance
|
||||
getErr error
|
||||
upErr error
|
||||
}
|
||||
|
||||
func (s *stubBalancesStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) {
|
||||
func (s *stubBalancesStore) Get(ctx context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) {
|
||||
if s.getErr != nil {
|
||||
return nil, s.getErr
|
||||
}
|
||||
@@ -98,13 +98,13 @@ func (s *stubBalancesStore) Upsert(ctx context.Context, balance *model.AccountBa
|
||||
copied := *balance
|
||||
s.upserts = append(s.upserts, &copied)
|
||||
if s.records == nil {
|
||||
s.records = make(map[primitive.ObjectID]*model.AccountBalance)
|
||||
s.records = make(map[bson.ObjectID]*model.AccountBalance)
|
||||
}
|
||||
s.records[balance.AccountRef] = &copied
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *stubBalancesStore) IncrementBalance(context.Context, primitive.ObjectID, string) error {
|
||||
func (s *stubBalancesStore) IncrementBalance(context.Context, bson.ObjectID, string) error {
|
||||
return merrors.NotImplemented("increment")
|
||||
}
|
||||
|
||||
@@ -126,22 +126,22 @@ func (s *stubOutboxStore) ListPending(context.Context, int) ([]*model.OutboxEven
|
||||
return nil, merrors.NotImplemented("list")
|
||||
}
|
||||
|
||||
func (s *stubOutboxStore) MarkSent(context.Context, primitive.ObjectID, time.Time) error {
|
||||
func (s *stubOutboxStore) MarkSent(context.Context, bson.ObjectID, time.Time) error {
|
||||
return merrors.NotImplemented("mark sent")
|
||||
}
|
||||
|
||||
func (s *stubOutboxStore) MarkFailed(context.Context, primitive.ObjectID) error {
|
||||
func (s *stubOutboxStore) MarkFailed(context.Context, bson.ObjectID) error {
|
||||
return merrors.NotImplemented("mark failed")
|
||||
}
|
||||
|
||||
func (s *stubOutboxStore) IncrementAttempts(context.Context, primitive.ObjectID) error {
|
||||
func (s *stubOutboxStore) IncrementAttempts(context.Context, bson.ObjectID) error {
|
||||
return merrors.NotImplemented("increment attempts")
|
||||
}
|
||||
|
||||
func TestResolveSettlementAccount_Default(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
settlementID := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
settlementID := bson.NewObjectID()
|
||||
settlement := &pmodel.LedgerAccount{}
|
||||
settlement.SetID(settlementID)
|
||||
settlement.OrganizationRef = &orgRef
|
||||
@@ -151,7 +151,7 @@ func TestResolveSettlementAccount_Default(t *testing.T) {
|
||||
accounts := &stubAccountsStore{defaultSettlement: settlement}
|
||||
repo := &stubRepository{accounts: accounts}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
cache := make(map[primitive.ObjectID]*pmodel.LedgerAccount)
|
||||
cache := make(map[bson.ObjectID]*pmodel.LedgerAccount)
|
||||
|
||||
result, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", cache)
|
||||
|
||||
@@ -162,18 +162,18 @@ func TestResolveSettlementAccount_Default(t *testing.T) {
|
||||
|
||||
func TestResolveSettlementAccount_Override(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
overrideID := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
overrideID := bson.NewObjectID()
|
||||
override := &pmodel.LedgerAccount{}
|
||||
override.SetID(overrideID)
|
||||
override.OrganizationRef = &orgRef
|
||||
override.Currency = "EUR"
|
||||
override.Status = pmodel.LedgerAccountStatusActive
|
||||
|
||||
accounts := &stubAccountsStore{getByID: map[primitive.ObjectID]*pmodel.LedgerAccount{overrideID: override}}
|
||||
accounts := &stubAccountsStore{getByID: map[bson.ObjectID]*pmodel.LedgerAccount{overrideID: override}}
|
||||
repo := &stubRepository{accounts: accounts}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
cache := make(map[primitive.ObjectID]*pmodel.LedgerAccount)
|
||||
cache := make(map[bson.ObjectID]*pmodel.LedgerAccount)
|
||||
|
||||
result, err := service.resolveSettlementAccount(ctx, orgRef, "EUR", overrideID.Hex(), cache)
|
||||
|
||||
@@ -184,12 +184,12 @@ func TestResolveSettlementAccount_Override(t *testing.T) {
|
||||
|
||||
func TestResolveSettlementAccount_NoDefault(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
accounts := &stubAccountsStore{defaultErr: storage.ErrAccountNotFound}
|
||||
repo := &stubRepository{accounts: accounts}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
|
||||
_, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", map[primitive.ObjectID]*pmodel.LedgerAccount{})
|
||||
_, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", map[bson.ObjectID]*pmodel.LedgerAccount{})
|
||||
|
||||
require.Error(t, err)
|
||||
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
|
||||
@@ -197,8 +197,8 @@ func TestResolveSettlementAccount_NoDefault(t *testing.T) {
|
||||
|
||||
func TestUpsertBalances_Succeeds(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
accountRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
account := &pmodel.LedgerAccount{AllowNegative: false, Currency: "USD"}
|
||||
account.OrganizationRef = &orgRef
|
||||
|
||||
@@ -213,7 +213,7 @@ func TestUpsertBalances_Succeeds(t *testing.T) {
|
||||
balances := &stubBalancesStore{}
|
||||
repo := &stubRepository{balances: balances}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
accountCache := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
accountCache := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
|
||||
require.NoError(t, service.upsertBalances(ctx, balanceLines, accountCache))
|
||||
require.Len(t, balances.upserts, 1)
|
||||
@@ -224,8 +224,8 @@ func TestUpsertBalances_Succeeds(t *testing.T) {
|
||||
|
||||
func TestUpsertBalances_DisallowNegative(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
accountRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
account := &pmodel.LedgerAccount{AllowNegative: false, Currency: "USD"}
|
||||
account.OrganizationRef = &orgRef
|
||||
|
||||
@@ -240,7 +240,7 @@ func TestUpsertBalances_DisallowNegative(t *testing.T) {
|
||||
balances := &stubBalancesStore{}
|
||||
repo := &stubRepository{balances: balances}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
accountCache := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
accountCache := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
|
||||
err := service.upsertBalances(ctx, balanceLines, accountCache)
|
||||
|
||||
@@ -250,8 +250,8 @@ func TestUpsertBalances_DisallowNegative(t *testing.T) {
|
||||
|
||||
func TestEnqueueOutbox_CreatesEvent(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
entryID := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
entryID := bson.NewObjectID()
|
||||
entry := &model.JournalEntry{
|
||||
IdempotencyKey: "idem",
|
||||
EventTime: time.Now().UTC(),
|
||||
@@ -263,7 +263,7 @@ func TestEnqueueOutbox_CreatesEvent(t *testing.T) {
|
||||
|
||||
lines := []*model.PostingLine{
|
||||
{
|
||||
AccountRef: primitive.NewObjectID(),
|
||||
AccountRef: bson.NewObjectID(),
|
||||
Amount: "100",
|
||||
Currency: "USD",
|
||||
LineType: model.LineTypeMain,
|
||||
|
||||
Reference in New Issue
Block a user