diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-05 21:09:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-05 21:09:06 +0300 |
commit | b042382bbf5a4977c5b5c6b0a9a33f4e8ca8d16d (patch) | |
tree | de31671ab7c6ca8c2a3721cbabd1f2a42b3d0194 /spec/requests | |
parent | eabf8fd774fef6a54903e5141138f47bdafeb331 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/error_tracking_spec.rb | 162 | ||||
-rw-r--r-- | spec/requests/api/issues/issues_spec.rb | 31 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 32 |
3 files changed, 207 insertions, 18 deletions
diff --git a/spec/requests/api/error_tracking_spec.rb b/spec/requests/api/error_tracking_spec.rb index 48ddc7f5a75..059744898b8 100644 --- a/spec/requests/api/error_tracking_spec.rb +++ b/spec/requests/api/error_tracking_spec.rb @@ -3,11 +3,129 @@ require 'spec_helper' describe API::ErrorTracking do - describe "GET /projects/:id/error_tracking/settings" do - let(:user) { create(:user) } - let(:setting) { create(:project_error_tracking_setting) } - let(:project) { setting.project } + let(:user) { create(:user) } + let(:setting) { create(:project_error_tracking_setting) } + let(:project) { setting.project } + + shared_examples 'returns project settings' do + it 'returns correct project settings' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to eq( + 'active' => setting.reload.enabled, + 'project_name' => setting.project_name, + 'sentry_external_url' => setting.sentry_external_url, + 'api_url' => setting.api_url + ) + end + end + + shared_examples 'returns 404' do + it 'returns correct project settings' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + expect(json_response['message']) + .to eq('404 Error Tracking Setting Not Found') + end + end + + describe "PATCH /projects/:id/error_tracking/settings" do + def make_patch_request(**params) + patch api("/projects/#{project.id}/error_tracking/settings", user), params: params + end + + context 'when authenticated as maintainer' do + before do + project.add_maintainer(user) + end + + context 'patch settings' do + subject do + make_patch_request(active: false) + end + + it_behaves_like 'returns project settings' + + it 'returns active is invalid if non boolean' do + make_patch_request(active: "randomstring") + + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response['error']) + .to eq('active is invalid') + end + + it 'returns 400 if active is empty' do + make_patch_request(active: '') + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response['error']) + .to eq('active is empty') + end + end + + context 'without a project setting' do + let(:project) { create(:project) } + + before do + project.add_maintainer(user) + end + + context 'patch settings' do + subject do + make_patch_request(active: true) + end + + it_behaves_like 'returns 404' + end + end + end + + context 'when authenticated as reporter' do + before do + project.add_reporter(user) + end + + it 'returns 403 for update request' do + make_patch_request(active: true) + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context 'when authenticated as developer' do + before do + project.add_developer(user) + end + + it 'returns 403 for update request' do + make_patch_request(active: true) + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context 'when authenticated as non-member' do + it 'returns 404 for update request' do + make_patch_request(active: false) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when unauthenticated' do + let(:user) { nil } + + it 'returns 401 for update request' do + make_patch_request(active: true) + + expect(response).to have_gitlab_http_status(:unauthorized) + end + end + end + + describe "GET /projects/:id/error_tracking/settings" do def make_request get api("/projects/#{project.id}/error_tracking/settings", user) end @@ -17,16 +135,12 @@ describe API::ErrorTracking do project.add_maintainer(user) end - it 'returns project settings' do - make_request + context 'get settings' do + subject do + make_request + end - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).to eq( - 'active' => setting.enabled, - 'project_name' => setting.project_name, - 'sentry_external_url' => setting.sentry_external_url, - 'api_url' => setting.api_url - ) + it_behaves_like 'returns project settings' end end @@ -37,12 +151,12 @@ describe API::ErrorTracking do project.add_maintainer(user) end - it 'returns 404' do - make_request + context 'get settings' do + subject do + make_request + end - expect(response).to have_gitlab_http_status(:not_found) - expect(json_response['message']) - .to eq('404 Error Tracking Setting Not Found') + it_behaves_like 'returns 404' end end @@ -58,6 +172,18 @@ describe API::ErrorTracking do end end + context 'when authenticated as developer' do + before do + project.add_developer(user) + end + + it 'returns 403' do + make_request + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + context 'when authenticated as non-member' do it 'returns 404' do make_request diff --git a/spec/requests/api/issues/issues_spec.rb b/spec/requests/api/issues/issues_spec.rb index a3538aa98b1..09e005398a9 100644 --- a/spec/requests/api/issues/issues_spec.rb +++ b/spec/requests/api/issues/issues_spec.rb @@ -778,6 +778,32 @@ describe API::Issues do expect(json_response["error"]).to include("mutually exclusive") end end + + context 'filtering by non_archived' do + let_it_be(:group1) { create(:group) } + let_it_be(:archived_project) { create(:project, :archived, namespace: group1) } + let_it_be(:active_project) { create(:project, namespace: group1) } + let_it_be(:issue1) { create(:issue, project: active_project) } + let_it_be(:issue2) { create(:issue, project: active_project) } + let_it_be(:issue3) { create(:issue, project: archived_project) } + + before do + archived_project.add_developer(user) + active_project.add_developer(user) + end + + it 'returns issues from non archived projects only by default' do + get api("/groups/#{group1.id}/issues", user), params: { scope: 'all' } + + expect_response_contain_exactly(issue2, issue1) + end + + it 'returns issues from archived and non archived projects when non_archived is false' do + get api("/groups/#{group1.id}/issues", user), params: { non_archived: false, scope: 'all' } + + expect_response_contain_exactly(issue1, issue2, issue3) + end + end end context "when returns issue merge_requests_count for different access levels" do @@ -862,4 +888,9 @@ describe API::Issues do include_examples 'time tracking endpoints', 'issue' end + + def expect_response_contain_exactly(*items) + expect(json_response.length).to eq(items.size) + expect(json_response.map { |element| element['id'] }).to contain_exactly(*items.map(&:id)) + end end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 33ac175e945..adfe865da90 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -807,6 +807,38 @@ describe API::MergeRequests do end end end + + context 'with archived projects' do + let(:project2) { create(:project, :public, :archived, namespace: group) } + let!(:merge_request_archived) { create(:merge_request, title: 'archived mr', author: user, source_project: project2, target_project: project2) } + + it 'returns an array excluding merge_requests from archived projects' do + get api(endpoint_path, user) + + expect_response_contain_exactly( + merge_request_merged, + merge_request_locked, + merge_request_closed, + merge_request + ) + end + + context 'with non_archived param set as false' do + it 'returns an array including merge_requests from archived projects' do + path = endpoint_path + '?non_archived=false' + + get api(path, user) + + expect_response_contain_exactly( + merge_request_merged, + merge_request_locked, + merge_request_closed, + merge_request, + merge_request_archived + ) + end + end + end end describe "GET /projects/:id/merge_requests/:merge_request_iid" do |