Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-14 15:08:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-14 15:08:21 +0300
commit674e7e2c3d295704bdf504dd0caa2e5a2d9b5cd2 (patch)
tree7454890d4f7aa8644c9e89954a978466e4416815 /spec/requests
parentc7ad2610df033b370845995ac3bbe269a191d9bb (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/graphql/mutations/alert_management/alerts/update_alert_status_spec.rb42
-rw-r--r--spec/requests/api/metrics/user_starred_dashboards_spec.rb94
2 files changed, 125 insertions, 11 deletions
diff --git a/spec/requests/api/graphql/mutations/alert_management/alerts/update_alert_status_spec.rb b/spec/requests/api/graphql/mutations/alert_management/alerts/update_alert_status_spec.rb
new file mode 100644
index 00000000000..fe50468134c
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/alert_management/alerts/update_alert_status_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Setting the status of an alert' do
+ include GraphqlHelpers
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let(:alert) { create(:alert_management_alert, project: project) }
+ let(:input) { { status: 'ACKNOWLEDGED' } }
+
+ let(:mutation) do
+ variables = {
+ project_path: project.full_path,
+ iid: alert.iid.to_s
+ }
+ graphql_mutation(:update_alert_status, variables.merge(input),
+ <<~QL
+ clientMutationId
+ errors
+ alert {
+ iid
+ status
+ }
+ QL
+ )
+ end
+
+ let(:mutation_response) { graphql_mutation_response(:update_alert_status) }
+
+ before do
+ project.add_developer(user)
+ end
+
+ it 'updates the status of the alert' do
+ post_graphql_mutation(mutation, current_user: user)
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(mutation_response['alert']['status']).to eq(input[:status])
+ end
+end
diff --git a/spec/requests/api/metrics/user_starred_dashboards_spec.rb b/spec/requests/api/metrics/user_starred_dashboards_spec.rb
index 4b3c6407ef7..8f9394a0e20 100644
--- a/spec/requests/api/metrics/user_starred_dashboards_spec.rb
+++ b/spec/requests/api/metrics/user_starred_dashboards_spec.rb
@@ -4,20 +4,17 @@ require 'spec_helper'
describe API::Metrics::UserStarredDashboards do
let_it_be(:user) { create(:user) }
- let!(:project) { create(:project, :private, :repository, :custom_repo, namespace: user.namespace, files: { dashboard => dashboard_yml }) }
- let(:dashboard_yml) { fixture_file('lib/gitlab/metrics/dashboard/sample_dashboard.yml') }
- let(:dashboard) { '.gitlab/dashboards/find&seek.yml' }
+ let_it_be(:dashboard_yml) { fixture_file('lib/gitlab/metrics/dashboard/sample_dashboard.yml') }
+ let_it_be(:dashboard) { '.gitlab/dashboards/find&seek.yml' }
+ let_it_be(:project) { create(:project, :private, :repository, :custom_repo, namespace: user.namespace, files: { dashboard => dashboard_yml }) }
+ let(:url) { "/projects/#{project.id}/metrics/user_starred_dashboards" }
let(:params) do
{
- user: user,
- project: project,
dashboard_path: CGI.escape(dashboard)
}
end
describe 'POST /projects/:id/metrics/user_starred_dashboards' do
- let(:url) { "/projects/#{project.id}/metrics/user_starred_dashboards" }
-
before do
project.add_reporter(user)
end
@@ -25,7 +22,7 @@ describe API::Metrics::UserStarredDashboards do
context 'with correct permissions' do
context 'with valid parameters' do
context 'dashboard_path as url param url escaped' do
- it 'creates a new annotation', :aggregate_failures do
+ it 'creates a new user starred metrics dashboard', :aggregate_failures do
post api(url, user), params: params
expect(response).to have_gitlab_http_status(:created)
@@ -38,13 +35,11 @@ describe API::Metrics::UserStarredDashboards do
context 'dashboard_path in request body unescaped' do
let(:params) do
{
- user: user,
- project: project,
dashboard_path: dashboard
}
end
- it 'creates a new annotation', :aggregate_failures do
+ it 'creates a new user starred metrics dashboard', :aggregate_failures do
post api(url, user), params: params
expect(response).to have_gitlab_http_status(:created)
@@ -89,4 +84,81 @@ describe API::Metrics::UserStarredDashboards do
end
end
end
+
+ describe 'DELETE /projects/:id/metrics/user_starred_dashboards' do
+ let_it_be(:user_starred_dashboard_1) { create(:metrics_users_starred_dashboard, user: user, project: project, dashboard_path: dashboard) }
+ let_it_be(:user_starred_dashboard_2) { create(:metrics_users_starred_dashboard, user: user, project: project) }
+ let_it_be(:other_user_starred_dashboard) { create(:metrics_users_starred_dashboard, project: project) }
+ let_it_be(:other_project_starred_dashboard) { create(:metrics_users_starred_dashboard, user: user) }
+
+ before do
+ project.add_reporter(user)
+ end
+
+ context 'with correct permissions' do
+ context 'with valid parameters' do
+ context 'dashboard_path as url param url escaped' do
+ it 'deletes given user starred metrics dashboard', :aggregate_failures do
+ delete api(url, user), params: params
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['deleted_rows']).to eq(1)
+ expect(::Metrics::UsersStarredDashboard.all.pluck(:dashboard_path)).not_to include(dashboard)
+ end
+ end
+
+ context 'dashboard_path in request body unescaped' do
+ let(:params) do
+ {
+ dashboard_path: dashboard
+ }
+ end
+
+ it 'deletes given user starred metrics dashboard', :aggregate_failures do
+ delete api(url, user), params: params
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['deleted_rows']).to eq(1)
+ expect(::Metrics::UsersStarredDashboard.all.pluck(:dashboard_path)).not_to include(dashboard)
+ end
+ end
+
+ context 'dashboard_path has not been specified' do
+ it 'deletes all starred dashboards for that user within given project', :aggregate_failures do
+ delete api(url, user), params: {}
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['deleted_rows']).to eq(2)
+ expect(::Metrics::UsersStarredDashboard.all).to contain_exactly(other_user_starred_dashboard, other_project_starred_dashboard)
+ end
+ end
+ end
+
+ context 'with invalid parameters' do
+ context 'user is missing' do
+ it 'returns 404 not found' do
+ post api(url, nil), params: params
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'project is missing' do
+ it 'returns 404 not found' do
+ post api("/projects/#{project.id + 1}/user_starred_dashboards", user), params: params
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+ end
+
+ context 'without correct permissions' do
+ it 'returns 404 not found' do
+ post api(url, create(:user)), params: params
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
end