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

@@ -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
},
}