fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! adding more tests for ListOrganization()

This commit is contained in:
Iraq Jaber
2025-05-07 09:02:56 +02:00
parent d5602e59a1
commit 4eb67cebcc
5 changed files with 35 additions and 45 deletions

View File

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

View File

@@ -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{

View File

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

View File

@@ -286,7 +286,6 @@ func TestReplaceUser(t *testing.T) {
}, retryDuration, tick)
})
}
}
func TestReplaceUser_removeOldMetadata(t *testing.T) {

View File

@@ -20,7 +20,7 @@ option go_package = "github.com/zitadel/zitadel/pkg/grpc/org/v2beta;org";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {
title: "Organization Service (Beta)";
title: "Organization Service";
version: "2.0-beta";
description: "This API is intended to manage organizations in a ZITADEL instance. This project is in beta state. It can AND will continue breaking until the services provide the same functionality as the current login.";
contact:{
@@ -106,7 +106,7 @@ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
}
};
service OrganizationServiceV2beta {
service OrganizationService {
// Create Organization
//
@@ -432,7 +432,13 @@ message CreateOrganizationResponse{
optional string email_code = 2;
optional string phone_code = 3;
}
zitadel.object.v2beta.Details details = 1;
// The timestamp of the organization was created.
google.protobuf.Timestamp created_date = 1 [
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
example: "\"2024-12-18T07:50:47.492Z\"";
}
];
// Organization ID of the newly created organization.
string id = 2 [
(validate.rules).string = {min_len: 1, max_len: 200},
(google.api.field_behavior) = REQUIRED,
@@ -440,7 +446,6 @@ message CreateOrganizationResponse{
min_length: 1;
max_length: 200;
example: "\"69629012906488334\"";
description: "Organization ID of the newly created organization."
}
];
repeated CreatedAdmin created_admins = 3;
@@ -589,7 +594,12 @@ message AddOrganizationDomainRequest {
}
message AddOrganizationDomainResponse {
zitadel.object.v2beta.Details details = 1;
// The timestamp of the organization was created.
google.protobuf.Timestamp created_date = 1 [
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
example: "\"2024-12-18T07:50:47.492Z\"";
}
];
}
message ListOrganizationDomainsRequest {