1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Query', feature_category: :groups_and_projects do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:other_user) { create(:user) }
let_it_be(:group_namespace) { create(:group, :private) }
let_it_be(:public_group_namespace) { create(:group, :public) }
let_it_be(:user_namespace) { create(:user_namespace, owner: user) }
let_it_be(:project) { create(:project, group: group_namespace) }
describe '.namespace' do
subject { post_graphql(query, current_user: current_user) }
let(:current_user) { user }
let(:query) { graphql_query_for(:namespace, { 'fullPath' => target_namespace.full_path }, all_graphql_fields_for('Namespace')) }
let(:query_result) { graphql_data['namespace'] }
shared_examples 'retrieving a namespace' do
context 'authorised query' do
before do
subject
end
it_behaves_like 'a working graphql query'
it 'fetches the expected data' do
expect(query_result).to include(
'fullPath' => target_namespace.full_path,
'name' => target_namespace.name,
'crossProjectPipelineAvailable' => target_namespace.licensed_feature_available?(:cross_project_pipeline),
'achievementsPath' => achievements_path
)
end
end
context 'unauthorised query' do
before do
subject
end
context 'anonymous user' do
let(:current_user) { nil }
it 'does not retrieve the record' do
expect(query_result).to be_nil
end
end
context 'the current user does not have permission' do
let(:current_user) { other_user }
it 'does not retrieve the record' do
expect(query_result).to be_nil
end
end
end
end
context 'when achievements feature flag is off' do
let(:target_namespace) { public_group_namespace }
before do
stub_feature_flags(achievements: false)
end
it 'does not return achievementsPath' do
subject
expect(query_result).to include(
'achievementsPath' => nil
)
end
end
context 'when used with a public group' do
let(:target_namespace) { public_group_namespace }
let(:achievements_path) { ::Gitlab::Routing.url_helpers.group_achievements_path(target_namespace) }
before do
subject
end
it_behaves_like 'a working graphql query'
context 'when user is a member' do
before do
public_group_namespace.add_developer(user)
end
it 'fetches the expected data' do
expect(query_result).to include(
'fullPath' => target_namespace.full_path,
'name' => target_namespace.name,
'achievementsPath' => achievements_path
)
end
end
context 'when user is anonymous' do
let(:current_user) { nil }
it 'fetches the expected data' do
expect(query_result).to include(
'fullPath' => target_namespace.full_path,
'name' => target_namespace.name,
'achievementsPath' => achievements_path
)
end
end
context 'when user is not a member' do
let(:current_user) { other_user }
it 'fetches the expected data' do
expect(query_result).to include(
'fullPath' => target_namespace.full_path,
'name' => target_namespace.name,
'achievementsPath' => achievements_path
)
end
end
end
context 'when used with a private namespace' do
context 'retrieving a group' do
it_behaves_like 'retrieving a namespace' do
let(:target_namespace) { group_namespace }
let(:achievements_path) { ::Gitlab::Routing.url_helpers.group_achievements_path(target_namespace) }
before do
group_namespace.add_developer(user)
end
end
end
context 'retrieving a user namespace' do
it_behaves_like 'retrieving a namespace' do
let(:target_namespace) { user_namespace }
let(:achievements_path) { nil }
end
end
context 'retrieving a project' do
it_behaves_like 'retrieving a namespace' do
let(:target_namespace) { project }
let(:achievements_path) { nil }
before do
group_namespace.add_developer(user)
end
end
end
end
end
end
|