summaryrefslogtreecommitdiff
path: root/spec/requests/projects/metrics/dashboards/builder_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/projects/metrics/dashboards/builder_spec.rb')
-rw-r--r--spec/requests/projects/metrics/dashboards/builder_spec.rb67
1 files changed, 62 insertions, 5 deletions
diff --git a/spec/requests/projects/metrics/dashboards/builder_spec.rb b/spec/requests/projects/metrics/dashboards/builder_spec.rb
index b56a5def211..5f85788cdb6 100644
--- a/spec/requests/projects/metrics/dashboards/builder_spec.rb
+++ b/spec/requests/projects/metrics/dashboards/builder_spec.rb
@@ -6,6 +6,42 @@ 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)
@@ -17,14 +53,14 @@ RSpec.describe 'Projects::Metrics::Dashboards::BuilderController' do
stub_feature_flags(metrics_dashboard_new_panel_page: true)
end
- it 'redirects to sign in' 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 reporter access' do
+ context 'as user with guest access' do
before do
stub_feature_flags(metrics_dashboard_new_panel_page: true)
project.add_guest(user)
@@ -49,10 +85,31 @@ RSpec.describe 'Projects::Metrics::Dashboards::BuilderController' do
stub_feature_flags(metrics_dashboard_new_panel_page: true)
end
- it 'returns success' do
- send_request
+ 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(:ok)
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ expect(json_response['message']).to eq('Invalid configuration format')
+ end
end
end