diff --git a/descope/internal/mgmt/user_test.go b/descope/internal/mgmt/user_test.go index 825366f4..4a7e1f26 100644 --- a/descope/internal/mgmt/user_test.go +++ b/descope/internal/mgmt/user_test.go @@ -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{{ diff --git a/descope/types.go b/descope/types.go index 6d3a7252..c8228e0d 100644 --- a/descope/types.go +++ b/descope/types.go @@ -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"` @@ -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.