diff options
Diffstat (limited to 'spec/requests/api/graphql/user_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/user_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/user_spec.rb b/spec/requests/api/graphql/user_spec.rb index 41ee233dfc5..22ebc1be964 100644 --- a/spec/requests/api/graphql/user_spec.rb +++ b/spec/requests/api/graphql/user_spec.rb @@ -113,4 +113,36 @@ RSpec.describe 'User', feature_category: :user_profile do end end end + + describe 'organizations field' do + let_it_be(:organization_user) { create(:organization_user, user: current_user) } + let_it_be(:organization) { organization_user.organization } + let_it_be(:another_organization) { create(:organization) } + let_it_be(:another_user) { create(:user) } + + let(:query) do + graphql_query_for( + :user, + { username: current_user.username.to_s.upcase }, + 'organizations { nodes { path } }' + ) + end + + context 'with permission' do + it 'returns the relevant organization details' do + post_graphql(query, current_user: current_user) + + expect(graphql_data.dig('user', 'organizations', 'nodes').pluck('path')) + .to match_array(organization.path) + end + end + + context 'without permission' do + it 'does not return organization details' do + post_graphql(query, current_user: another_user) + + expect(graphql_data.dig('user', 'organizations', 'nodes')).to be_nil + end + end + end end |