fixed doc env vars + mongo v2 migration

This commit is contained in:
Stephan D
2026-01-31 00:26:42 +01:00
parent cbb7bd8ba6
commit 1aa7e287fb
356 changed files with 1705 additions and 1729 deletions

View File

@@ -13,8 +13,8 @@ import (
pkm "github.com/tech/sendico/pkg/model"
"github.com/tech/sendico/pkg/mservice"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -114,7 +114,7 @@ func (a *accountsStore) Create(ctx context.Context, account *pkm.LedgerAccount)
return nil
}
func (a *accountsStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*pkm.LedgerAccount, error) {
func (a *accountsStore) Get(ctx context.Context, accountRef bson.ObjectID) (*pkm.LedgerAccount, error) {
if accountRef.IsZero() {
a.logger.Warn("Attempt to get account with zero ID")
return nil, merrors.InvalidArgument("accountsStore: zero account ID")
@@ -134,7 +134,7 @@ func (a *accountsStore) Get(ctx context.Context, accountRef primitive.ObjectID)
return result, nil
}
func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef primitive.ObjectID, accountCode, currency string) (*pkm.LedgerAccount, error) {
func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef bson.ObjectID, accountCode, currency string) (*pkm.LedgerAccount, error) {
if orgRef.IsZero() {
a.logger.Warn("Attempt to get account with zero organization ID")
return nil, merrors.InvalidArgument("accountsStore: zero organization ID")
@@ -167,7 +167,7 @@ func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef primitive.O
return result, nil
}
func (a *accountsStore) GetByRole(ctx context.Context, orgRef primitive.ObjectID, currency string, role pkm.AccountRole) (*pkm.LedgerAccount, error) {
func (a *accountsStore) GetByRole(ctx context.Context, orgRef bson.ObjectID, currency string, role pkm.AccountRole) (*pkm.LedgerAccount, error) {
if orgRef.IsZero() {
a.logger.Warn("Attempt to get account with zero organization ID")
return nil, merrors.InvalidArgument("accountsStore: zero organization ID")
@@ -240,7 +240,7 @@ func (a *accountsStore) GetSystemAccount(ctx context.Context, purpose pkm.System
return result, nil
}
func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef primitive.ObjectID, currency string) (*pkm.LedgerAccount, error) {
func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef bson.ObjectID, currency string) (*pkm.LedgerAccount, error) {
if orgRef.IsZero() {
a.logger.Warn("Attempt to get default settlement with zero organization ID")
return nil, merrors.InvalidArgument("accountsStore: zero organization ID")
@@ -275,7 +275,7 @@ func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef primiti
return result, nil
}
func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef primitive.ObjectID, filter *storage.AccountsFilter, limit int, offset int) ([]*pkm.LedgerAccount, error) {
func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef bson.ObjectID, filter *storage.AccountsFilter, limit int, offset int) ([]*pkm.LedgerAccount, error) {
if orgRef.IsZero() {
a.logger.Warn("Attempt to list accounts with zero organization reference")
return nil, merrors.InvalidArgument("accountsStore: zero organization reference")
@@ -316,7 +316,7 @@ func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef primitive
return accounts, nil
}
func (a *accountsStore) UpdateStatus(ctx context.Context, accountRef primitive.ObjectID, status pkm.LedgerAccountStatus) error {
func (a *accountsStore) UpdateStatus(ctx context.Context, accountRef bson.ObjectID, status pkm.LedgerAccountStatus) error {
if accountRef.IsZero() {
a.logger.Warn("Attempt to update account status with zero reference")
return merrors.InvalidArgument("accountsStore: zero account reference")

View File

@@ -14,8 +14,8 @@ import (
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/merrors"
pkm "github.com/tech/sendico/pkg/model"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -105,9 +105,9 @@ func TestAccountsStore_Get(t *testing.T) {
logger := zap.NewNop()
t.Run("Success", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
stub := &repositoryStub{
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
account := result.(*pkm.LedgerAccount)
account.SetID(accountRef)
account.AccountCode = "1000"
@@ -129,7 +129,7 @@ func TestAccountsStore_Get(t *testing.T) {
stub := &repositoryStub{}
store := &accountsStore{logger: logger, repo: stub}
result, err := store.Get(ctx, primitive.NilObjectID)
result, err := store.Get(ctx, bson.NilObjectID)
require.Error(t, err)
assert.Nil(t, result)
@@ -137,9 +137,9 @@ func TestAccountsStore_Get(t *testing.T) {
})
t.Run("NotFound", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
stub := &repositoryStub{
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
return merrors.ErrNoData
},
}
@@ -153,10 +153,10 @@ func TestAccountsStore_Get(t *testing.T) {
})
t.Run("GetError", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
expectedErr := errors.New("database error")
stub := &repositoryStub{
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
return expectedErr
},
}
@@ -173,7 +173,7 @@ func TestAccountsStore_Get(t *testing.T) {
func TestAccountsStore_GetByAccountCode(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
orgRef := primitive.NewObjectID()
orgRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
stub := &repositoryStub{
@@ -198,7 +198,7 @@ func TestAccountsStore_GetByAccountCode(t *testing.T) {
stub := &repositoryStub{}
store := &accountsStore{logger: logger, repo: stub}
result, err := store.GetByAccountCode(ctx, primitive.NilObjectID, "1000", "USD")
result, err := store.GetByAccountCode(ctx, bson.NilObjectID, "1000", "USD")
require.Error(t, err)
assert.Nil(t, result)
@@ -246,7 +246,7 @@ func TestAccountsStore_GetByAccountCode(t *testing.T) {
func TestAccountsStore_GetByRole(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
orgRef := primitive.NewObjectID()
orgRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
stub := &repositoryStub{
@@ -269,7 +269,7 @@ func TestAccountsStore_GetByRole(t *testing.T) {
t.Run("ZeroOrganizationID", func(t *testing.T) {
store := &accountsStore{logger: logger, repo: &repositoryStub{}}
result, err := store.GetByRole(ctx, primitive.NilObjectID, "USD", pkm.AccountRoleOperating)
result, err := store.GetByRole(ctx, bson.NilObjectID, "USD", pkm.AccountRoleOperating)
require.Error(t, err)
assert.Nil(t, result)
@@ -329,13 +329,13 @@ func TestAccountsStore_GetByRole(t *testing.T) {
func TestAccountsStore_GetDefaultSettlement(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
orgRef := primitive.NewObjectID()
orgRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
stub := &repositoryStub{
FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error {
account := result.(*pkm.LedgerAccount)
account.SetID(primitive.NewObjectID())
account.SetID(bson.NewObjectID())
account.Currency = "USD"
account.Role = pkm.AccountRoleSettlement
return nil
@@ -353,7 +353,7 @@ func TestAccountsStore_GetDefaultSettlement(t *testing.T) {
t.Run("ZeroOrganizationID", func(t *testing.T) {
store := &accountsStore{logger: logger, repo: &repositoryStub{}}
result, err := store.GetDefaultSettlement(ctx, primitive.NilObjectID, "USD")
result, err := store.GetDefaultSettlement(ctx, bson.NilObjectID, "USD")
require.Error(t, err)
assert.Nil(t, result)
@@ -481,7 +481,7 @@ func TestAccountsStore_GetSystemAccount(t *testing.T) {
func TestAccountsStore_ListByOrganization(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
orgRef := primitive.NewObjectID()
orgRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
var calledWithQuery bool
@@ -506,7 +506,7 @@ func TestAccountsStore_ListByOrganization(t *testing.T) {
stub := &repositoryStub{}
store := &accountsStore{logger: logger, repo: stub}
results, err := store.ListByOrganization(ctx, primitive.NilObjectID, nil, 10, 0)
results, err := store.ListByOrganization(ctx, bson.NilObjectID, nil, 10, 0)
require.Error(t, err)
assert.Nil(t, results)
@@ -547,13 +547,13 @@ func TestAccountsStore_ListByOrganization(t *testing.T) {
func TestAccountsStore_UpdateStatus(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
var patchedID primitive.ObjectID
var patchedID bson.ObjectID
var patchedStatus pkm.LedgerAccountStatus
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
patchedID = id
// In real test, we'd inspect patch builder but this is sufficient for stub
patchedStatus = pkm.LedgerAccountStatusFrozen
@@ -573,7 +573,7 @@ func TestAccountsStore_UpdateStatus(t *testing.T) {
stub := &repositoryStub{}
store := &accountsStore{logger: logger, repo: stub}
err := store.UpdateStatus(ctx, primitive.NilObjectID, pkm.LedgerAccountStatusFrozen)
err := store.UpdateStatus(ctx, bson.NilObjectID, pkm.LedgerAccountStatusFrozen)
require.Error(t, err)
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
@@ -582,7 +582,7 @@ func TestAccountsStore_UpdateStatus(t *testing.T) {
t.Run("PatchError", func(t *testing.T) {
expectedErr := errors.New("database error")
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
return expectedErr
},
}

View File

@@ -11,8 +11,8 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -45,7 +45,7 @@ func NewBalances(logger mlogger.Logger, db *mongo.Database) (storage.BalancesSto
}, nil
}
func (b *balancesStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) {
func (b *balancesStore) Get(ctx context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) {
if accountRef.IsZero() {
b.logger.Warn("attempt to get balance with zero account ID")
return nil, merrors.InvalidArgument("balancesStore: zero account ID")
@@ -98,7 +98,7 @@ func (b *balancesStore) Upsert(ctx context.Context, balance *model.AccountBalanc
return b.repo.Update(ctx, balance)
}
func (b *balancesStore) IncrementBalance(ctx context.Context, accountRef primitive.ObjectID, amount string) error {
func (b *balancesStore) IncrementBalance(ctx context.Context, accountRef bson.ObjectID, amount string) error {
if accountRef.IsZero() {
b.logger.Warn("attempt to increment balance with zero account ID")
return merrors.InvalidArgument("balancesStore: zero account ID")

View File

@@ -5,14 +5,14 @@ import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tech/sendico/ledger/storage"
"github.com/tech/sendico/ledger/storage/model"
"github.com/tech/sendico/pkg/db/repository/builder"
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/merrors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -21,7 +21,7 @@ func TestBalancesStore_Get(t *testing.T) {
logger := zap.NewNop()
t.Run("Success", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
stub := &repositoryStub{
FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error {
balance := result.(*model.AccountBalance)
@@ -46,7 +46,7 @@ func TestBalancesStore_Get(t *testing.T) {
stub := &repositoryStub{}
store := &balancesStore{logger: logger, repo: stub}
result, err := store.Get(ctx, primitive.NilObjectID)
result, err := store.Get(ctx, bson.NilObjectID)
require.Error(t, err)
assert.Nil(t, result)
@@ -54,7 +54,7 @@ func TestBalancesStore_Get(t *testing.T) {
})
t.Run("NotFound", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
stub := &repositoryStub{
FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error {
return merrors.ErrNoData
@@ -70,7 +70,7 @@ func TestBalancesStore_Get(t *testing.T) {
})
t.Run("FindError", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
expectedErr := errors.New("database error")
stub := &repositoryStub{
FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error {
@@ -92,7 +92,7 @@ func TestBalancesStore_Upsert(t *testing.T) {
logger := zap.NewNop()
t.Run("Insert_NewBalance", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
var insertedBalance *model.AccountBalance
stub := &repositoryStub{
@@ -120,8 +120,8 @@ func TestBalancesStore_Upsert(t *testing.T) {
})
t.Run("Update_ExistingBalance", func(t *testing.T) {
accountRef := primitive.NewObjectID()
existingID := primitive.NewObjectID()
accountRef := bson.NewObjectID()
existingID := bson.NewObjectID()
var updatedBalance *model.AccountBalance
stub := &repositoryStub{
@@ -170,7 +170,7 @@ func TestBalancesStore_Upsert(t *testing.T) {
store := &balancesStore{logger: logger, repo: stub}
balance := &model.AccountBalance{
AccountRef: primitive.NilObjectID,
AccountRef: bson.NilObjectID,
Balance: "100.00",
}
@@ -181,7 +181,7 @@ func TestBalancesStore_Upsert(t *testing.T) {
})
t.Run("FindError", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
expectedErr := errors.New("database error")
stub := &repositoryStub{
@@ -203,7 +203,7 @@ func TestBalancesStore_Upsert(t *testing.T) {
})
t.Run("InsertError", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
expectedErr := errors.New("insert error")
stub := &repositoryStub{
@@ -228,8 +228,8 @@ func TestBalancesStore_Upsert(t *testing.T) {
})
t.Run("UpdateError", func(t *testing.T) {
accountRef := primitive.NewObjectID()
existingID := primitive.NewObjectID()
accountRef := bson.NewObjectID()
existingID := bson.NewObjectID()
expectedErr := errors.New("update error")
stub := &repositoryStub{
@@ -263,7 +263,7 @@ func TestBalancesStore_IncrementBalance(t *testing.T) {
logger := zap.NewNop()
t.Run("NotImplemented", func(t *testing.T) {
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
stub := &repositoryStub{}
store := &balancesStore{logger: logger, repo: stub}
@@ -277,7 +277,7 @@ func TestBalancesStore_IncrementBalance(t *testing.T) {
stub := &repositoryStub{}
store := &balancesStore{logger: logger, repo: stub}
err := store.IncrementBalance(ctx, primitive.NilObjectID, "100.00")
err := store.IncrementBalance(ctx, bson.NilObjectID, "100.00")
require.Error(t, err)
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))

View File

@@ -11,8 +11,8 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -78,7 +78,7 @@ func (j *journalEntriesStore) Create(ctx context.Context, entry *model.JournalEn
return nil
}
func (j *journalEntriesStore) Get(ctx context.Context, entryRef primitive.ObjectID) (*model.JournalEntry, error) {
func (j *journalEntriesStore) Get(ctx context.Context, entryRef bson.ObjectID) (*model.JournalEntry, error) {
if entryRef.IsZero() {
j.logger.Warn("attempt to get journal entry with zero ID")
return nil, merrors.InvalidArgument("journalEntriesStore: zero entry ID")
@@ -99,7 +99,7 @@ func (j *journalEntriesStore) Get(ctx context.Context, entryRef primitive.Object
return result, nil
}
func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.JournalEntry, error) {
func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.JournalEntry, error) {
if orgRef.IsZero() {
j.logger.Warn("attempt to get journal entry with zero organization ID")
return nil, merrors.InvalidArgument("journalEntriesStore: zero organization ID")
@@ -128,7 +128,7 @@ func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef pr
return result, nil
}
func (j *journalEntriesStore) ListByOrganization(ctx context.Context, orgRef primitive.ObjectID, limit int, offset int) ([]*model.JournalEntry, error) {
func (j *journalEntriesStore) ListByOrganization(ctx context.Context, orgRef bson.ObjectID, limit int, offset int) ([]*model.JournalEntry, error) {
if orgRef.IsZero() {
j.logger.Warn("attempt to list journal entries with zero organization ID")
return nil, merrors.InvalidArgument("journalEntriesStore: zero organization ID")

View File

@@ -6,16 +6,16 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tech/sendico/ledger/storage"
"github.com/tech/sendico/ledger/storage/model"
"github.com/tech/sendico/pkg/db/repository/builder"
rd "github.com/tech/sendico/pkg/db/repository/decoder"
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/merrors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -107,9 +107,9 @@ func TestJournalEntriesStore_Get(t *testing.T) {
logger := zap.NewNop()
t.Run("Success", func(t *testing.T) {
entryRef := primitive.NewObjectID()
entryRef := bson.NewObjectID()
stub := &repositoryStub{
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
entry := result.(*model.JournalEntry)
entry.SetID(entryRef)
entry.IdempotencyKey = "test-key-123"
@@ -131,7 +131,7 @@ func TestJournalEntriesStore_Get(t *testing.T) {
stub := &repositoryStub{}
store := &journalEntriesStore{logger: logger, repo: stub}
result, err := store.Get(ctx, primitive.NilObjectID)
result, err := store.Get(ctx, bson.NilObjectID)
require.Error(t, err)
assert.Nil(t, result)
@@ -139,9 +139,9 @@ func TestJournalEntriesStore_Get(t *testing.T) {
})
t.Run("NotFound", func(t *testing.T) {
entryRef := primitive.NewObjectID()
entryRef := bson.NewObjectID()
stub := &repositoryStub{
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
return merrors.ErrNoData
},
}
@@ -158,7 +158,7 @@ func TestJournalEntriesStore_Get(t *testing.T) {
func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
orgRef := primitive.NewObjectID()
orgRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
stub := &repositoryStub{
@@ -183,7 +183,7 @@ func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) {
stub := &repositoryStub{}
store := &journalEntriesStore{logger: logger, repo: stub}
result, err := store.GetByIdempotencyKey(ctx, primitive.NilObjectID, "test-key")
result, err := store.GetByIdempotencyKey(ctx, bson.NilObjectID, "test-key")
require.Error(t, err)
assert.Nil(t, result)
@@ -220,7 +220,7 @@ func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) {
func TestJournalEntriesStore_ListByOrganization(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
orgRef := primitive.NewObjectID()
orgRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
called := false
@@ -243,7 +243,7 @@ func TestJournalEntriesStore_ListByOrganization(t *testing.T) {
stub := &repositoryStub{}
store := &journalEntriesStore{logger: logger, repo: stub}
results, err := store.ListByOrganization(ctx, primitive.NilObjectID, 10, 0)
results, err := store.ListByOrganization(ctx, bson.NilObjectID, 10, 0)
require.Error(t, err)
assert.Nil(t, results)

View File

@@ -10,8 +10,8 @@ import (
ri "github.com/tech/sendico/pkg/db/repository/index"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -101,7 +101,7 @@ func (o *outboxStore) ListPending(ctx context.Context, limit int) ([]*model.Outb
return events, nil
}
func (o *outboxStore) MarkSent(ctx context.Context, eventRef primitive.ObjectID, sentAt time.Time) error {
func (o *outboxStore) MarkSent(ctx context.Context, eventRef bson.ObjectID, sentAt time.Time) error {
if eventRef.IsZero() {
o.logger.Warn("attempt to mark sent with zero event ID")
return merrors.InvalidArgument("outboxStore: zero event ID")
@@ -120,7 +120,7 @@ func (o *outboxStore) MarkSent(ctx context.Context, eventRef primitive.ObjectID,
return nil
}
func (o *outboxStore) MarkFailed(ctx context.Context, eventRef primitive.ObjectID) error {
func (o *outboxStore) MarkFailed(ctx context.Context, eventRef bson.ObjectID) error {
if eventRef.IsZero() {
o.logger.Warn("attempt to mark failed with zero event ID")
return merrors.InvalidArgument("outboxStore: zero event ID")
@@ -137,7 +137,7 @@ func (o *outboxStore) MarkFailed(ctx context.Context, eventRef primitive.ObjectI
return nil
}
func (o *outboxStore) IncrementAttempts(ctx context.Context, eventRef primitive.ObjectID) error {
func (o *outboxStore) IncrementAttempts(ctx context.Context, eventRef bson.ObjectID) error {
if eventRef.IsZero() {
o.logger.Warn("attempt to increment attempts with zero event ID")
return merrors.InvalidArgument("outboxStore: zero event ID")

View File

@@ -6,16 +6,16 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tech/sendico/ledger/storage/model"
"github.com/tech/sendico/pkg/db/repository"
"github.com/tech/sendico/pkg/db/repository/builder"
rd "github.com/tech/sendico/pkg/db/repository/decoder"
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/merrors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -176,13 +176,13 @@ func TestOutboxStore_ListPending(t *testing.T) {
func TestOutboxStore_MarkSent(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
eventRef := primitive.NewObjectID()
eventRef := bson.NewObjectID()
sentTime := time.Now()
t.Run("Success", func(t *testing.T) {
var patchedID primitive.ObjectID
var patchedID bson.ObjectID
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
patchedID = id
return nil
},
@@ -199,7 +199,7 @@ func TestOutboxStore_MarkSent(t *testing.T) {
stub := &repositoryStub{}
store := &outboxStore{logger: logger, repo: stub}
err := store.MarkSent(ctx, primitive.NilObjectID, sentTime)
err := store.MarkSent(ctx, bson.NilObjectID, sentTime)
require.Error(t, err)
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
@@ -208,7 +208,7 @@ func TestOutboxStore_MarkSent(t *testing.T) {
t.Run("PatchError", func(t *testing.T) {
expectedErr := errors.New("database error")
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
return expectedErr
},
}
@@ -224,12 +224,12 @@ func TestOutboxStore_MarkSent(t *testing.T) {
func TestOutboxStore_MarkFailed(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
eventRef := primitive.NewObjectID()
eventRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
var patchedID primitive.ObjectID
var patchedID bson.ObjectID
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
patchedID = id
return nil
},
@@ -246,7 +246,7 @@ func TestOutboxStore_MarkFailed(t *testing.T) {
stub := &repositoryStub{}
store := &outboxStore{logger: logger, repo: stub}
err := store.MarkFailed(ctx, primitive.NilObjectID)
err := store.MarkFailed(ctx, bson.NilObjectID)
require.Error(t, err)
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
@@ -255,7 +255,7 @@ func TestOutboxStore_MarkFailed(t *testing.T) {
t.Run("PatchError", func(t *testing.T) {
expectedErr := errors.New("database error")
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
return expectedErr
},
}
@@ -271,12 +271,12 @@ func TestOutboxStore_MarkFailed(t *testing.T) {
func TestOutboxStore_IncrementAttempts(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
eventRef := primitive.NewObjectID()
eventRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
var patchedID primitive.ObjectID
var patchedID bson.ObjectID
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
patchedID = id
return nil
},
@@ -293,7 +293,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) {
stub := &repositoryStub{}
store := &outboxStore{logger: logger, repo: stub}
err := store.IncrementAttempts(ctx, primitive.NilObjectID)
err := store.IncrementAttempts(ctx, bson.NilObjectID)
require.Error(t, err)
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
@@ -302,7 +302,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) {
t.Run("PatchError", func(t *testing.T) {
expectedErr := errors.New("database error")
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
return expectedErr
},
}
@@ -317,7 +317,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) {
t.Run("MultipleIncrements", func(t *testing.T) {
var callCount int
stub := &repositoryStub{
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
callCount++
return nil
},

View File

@@ -11,8 +11,8 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -80,7 +80,7 @@ func (p *postingLinesStore) CreateMany(ctx context.Context, lines []*model.Posti
return nil
}
func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef primitive.ObjectID) ([]*model.PostingLine, error) {
func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef bson.ObjectID) ([]*model.PostingLine, error) {
if entryRef.IsZero() {
p.logger.Warn("attempt to list posting lines with zero entry ID")
return nil, merrors.InvalidArgument("postingLinesStore: zero entry ID")
@@ -106,7 +106,7 @@ func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef pri
return lines, nil
}
func (p *postingLinesStore) ListByAccount(ctx context.Context, accountRef primitive.ObjectID, limit int, offset int) ([]*model.PostingLine, error) {
func (p *postingLinesStore) ListByAccount(ctx context.Context, accountRef bson.ObjectID, limit int, offset int) ([]*model.PostingLine, error) {
if accountRef.IsZero() {
p.logger.Warn("attempt to list posting lines with zero account ID")
return nil, merrors.InvalidArgument("postingLinesStore: zero account ID")

View File

@@ -5,14 +5,14 @@ import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tech/sendico/ledger/storage/model"
"github.com/tech/sendico/pkg/db/repository/builder"
rd "github.com/tech/sendico/pkg/db/repository/decoder"
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/merrors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -32,14 +32,14 @@ func TestPostingLinesStore_CreateMany(t *testing.T) {
store := &postingLinesStore{logger: logger, repo: stub}
lines := []*model.PostingLine{
{
JournalEntryRef: primitive.NewObjectID(),
AccountRef: primitive.NewObjectID(),
JournalEntryRef: bson.NewObjectID(),
AccountRef: bson.NewObjectID(),
LineType: model.LineTypeMain,
Amount: "100.00",
},
{
JournalEntryRef: primitive.NewObjectID(),
AccountRef: primitive.NewObjectID(),
JournalEntryRef: bson.NewObjectID(),
AccountRef: bson.NewObjectID(),
LineType: model.LineTypeMain,
Amount: "100.00",
},
@@ -104,9 +104,9 @@ func TestPostingLinesStore_CreateMany(t *testing.T) {
}
store := &postingLinesStore{logger: logger, repo: stub}
entryRef := primitive.NewObjectID()
cashAccount := primitive.NewObjectID()
revenueAccount := primitive.NewObjectID()
entryRef := bson.NewObjectID()
cashAccount := bson.NewObjectID()
revenueAccount := bson.NewObjectID()
lines := []*model.PostingLine{
{
@@ -133,7 +133,7 @@ func TestPostingLinesStore_CreateMany(t *testing.T) {
func TestPostingLinesStore_ListByJournalEntry(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
entryRef := primitive.NewObjectID()
entryRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
called := false
@@ -156,7 +156,7 @@ func TestPostingLinesStore_ListByJournalEntry(t *testing.T) {
stub := &repositoryStub{}
store := &postingLinesStore{logger: logger, repo: stub}
results, err := store.ListByJournalEntry(ctx, primitive.NilObjectID)
results, err := store.ListByJournalEntry(ctx, bson.NilObjectID)
require.Error(t, err)
assert.Nil(t, results)
@@ -197,7 +197,7 @@ func TestPostingLinesStore_ListByJournalEntry(t *testing.T) {
func TestPostingLinesStore_ListByAccount(t *testing.T) {
ctx := context.Background()
logger := zap.NewNop()
accountRef := primitive.NewObjectID()
accountRef := bson.NewObjectID()
t.Run("Success", func(t *testing.T) {
called := false
@@ -220,7 +220,7 @@ func TestPostingLinesStore_ListByAccount(t *testing.T) {
stub := &repositoryStub{}
store := &postingLinesStore{logger: logger, repo: stub}
results, err := store.ListByAccount(ctx, primitive.NilObjectID, 10, 0)
results, err := store.ListByAccount(ctx, bson.NilObjectID, 10, 0)
require.Error(t, err)
assert.Nil(t, results)

View File

@@ -9,23 +9,23 @@ import (
ri "github.com/tech/sendico/pkg/db/repository/index"
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/model"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// repositoryStub provides a stub implementation of repository.Repository for testing
type repositoryStub struct {
AggregateFunc func(ctx context.Context, pipeline builder.Pipeline, decoder rd.DecodingFunc) error
GetFunc func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error
GetFunc func(ctx context.Context, id bson.ObjectID, result storable.Storable) error
InsertFunc func(ctx context.Context, object storable.Storable, filter builder.Query) error
InsertManyFunc func(ctx context.Context, objects []storable.Storable) error
UpdateFunc func(ctx context.Context, object storable.Storable) error
DeleteFunc func(ctx context.Context, id primitive.ObjectID) error
DeleteFunc func(ctx context.Context, id bson.ObjectID) error
FindOneByFilterFunc func(ctx context.Context, filter builder.Query, result storable.Storable) error
FindManyByFilterFunc func(ctx context.Context, filter builder.Query, decoder rd.DecodingFunc) error
PatchFunc func(ctx context.Context, id primitive.ObjectID, patch repository.PatchDoc) error
PatchFunc func(ctx context.Context, id bson.ObjectID, patch repository.PatchDoc) error
PatchManyFunc func(ctx context.Context, filter repository.FilterQuery, patch repository.PatchDoc) (int, error)
DeleteManyFunc func(ctx context.Context, query builder.Query) error
ListIDsFunc func(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error)
ListIDsFunc func(ctx context.Context, query builder.Query) ([]bson.ObjectID, error)
CreateIndexFunc func(def *ri.Definition) error
}
@@ -36,7 +36,7 @@ func (r *repositoryStub) Aggregate(ctx context.Context, pipeline builder.Pipelin
return nil
}
func (r *repositoryStub) Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
func (r *repositoryStub) Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
if r.GetFunc != nil {
return r.GetFunc(ctx, id, result)
}
@@ -64,7 +64,7 @@ func (r *repositoryStub) Update(ctx context.Context, object storable.Storable) e
return nil
}
func (r *repositoryStub) Delete(ctx context.Context, id primitive.ObjectID) error {
func (r *repositoryStub) Delete(ctx context.Context, id bson.ObjectID) error {
if r.DeleteFunc != nil {
return r.DeleteFunc(ctx, id)
}
@@ -85,7 +85,7 @@ func (r *repositoryStub) FindManyByFilter(ctx context.Context, filter builder.Qu
return nil
}
func (r *repositoryStub) Patch(ctx context.Context, id primitive.ObjectID, patch repository.PatchDoc) error {
func (r *repositoryStub) Patch(ctx context.Context, id bson.ObjectID, patch repository.PatchDoc) error {
if r.PatchFunc != nil {
return r.PatchFunc(ctx, id, patch)
}
@@ -106,7 +106,7 @@ func (r *repositoryStub) DeleteMany(ctx context.Context, query builder.Query) er
return nil
}
func (r *repositoryStub) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) {
func (r *repositoryStub) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) {
if r.ListIDsFunc != nil {
return r.ListIDsFunc(ctx, query)
}