Remove platform tenancy from SXCHNGE customer BFF (#34)

This commit is contained in:
Stephan D committed 2026-09-12 14:00:14 +02:00
1 parent 7062672a87
commit 981e84a4b4
244 files changed
+651 -17130

No files matched your search

@@ -10,7 +10,6 @@ import (
"git.sendico.io/tech/sxchnge/bff/pkg/db/storable"
"git.sendico.io/tech/sxchnge/bff/pkg/db/transaction"
"git.sendico.io/tech/sxchnge/bff/pkg/merrors"
"git.sendico.io/tech/sxchnge/bff/pkg/model"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
@@ -227,57 +226,6 @@ func (r *MongoRepository) ListIDs(ctx context.Context, query builder.Query) ([]b
return ids, nil
}
func (r *MongoRepository) ListPermissionBound(ctx context.Context, query builder.Query) ([]model.PermissionBoundStorable, error) {
return listProjectedStorables(ctx, r.collection, query, bson.M{
storable.IDField: 1,
storable.PermissionRefField: 1,
storable.OrganizationRefField: 1,
}, func(doc *model.PermissionBound) model.PermissionBoundStorable {
return doc
})
}
func (r *MongoRepository) ListAccountBound(ctx context.Context, query builder.Query) ([]model.AccountBoundStorable, error) {
return listProjectedStorables(ctx, r.collection, query, bson.M{
storable.IDField: 1,
model.AccountRefField: 1,
model.OrganizationRefField: 1,
}, func(doc *model.AccountBoundBase) model.AccountBoundStorable {
return doc
})
}
func listProjectedStorables[T any, R any](
ctx context.Context,
collection *mongo.Collection,
query builder.Query,
projection bson.M,
wrap func(*T) R,
) ([]R, error) {
filter := query.BuildQuery()
cursor, err := collection.Find(ctx, filter, options.Find().SetProjection(projection))
if err != nil {
return nil, err
}
defer func() {
_ = cursor.Close(ctx)
}()
result := make([]R, 0)
for cursor.Next(ctx) {
doc := new(T)
if err := cursor.Decode(doc); err != nil {
return nil, err
}
result = append(result, wrap(doc))
}
if err := cursor.Err(); err != nil {
return nil, err
}
return result, nil
}
func (r *MongoRepository) Delete(ctx context.Context, id bson.ObjectID) error {
_, err := r.collection.DeleteOne(ctx, idFilter(id))
return err
@@ -446,72 +446,6 @@ func TestMongoRepository_Name(t *testing.T) {
})
}
func TestMongoRepository_ListPermissionBound(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
mongoContainer, err := mongodb.Run(ctx,
"mongo:latest",
mongodb.WithUsername("root"),
mongodb.WithPassword("password"),
testcontainers.WithWaitStrategy(wait.ForLog("Waiting for connections")),
)
require.NoError(t, err, "failed to start MongoDB container")
defer terminate(ctx, t, mongoContainer)
mongoURI, err := mongoContainer.ConnectionString(ctx)
require.NoError(t, err, "failed to get MongoDB connection string")
clientOptions := options.Client().ApplyURI(mongoURI)
client, err := mongo.Connect(clientOptions)
require.NoError(t, err, "failed to connect to MongoDB")
defer disconnect(ctx, t, client)
db := client.Database("testdb")
repository := repositoryimp.NewMongoRepository(db, "testcollection")
t.Run("ListPermissionBound_WithData", func(t *testing.T) {
// Insert test objects with permission bound data
orgID := bson.NewObjectID()
// Insert documents directly with permission bound fields
_, err := db.Collection("testcollection").InsertMany(ctx, []interface{}{
bson.M{
"_id": bson.NewObjectID(),
"organizationRef": orgID,
"permissionRef": bson.NewObjectID(),
},
bson.M{
"_id": bson.NewObjectID(),
"organizationRef": orgID,
"permissionRef": bson.NewObjectID(),
},
})
require.NoError(t, err)
// Query for permission bound objects
query := builderimp.NewQueryImp().Comparison(builderimp.NewFieldImp("organizationRef"), builder.Eq, orgID)
results, err := repository.ListPermissionBound(ctx, query)
require.NoError(t, err)
assert.Len(t, results, 2)
for _, result := range results {
assert.Equal(t, orgID, result.GetOrganizationRef())
assert.NotNil(t, result.GetPermissionRef())
}
})
t.Run("ListPermissionBound_EmptyResult", func(t *testing.T) {
nonExistentOrgID := bson.NewObjectID()
query := builderimp.NewQueryImp().Comparison(builderimp.NewFieldImp("organizationRef"), builder.Eq, nonExistentOrgID)
results, err := repository.ListPermissionBound(ctx, query)
require.NoError(t, err)
assert.Empty(t, results)
})
}
func TestMongoRepository_UpdateTimestamp(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()