diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-10 00:08:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-10 00:08:21 +0300 |
commit | 64786982930713d095ccd3aebd812182a1879fed (patch) | |
tree | 542e79df02f79049d8a63b31388c7d1e3e3b9166 /spec/requests | |
parent | 3d0474695407d24d49bb94f29a182739ee35e1f8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/graphql/project/alert_management/alert/assignees_spec.rb | 85 | ||||
-rw-r--r-- | spec/requests/api/graphql/project/alert_management/alerts_spec.rb | 15 |
2 files changed, 14 insertions, 86 deletions
diff --git a/spec/requests/api/graphql/project/alert_management/alert/assignees_spec.rb b/spec/requests/api/graphql/project/alert_management/alert/assignees_spec.rb deleted file mode 100644 index 86b56e42a24..00000000000 --- a/spec/requests/api/graphql/project/alert_management/alert/assignees_spec.rb +++ /dev/null @@ -1,85 +0,0 @@ -# frozen_string_literal: true -require 'spec_helper' - -describe 'getting Alert Management Alert Assignees' do - include GraphqlHelpers - - let_it_be(:project) { create(:project) } - let_it_be(:current_user) { create(:user) } - let_it_be(:first_alert) { create(:alert_management_alert, project: project, assignees: [current_user]) } - let_it_be(:second_alert) { create(:alert_management_alert, project: project) } - - let(:params) { {} } - - let(:fields) do - <<~QUERY - nodes { - #{all_graphql_fields_for('AlertManagementAlert')} - } - QUERY - end - - let(:query) do - graphql_query_for( - 'project', - { 'fullPath' => project.full_path }, - query_graphql_field('alertManagementAlerts', params, fields) - ) - end - - let(:alerts) { graphql_data.dig('project', 'alertManagementAlerts', 'nodes') } - let(:assignees) { alerts.map { |alert| [alert['iid'], alert['assignees']['nodes']] }.to_h } - let(:first_assignees) { assignees[first_alert.iid.to_s] } - let(:second_assignees) { assignees[second_alert.iid.to_s] } - - before do - project.add_developer(current_user) - end - - it 'returns the correct assignees' do - post_graphql(query, current_user: current_user) - - expect(first_assignees.length).to eq(1) - expect(first_assignees.first).to include('username' => current_user.username) - expect(second_assignees).to be_empty - end - - it 'applies appropriate filters for non-visible users' do - allow(Ability).to receive(:allowed?).and_call_original - allow(Ability).to receive(:allowed?).with(current_user, :read_user, current_user).and_return(false) - - post_graphql(query, current_user: current_user) - - expect(first_assignees).to be_empty - expect(second_assignees).to be_empty - end - - it 'avoids N+1 queries' do - base_count = ActiveRecord::QueryRecorder.new do - post_graphql(query, current_user: current_user) - end - - # An N+1 would mean a new alert would increase the query count - third_alert = create(:alert_management_alert, project: project, assignees: [current_user]) - - expect { post_graphql(query, current_user: current_user) }.not_to exceed_query_limit(base_count) - - third_assignees = assignees[third_alert.iid.to_s] - - expect(third_assignees.length).to eq(1) - expect(third_assignees.first).to include('username' => current_user.username) - end - - context 'with alert_assignee flag disabled' do - before do - stub_feature_flags(alert_assignee: false) - end - - it 'excludes assignees' do - post_graphql(query, current_user: current_user) - - expect(first_assignees).to be_empty - expect(second_assignees).to be_empty - end - end -end diff --git a/spec/requests/api/graphql/project/alert_management/alerts_spec.rb b/spec/requests/api/graphql/project/alert_management/alerts_spec.rb index 05c1eb732ef..ae819f93ee7 100644 --- a/spec/requests/api/graphql/project/alert_management/alerts_spec.rb +++ b/spec/requests/api/graphql/project/alert_management/alerts_spec.rb @@ -75,7 +75,7 @@ describe 'getting Alert Management Alerts' do 'updatedAt' => triggered_alert.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ') ) - expect(first_alert['assignees']['nodes'].first).to include('username' => triggered_alert.assignees.first.username) + expect(first_alert['assignees'].first).to include('username' => triggered_alert.assignees.first.username) expect(second_alert).to include( 'iid' => resolved_alert.iid.to_s, @@ -137,5 +137,18 @@ describe 'getting Alert Management Alerts' do end end end + + context 'with alert_assignee flag disabled' do + before do + stub_feature_flags(alert_assignee: false) + project.add_developer(current_user) + + post_graphql(query, current_user: current_user) + end + + it 'excludes assignees' do + expect(alerts.first['assignees']).to be_empty + end + end end end |