Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions descope/internal/mgmt/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,44 @@ func TestUserLoadSuccess(t *testing.T) {
require.Equal(t, "a@b.c", res.Email)
}

func TestUserLoadParsesRoleIds(t *testing.T) {
response := map[string]any{
"user": map[string]any{
"email": "a@b.c",
"roleIds": []string{"gid1"},
"userTenants": []map[string]any{
{"tenantId": "t1", "roleNames": []string{"role1"}, "roleIds": []string{"rid1"}},
},
}}
m := newTestMgmt(nil, helpers.DoOkWithBody(func(_ *http.Request) {}, response))
res, err := m.User().Load(context.Background(), "abc")
require.NoError(t, err)
require.NotNil(t, res)
require.EqualValues(t, []string{"gid1"}, res.RoleIDs)
require.Len(t, res.UserTenants, 1)
require.EqualValues(t, []string{"rid1"}, res.UserTenants[0].RoleIDs)
}

func TestSearchAllUsersParsesRoleIds(t *testing.T) {
response := map[string]any{
"users": []map[string]any{{
"email": "a@b.c",
"roleIds": []string{"gid1"},
"userTenants": []map[string]any{
{"tenantId": "t1", "roleNames": []string{"role1"}, "roleIds": []string{"rid1"}},
},
}},
"total": 1,
}
m := newTestMgmt(nil, helpers.DoOkWithBody(func(_ *http.Request) {}, response))
res, _, err := m.User().SearchAll(context.Background(), &descope.UserSearchOptions{})
require.NoError(t, err)
require.Len(t, res, 1)
require.EqualValues(t, []string{"gid1"}, res[0].RoleIDs)
require.Len(t, res[0].UserTenants, 1)
require.EqualValues(t, []string{"rid1"}, res[0].UserTenants[0].RoleIDs)
}

func TestUsersLoad(t *testing.T) {
response := map[string]any{
"users": []map[string]any{{
Expand Down
2 changes: 2 additions & 0 deletions descope/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ type UserResponse struct {
VerifiedEmail bool `json:"verifiedEmail,omitempty"`
VerifiedPhone bool `json:"verifiedPhone,omitempty"`
RoleNames []string `json:"roleNames,omitempty"`
RoleIDs []string `json:"roleIds,omitempty"`
UserTenants []*UserResponseAssociatedTenant `json:"userTenants,omitempty"`
Status string `json:"status,omitempty"`
Picture string `json:"picture,omitempty"`
Expand Down Expand Up @@ -741,6 +742,7 @@ type AssociatedTenant struct {
type UserResponseAssociatedTenant struct {
AssociatedTenant `json:",inline"`
Permissions []string `json:"permissions,omitempty"`
RoleIDs []string `json:"roleIds,omitempty"`
}

// Represents a mapping between a set of groups of users and a role that will be assigned to them.
Expand Down
Loading