mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-14 03:37:35 +00:00
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! adding more tests for ListOrganization()
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
v2beta "github.com/zitadel/zitadel/pkg/grpc/object/v2beta"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
// TODO fix below
|
||||
org "github.com/zitadel/zitadel/pkg/grpc/org/v2beta"
|
||||
@@ -79,7 +80,7 @@ func createdOrganizationToPb(createdOrg *command.CreatedOrg) (_ *org.CreateOrgan
|
||||
}
|
||||
}
|
||||
return &org.CreateOrganizationResponse{
|
||||
Details: v2beta_object.DomainToDetailsPb(createdOrg.ObjectDetails),
|
||||
CreatedDate: timestamppb.New(createdOrg.ObjectDetails.EventDate),
|
||||
Id: createdOrg.ObjectDetails.ResourceOwner,
|
||||
CreatedAdmins: admins,
|
||||
}, nil
|
||||
|
@@ -177,14 +177,11 @@ func TestServer_CreateOrganization(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// check details
|
||||
assert.NotZero(t, got.GetDetails().GetSequence())
|
||||
gotCD := got.GetDetails().GetChangeDate().AsTime()
|
||||
gotCD := got.GetCreatedDate().AsTime()
|
||||
now := time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, got.GetDetails().GetResourceOwner())
|
||||
|
||||
// organization id must be the same as the resourceOwner
|
||||
assert.Equal(t, got.GetDetails().GetResourceOwner(), got.GetId())
|
||||
|
||||
// check the admins
|
||||
require.Len(t, got.GetCreatedAdmins(), len(tt.want.GetCreatedAdmins()))
|
||||
@@ -256,11 +253,9 @@ func TestServer_UpdateOrganization(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// check details
|
||||
assert.NotZero(t, got.GetDetails().GetSequence())
|
||||
gotCD := got.GetDetails().GetChangeDate().AsTime()
|
||||
gotCD := got.GetChangeDate().AsTime()
|
||||
now := time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, got.GetDetails().GetResourceOwner())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -596,11 +591,9 @@ func TestServer_DeleteOrganization(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// check details
|
||||
assert.NotZero(t, got.GetDetails().GetSequence())
|
||||
gotCD := got.GetDetails().GetChangeDate().AsTime()
|
||||
gotCD := got.GetChangeDate().AsTime()
|
||||
now := time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, got.GetDetails().GetResourceOwner())
|
||||
|
||||
listOrgRes, err := Client.ListOrganizations(tt.ctx, &v2beta_org.ListOrganizationsRequest{
|
||||
Queries: []*v2beta_org.OrgQuery{
|
||||
@@ -664,11 +657,9 @@ func TestServer_DeactivateReactivateOrganization(t *testing.T) {
|
||||
Id: orgId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.NotZero(t, deactivate_res.GetDetails().GetSequence())
|
||||
gotCD := deactivate_res.GetDetails().GetChangeDate().AsTime()
|
||||
gotCD := deactivate_res.GetChangeDate().AsTime()
|
||||
now := time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, deactivate_res.GetDetails().GetResourceOwner())
|
||||
|
||||
// 4. check organization state is deactivated
|
||||
listOrgRes, err = Client.ListOrganizations(ctx, &v2beta_org.ListOrganizationsRequest{
|
||||
@@ -713,11 +704,9 @@ func TestServer_DeactivateReactivateOrganization(t *testing.T) {
|
||||
Id: orgId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.NotZero(t, reactivate_res.GetDetails().GetSequence())
|
||||
gotCD = reactivate_res.GetDetails().GetChangeDate().AsTime()
|
||||
gotCD = reactivate_res.GetChangeDate().AsTime()
|
||||
now = time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, reactivate_res.GetDetails().GetResourceOwner())
|
||||
|
||||
// 8. check organization state is active
|
||||
listOrgRes, err = Client.ListOrganizations(ctx, &v2beta_org.ListOrganizationsRequest{
|
||||
@@ -774,11 +763,9 @@ func TestServer_AddOListDeleterganizationDomain(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// check details
|
||||
assert.NotZero(t, addOrgDomainRes.GetDetails().GetSequence())
|
||||
gotCD := addOrgDomainRes.GetDetails().GetChangeDate().AsTime()
|
||||
gotCD := addOrgDomainRes.GetCreatedDate().AsTime()
|
||||
now := time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, addOrgDomainRes.GetDetails().GetResourceOwner())
|
||||
|
||||
// 2. check domain is added
|
||||
queryRes, err := Client.ListOrganizationDomains(CTX, &v2beta_org.ListOrganizationDomainsRequest{
|
||||
@@ -802,11 +789,9 @@ func TestServer_AddOListDeleterganizationDomain(t *testing.T) {
|
||||
// require.NoError(t, err)
|
||||
require.Contains(t, err.Error(), "Errors.Already.Exists")
|
||||
// check details
|
||||
// assert.NotZero(t, addOrgDomainRes.GetDetails().GetSequence())
|
||||
// gotCD = addOrgDomainRes.GetDetails().GetChangeDate().AsTime()
|
||||
// now = time.Now()
|
||||
// assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
// assert.NotEmpty(t, addOrgDomainRes.GetDetails().GetResourceOwner())
|
||||
|
||||
// 4. check domain is added
|
||||
queryRes, err = Client.ListOrganizationDomains(CTX, &v2beta_org.ListOrganizationDomainsRequest{
|
||||
@@ -828,11 +813,9 @@ func TestServer_AddOListDeleterganizationDomain(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// check details
|
||||
assert.NotZero(t, deleteOrgDomainRes.GetDetails().GetSequence())
|
||||
gotCD = deleteOrgDomainRes.GetDetails().GetChangeDate().AsTime()
|
||||
gotCD = deleteOrgDomainRes.GetChangeDate().AsTime()
|
||||
now = time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, deleteOrgDomainRes.GetDetails().GetResourceOwner())
|
||||
|
||||
// 6. check organization domain deleted
|
||||
queryRes, err = Client.ListOrganizationDomains(CTX, &v2beta_org.ListOrganizationDomainsRequest{
|
||||
@@ -856,11 +839,9 @@ func TestServer_AddOListDeleterganizationDomain(t *testing.T) {
|
||||
// require.NoError(t, err)
|
||||
require.Contains(t, err.Error(), "Domain doesn't exist on organization")
|
||||
// check details
|
||||
// assert.NotZero(t, deleteOrgDomainRes.GetDetails().GetSequence())
|
||||
// gotCD = deleteOrgDomainRes.GetDetails().GetChangeDate().AsTime()
|
||||
// now = time.Now()
|
||||
// assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
// assert.NotEmpty(t, deleteOrgDomainRes.GetDetails().GetResourceOwner())
|
||||
|
||||
// 8. check organization domain deleted
|
||||
queryRes, err = Client.ListOrganizationDomains(CTX, &v2beta_org.ListOrganizationDomainsRequest{
|
||||
@@ -1060,11 +1041,9 @@ func TestServer_SetOrganizationMetadata(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// check details
|
||||
assert.NotZero(t, got.GetDetails().GetSequence())
|
||||
gotCD := got.GetDetails().GetChangeDate().AsTime()
|
||||
gotCD := got.GetChangeDate().AsTime()
|
||||
now := time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, got.GetDetails().GetResourceOwner())
|
||||
|
||||
// check metadata
|
||||
listMetadataRes, err := Client.ListOrganizationMetadata(tt.ctx, &v2beta_org.ListOrganizationMetadataRequest{
|
||||
|
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
org "github.com/zitadel/zitadel/pkg/grpc/org/v2beta"
|
||||
v2beta_org "github.com/zitadel/zitadel/pkg/grpc/org/v2beta"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
func (s *Server) CreateOrganization(ctx context.Context, request *v2beta_org.CreateOrganizationRequest) (*v2beta_org.CreateOrganizationResponse, error) {
|
||||
@@ -32,7 +33,7 @@ func (s *Server) UpdateOrganization(ctx context.Context, request *v2beta_org.Upd
|
||||
}
|
||||
|
||||
return &v2beta_org.UpdateOrganizationResponse{
|
||||
Details: object.DomainToDetailsPb(org),
|
||||
ChangeDate: timestamppb.New(org.EventDate),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ func (s *Server) DeleteOrganization(ctx context.Context, request *v2beta_org.Del
|
||||
return nil, err
|
||||
}
|
||||
return &v2beta_org.DeleteOrganizationResponse{
|
||||
Details: object.DomainToDetailsPb(details),
|
||||
ChangeDate: timestamppb.New(details.EventDate),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ func (s *Server) SetOrganizationMetadata(ctx context.Context, request *v2beta_or
|
||||
return nil, err
|
||||
}
|
||||
return &org.SetOrganizationMetadataResponse{
|
||||
Details: object.DomainToDetailsPb(result),
|
||||
ChangeDate: timestamppb.New(result.EventDate),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ func (s *Server) DeleteOrganizationMetadata(ctx context.Context, request *v2beta
|
||||
return nil, err
|
||||
}
|
||||
return &v2beta_org.DeleteOrganizationMetadataResponse{
|
||||
Details: object.DomainToChangeDetailsPb(result),
|
||||
ChangeDate: timestamppb.New(result.EventDate),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ func (s *Server) DeactivateOrganization(ctx context.Context, request *org.Deacti
|
||||
return nil, err
|
||||
}
|
||||
return &org.DeactivateOrganizationResponse{
|
||||
Details: object.DomainToDetailsPb(objectDetails),
|
||||
ChangeDate: timestamppb.New(objectDetails.EventDate),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -112,7 +113,7 @@ func (s *Server) ReactivateOrganization(ctx context.Context, request *org.Reacti
|
||||
return nil, err
|
||||
}
|
||||
return &org.ReactivateOrganizationResponse{
|
||||
Details: object.DomainToDetailsPb(objectDetails),
|
||||
ChangeDate: timestamppb.New(objectDetails.EventDate),
|
||||
}, err
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ func (s *Server) AddOrganizationDomain(ctx context.Context, request *org.AddOrga
|
||||
return nil, err
|
||||
}
|
||||
return &org.AddOrganizationDomainResponse{
|
||||
Details: object.DomainToDetailsPb(details),
|
||||
CreatedDate: timestamppb.New(details.EventDate),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -157,7 +158,7 @@ func (s *Server) DeleteOrganizationDomain(ctx context.Context, req *org.DeleteOr
|
||||
return nil, err
|
||||
}
|
||||
return &org.DeleteOrganizationDomainResponse{
|
||||
Details: object.DomainToDetailsPb(details),
|
||||
ChangeDate: timestamppb.New(details.EventDate),
|
||||
}, err
|
||||
}
|
||||
|
||||
@@ -182,7 +183,7 @@ func (s *Server) VerifyOrganizationDomain(ctx context.Context, request *org.Veri
|
||||
return nil, err
|
||||
}
|
||||
return &org.VerifyOrganizationDomainResponse{
|
||||
Details: object.DomainToChangeDetailsPb(details),
|
||||
ChangeDate: timestamppb.New(details.EventDate),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@@ -286,7 +286,6 @@ func TestReplaceUser(t *testing.T) {
|
||||
}, retryDuration, tick)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestReplaceUser_removeOldMetadata(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user