mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-19 14:12:52 +00:00
# Which Problems Are Solved To be able to update metadata via the `UpdateUser` endpoint. # How the Problems Are Solved This is achieved by: * adding the `Metadata` field to `UpdateUserRequest` * update the server layer to convert/set metadata fields to domain layer metadata * update the command layer to handle metadata updates # Additional Changes N/A # Additional Context - Related to https://github.com/zitadel/zitadel/issues/11369, https://github.com/zitadel/zitadel/issues/11759 - Follow-up for PR https://github.com/zitadel/zitadel/pull/11719 --------- Co-authored-by: Copilot <[email protected]>
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package user
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
"github.com/muhlemmer/gu"
|
|
"golang.org/x/text/language"
|
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
|
)
|
|
|
|
func Test_patchMachineUserToCommand(t *testing.T) {
|
|
type args struct {
|
|
userId string
|
|
userName *string
|
|
machine *user.UpdateUserRequest_Machine
|
|
metadata []*user.Metadata
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *command.ChangeMachine
|
|
}{{
|
|
name: "single property",
|
|
args: args{
|
|
userId: "userId",
|
|
machine: &user.UpdateUserRequest_Machine{
|
|
Name: gu.Ptr("name"),
|
|
},
|
|
},
|
|
want: &command.ChangeMachine{
|
|
ID: "userId",
|
|
Name: gu.Ptr("name"),
|
|
},
|
|
}, {
|
|
name: "all properties",
|
|
args: args{
|
|
userId: "userId",
|
|
userName: gu.Ptr("userName"),
|
|
machine: &user.UpdateUserRequest_Machine{
|
|
Name: gu.Ptr("name"),
|
|
Description: gu.Ptr("description"),
|
|
AccessTokenType: gu.Ptr(user.AccessTokenType_ACCESS_TOKEN_TYPE_JWT),
|
|
},
|
|
metadata: []*user.Metadata{
|
|
{
|
|
Key: "key1",
|
|
Value: []byte("value1"),
|
|
},
|
|
{
|
|
Key: "key2",
|
|
Value: []byte("value2"),
|
|
},
|
|
},
|
|
},
|
|
want: &command.ChangeMachine{
|
|
ID: "userId",
|
|
Username: gu.Ptr("userName"),
|
|
Name: gu.Ptr("name"),
|
|
Description: gu.Ptr("description"),
|
|
AccessTokenType: gu.Ptr(domain.OIDCTokenTypeJWT),
|
|
Metadata: []*domain.Metadata{
|
|
{
|
|
Key: "key1",
|
|
Value: []byte("value1"),
|
|
},
|
|
{
|
|
Key: "key2",
|
|
Value: []byte("value2"),
|
|
},
|
|
},
|
|
},
|
|
}}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := updateMachineUserToCommand(tt.args.userId, tt.args.userName, tt.args.machine, tt.args.metadata)
|
|
if diff := cmp.Diff(tt.want, got, cmpopts.EquateComparable(language.Tag{})); diff != "" {
|
|
t.Errorf("patchMachineUserToCommand() mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|