Files
sxchnge/backend/edge/shared/storage/organization/setarchived_test.go
T

52 lines
1.5 KiB
Go

package organization
import (
"context"
"errors"
"testing"
"git.sendico.io/tech/sxchnge/bff/pkg/merrors"
"git.sendico.io/tech/sxchnge/bff/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/v2/bson"
)
func TestOrganizationDB_SetArchived_TogglesState(t *testing.T) {
ctx := context.Background()
accountRef := bson.NewObjectID()
orgDB := newTestOrganizationDB(t)
org := &model.Organization{
OrganizationBase: model.OrganizationBase{
Describable: model.Describable{Name: "Sendico"},
TimeZone: "UTC",
},
}
org.SetID(bson.NewObjectID())
require.NoError(t, orgDB.Create(ctx, accountRef, *org.GetID(), org))
var stored model.Organization
require.NoError(t, orgDB.Get(ctx, accountRef, *org.GetID(), &stored))
assert.False(t, stored.IsArchived())
require.NoError(t, orgDB.SetArchived(ctx, accountRef, *org.GetID(), true, false))
require.NoError(t, orgDB.Get(ctx, accountRef, *org.GetID(), &stored))
assert.True(t, stored.IsArchived())
require.NoError(t, orgDB.SetArchived(ctx, accountRef, *org.GetID(), false, false))
require.NoError(t, orgDB.Get(ctx, accountRef, *org.GetID(), &stored))
assert.False(t, stored.IsArchived())
}
func TestOrganizationDB_SetArchived_UnknownOrganization(t *testing.T) {
ctx := context.Background()
accountRef := bson.NewObjectID()
orgDB := newTestOrganizationDB(t)
err := orgDB.SetArchived(ctx, accountRef, bson.NewObjectID(), true, false)
require.Error(t, err)
assert.True(t, errors.Is(err, merrors.ErrNoData))
}