diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/requests/projects | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/requests/projects')
3 files changed, 144 insertions, 2 deletions
diff --git a/spec/requests/projects/incident_management/pagerduty_incidents_spec.rb b/spec/requests/projects/incident_management/pagerduty_incidents_spec.rb index c246aacb4c7..b18bffdb110 100644 --- a/spec/requests/projects/incident_management/pagerduty_incidents_spec.rb +++ b/spec/requests/projects/incident_management/pagerduty_incidents_spec.rb @@ -12,7 +12,7 @@ RSpec.describe 'PagerDuty webhook' do def make_request headers = { 'Content-Type' => 'application/json' } - post project_incidents_pagerduty_url(project, token: 'VALID-TOKEN'), params: payload.to_json, headers: headers + post project_incidents_integrations_pagerduty_url(project, token: 'VALID-TOKEN'), params: payload.to_json, headers: headers end before do diff --git a/spec/requests/projects/metrics/dashboards/builder_spec.rb b/spec/requests/projects/metrics/dashboards/builder_spec.rb new file mode 100644 index 00000000000..e59ed591f63 --- /dev/null +++ b/spec/requests/projects/metrics/dashboards/builder_spec.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Projects::Metrics::Dashboards::BuilderController' do + let_it_be(:project) { create(:project) } + let_it_be(:environment) { create(:environment, project: project) } + let_it_be(:user) { create(:user) } + let_it_be(:valid_panel_yml) do + <<~YML + --- + title: "Super Chart A1" + type: "area-chart" + y_label: "y_label" + weight: 1 + max_value: 1 + metrics: + - id: metric_a1 + query_range: |+ + avg( + sum( + container_memory_usage_bytes{ + container_name!="POD", + pod_name=~"^{{ci_environment_slug}}-(.*)", + namespace="{{kube_namespace}}", + user_def_variable="{{user_def_variable}}" + } + ) by (job) + ) without (job) + /1024/1024/1024 + unit: unit + label: Legend Label + YML + end + let_it_be(:invalid_panel_yml) do + <<~YML + --- + title: "Super Chart A1" + type: "area-chart" + y_label: "y_label" + weight: 1 + max_value: 1 + YML + end + + def send_request(params = {}) + post namespace_project_metrics_dashboards_builder_path(namespace_id: project.namespace, project_id: project, format: :json, **params) + end + + describe 'POST /:namespace/:project/-/metrics/dashboards/builder' do + context 'as anonymous user' do + it 'redirects user to sign in page' do + send_request + + expect(response).to redirect_to(new_user_session_path) + end + end + + context 'as user with guest access' do + before do + project.add_guest(user) + login_as(user) + end + + it 'returns not found' do + send_request + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'as logged in user' do + before do + project.add_developer(user) + login_as(user) + end + + context 'valid yaml panel is supplied' do + it 'returns success' do + send_request(panel_yaml: valid_panel_yml) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to include('title' => 'Super Chart A1', 'type' => 'area-chart') + end + end + + context 'invalid yaml panel is supplied' do + it 'returns unprocessable entity' do + send_request(panel_yaml: invalid_panel_yml) + + expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(json_response['message']).to eq('Each "panel" must define an array :metrics') + end + end + + context 'invalid panel_yaml is not a yaml string' do + it 'returns unprocessable entity' do + send_request(panel_yaml: 1) + + expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(json_response['message']).to eq('Invalid configuration format') + end + end + end + end +end diff --git a/spec/requests/projects/metrics_dashboard_spec.rb b/spec/requests/projects/metrics_dashboard_spec.rb index ab35788387c..f571e4a4309 100644 --- a/spec/requests/projects/metrics_dashboard_spec.rb +++ b/spec/requests/projects/metrics_dashboard_spec.rb @@ -23,6 +23,22 @@ RSpec.describe 'metrics dashboard page' do send_request expect(assigns(:environment).id).to eq(environment.id) end + + context 'with anonymous user and public dashboard visibility' do + let(:anonymous_user) { create(:user) } + let(:project) do + create(:project, :public, metrics_dashboard_access_level: 'enabled') + end + + before do + login_as(anonymous_user) + end + + it 'returns 200' do + send_request + expect(response).to have_gitlab_http_status(:ok) + end + end end describe 'GET /:namespace/:project/-/metrics?environment=:environment.id' do @@ -79,7 +95,27 @@ RSpec.describe 'metrics dashboard page' do end end + describe 'GET :/namespace/:project/-/metrics/:page' do + it 'returns 200 with path param page' do + # send_request(page: 'panel/new') cannot be used because it encodes '/' + get "#{dashboard_route}/panel/new" + + expect(response).to have_gitlab_http_status(:ok) + end + + it 'returns 200 with dashboard and path param page' do + # send_request(page: 'panel/new') cannot be used because it encodes '/' + get "#{dashboard_route(dashboard_path: 'dashboard.yml')}/panel/new" + + expect(response).to have_gitlab_http_status(:ok) + end + end + def send_request(params = {}) - get namespace_project_metrics_dashboard_path(namespace_id: project.namespace, project_id: project, **params) + get dashboard_route(params) + end + + def dashboard_route(params = {}) + namespace_project_metrics_dashboard_path(namespace_id: project.namespace, project_id: project, **params) end end |