diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-12 15:09:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-12 15:09:47 +0300 |
commit | ef7cfec30c9fab7b9e757877c472ca7ca2eccc2d (patch) | |
tree | f69647e6f64c16fad044d564db65cb51c7a0b63f /spec/requests | |
parent | 0e1a6f6a2b28464e6ad151da4dced6d603bd11b0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/graphql/metrics/dashboard/annotations_spec.rb | 72 | ||||
-rw-r--r-- | spec/requests/api/metrics/dashboard/annotations_spec.rb | 90 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 2 |
3 files changed, 61 insertions, 103 deletions
diff --git a/spec/requests/api/graphql/metrics/dashboard/annotations_spec.rb b/spec/requests/api/graphql/metrics/dashboard/annotations_spec.rb index ceeaa12a2bf..cb35411b7a5 100644 --- a/spec/requests/api/graphql/metrics/dashboard/annotations_spec.rb +++ b/spec/requests/api/graphql/metrics/dashboard/annotations_spec.rb @@ -21,6 +21,7 @@ describe 'Getting Metrics Dashboard Annotations' do create(:metrics_dashboard_annotation, environment: environment, starting_at: to.advance(minutes: 5), dashboard_path: path) end + let(:args) { "from: \"#{from}\", to: \"#{to}\"" } let(:fields) do <<~QUERY #{all_graphql_fields_for('MetricsDashboardAnnotation'.classify)} @@ -47,63 +48,40 @@ describe 'Getting Metrics Dashboard Annotations' do ) end - context 'feature flag metrics_dashboard_annotations' do - let(:args) { "from: \"#{from}\", to: \"#{to}\"" } + before do + project.add_developer(current_user) + post_graphql(query, current_user: current_user) + end - before do - project.add_developer(current_user) - end + it_behaves_like 'a working graphql query' - context 'is off' do - before do - stub_feature_flags(metrics_dashboard_annotations: false) - post_graphql(query, current_user: current_user) - end + it 'returns annotations' do + annotations = graphql_data.dig('project', 'environments', 'nodes')[0].dig('metricsDashboard', 'annotations', 'nodes') - it 'returns empty nodes array' do - annotations = graphql_data.dig('project', 'environments', 'nodes')[0].dig('metricsDashboard', 'annotations', 'nodes') + expect(annotations).to match_array [{ + "description" => annotation.description, + "id" => annotation.to_global_id.to_s, + "panelId" => annotation.panel_xid, + "startingAt" => annotation.starting_at.iso8601, + "endingAt" => nil + }] + end - expect(annotations).to be_empty - end - end + context 'arguments' do + context 'from is missing' do + let(:args) { "to: \"#{from}\"" } - context 'is on' do - before do - stub_feature_flags(metrics_dashboard_annotations: true) + it 'returns error' do post_graphql(query, current_user: current_user) - end - it_behaves_like 'a working graphql query' - - it 'returns annotations' do - annotations = graphql_data.dig('project', 'environments', 'nodes')[0].dig('metricsDashboard', 'annotations', 'nodes') - - expect(annotations).to match_array [{ - "description" => annotation.description, - "id" => annotation.to_global_id.to_s, - "panelId" => annotation.panel_xid, - "startingAt" => annotation.starting_at.iso8601, - "endingAt" => nil - }] + expect(graphql_errors[0]).to include("message" => "Field 'annotations' is missing required arguments: from") end + end - context 'arguments' do - context 'from is missing' do - let(:args) { "to: \"#{from}\"" } - - it 'returns error' do - post_graphql(query, current_user: current_user) - - expect(graphql_errors[0]).to include("message" => "Field 'annotations' is missing required arguments: from") - end - end - - context 'to is missing' do - let(:args) { "from: \"#{from}\"" } + context 'to is missing' do + let(:args) { "from: \"#{from}\"" } - it_behaves_like 'a working graphql query' - end - end + it_behaves_like 'a working graphql query' end end end diff --git a/spec/requests/api/metrics/dashboard/annotations_spec.rb b/spec/requests/api/metrics/dashboard/annotations_spec.rb index c6a41ee6444..ec88b4db256 100644 --- a/spec/requests/api/metrics/dashboard/annotations_spec.rb +++ b/spec/requests/api/metrics/dashboard/annotations_spec.rb @@ -19,75 +19,55 @@ describe API::Metrics::Dashboard::Annotations do end context "with :source_type == #{source_type.pluralize}" do - context 'feature flag metrics_dashboard_annotations' do - context 'is on' do - before do - stub_feature_flags(metrics_dashboard_annotations: { enabled: true, thing: project }) - end + context 'with correct permissions' do + context 'with valid parameters' do + it 'creates a new annotation', :aggregate_failures do + post api(url, user), params: params - context 'with correct permissions' do - context 'with valid parameters' do - it 'creates a new annotation', :aggregate_failures do - post api(url, user), params: params - - expect(response).to have_gitlab_http_status(:created) - expect(json_response["#{source_type}_id"]).to eq(source.id) - expect(json_response['starting_at'].to_time).to eq(starting_at.to_time) - expect(json_response['ending_at'].to_time).to eq(ending_at.to_time) - expect(json_response['description']).to eq(params[:description]) - expect(json_response['dashboard_path']).to eq(dashboard) - end - end - - context 'with invalid parameters' do - it 'returns error messsage' do - post api(url, user), params: { dashboard_path: nil, starting_at: nil, description: nil } - - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']).to include({ "starting_at" => ["can't be blank"], "description" => ["can't be blank"], "dashboard_path" => ["can't be blank"] }) - end - end - - context 'with undeclared params' do - before do - params[:undeclared_param] = 'xyz' - end - - it 'filters out undeclared params' do - expect(::Metrics::Dashboard::Annotations::CreateService).to receive(:new).with(user, hash_excluding(:undeclared_param)) - - post api(url, user), params: params - end - end + expect(response).to have_gitlab_http_status(:created) + expect(json_response["#{source_type}_id"]).to eq(source.id) + expect(json_response['starting_at'].to_time).to eq(starting_at.to_time) + expect(json_response['ending_at'].to_time).to eq(ending_at.to_time) + expect(json_response['description']).to eq(params[:description]) + expect(json_response['dashboard_path']).to eq(dashboard) end + end - context 'without correct permissions' do - let_it_be(:guest) { create(:user) } - - before do - project.add_guest(guest) - end - - it 'returns error messsage' do - post api(url, guest), params: params + context 'with invalid parameters' do + it 'returns error messsage' do + post api(url, user), params: { dashboard_path: nil, starting_at: nil, description: nil } - expect(response).to have_gitlab_http_status(:forbidden) - end + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response['message']).to include({ "starting_at" => ["can't be blank"], "description" => ["can't be blank"], "dashboard_path" => ["can't be blank"] }) end end - context 'is off' do + context 'with undeclared params' do before do - stub_feature_flags(metrics_dashboard_annotations: { enabled: false }) + params[:undeclared_param] = 'xyz' end - it 'returns error messsage' do - post api(url, user), params: params + it 'filters out undeclared params' do + expect(::Metrics::Dashboard::Annotations::CreateService).to receive(:new).with(user, hash_excluding(:undeclared_param)) - expect(response).to have_gitlab_http_status(:not_found) + post api(url, user), params: params end end end + + context 'without correct permissions' do + let_it_be(:guest) { create(:user) } + + before do + project.add_guest(guest) + end + + it 'returns error message' do + post api(url, guest), params: params + + expect(response).to have_gitlab_http_status(:forbidden) + end + end end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index f776faf6458..0deff138e2e 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1806,7 +1806,7 @@ describe API::Projects do first_user = json_response.first expect(first_user['username']).to eq(user.username) expect(first_user['name']).to eq(user.name) - expect(first_user.keys).to contain_exactly(*%w[name username id state avatar_url web_url]) + expect(first_user.keys).to include(*%w[name username id state avatar_url web_url]) end end |