diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-14 00:07:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-14 00:07:39 +0300 |
commit | 74a89b1221eaf780374bd1d4c5b2ee4a0f488908 (patch) | |
tree | 27dbcfdbc4216e9bee04b9be9c974d86744d51ba /spec/requests/api | |
parent | b0abae12affecc466aeb10889e8a6c000d6f67f5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api')
-rw-r--r-- | spec/requests/api/deployments_spec.rb | 42 | ||||
-rw-r--r-- | spec/requests/api/error_tracking_spec.rb | 78 |
2 files changed, 120 insertions, 0 deletions
diff --git a/spec/requests/api/deployments_spec.rb b/spec/requests/api/deployments_spec.rb index 7e184cea3c0..9add328f6a8 100644 --- a/spec/requests/api/deployments_spec.rb +++ b/spec/requests/api/deployments_spec.rb @@ -343,6 +343,48 @@ describe API::Deployments do end end + describe 'GET /projects/:id/deployments/:deployment_id/merge_requests' do + let(:project) { create(:project, :repository) } + let!(:deployment) { create(:deployment, :success, project: project) } + + subject { get api("/projects/#{project.id}/deployments/#{deployment.id}/merge_requests", user) } + + context 'when a user is not a member of the deployment project' do + let(:user) { build(:user) } + + it 'returns a 404 status code' do + subject + + expect(response).to have_gitlab_http_status(404) + end + end + + context 'when a user member of the deployment project' do + let_it_be(:project2) { create(:project) } + let!(:merge_request1) { create(:merge_request, source_project: project, target_project: project) } + let!(:merge_request2) { create(:merge_request, source_project: project, target_project: project, state: 'closed') } + let!(:merge_request3) { create(:merge_request, source_project: project2, target_project: project2) } + + it 'returns the relevant merge requests linked to a deployment for a project' do + deployment.merge_requests << [merge_request1, merge_request2] + + subject + + expect(response).to have_gitlab_http_status(200) + expect(json_response.map { |d| d['id'] }).to contain_exactly(merge_request1.id, merge_request2.id) + end + + context 'when a deployment is not associated to any existing merge requests' do + it 'returns an empty array' do + subject + + expect(response).to have_gitlab_http_status(200) + expect(json_response).to eq([]) + end + end + end + end + context 'prevent N + 1 queries' do context 'when the endpoint returns multiple records' do let(:project) { create(:project, :repository) } diff --git a/spec/requests/api/error_tracking_spec.rb b/spec/requests/api/error_tracking_spec.rb new file mode 100644 index 00000000000..af337f34a68 --- /dev/null +++ b/spec/requests/api/error_tracking_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +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 } + + def make_request + get api("/projects/#{project.id}/error_tracking/settings", user) + end + + context 'when authenticated as maintainer' do + before do + project.add_maintainer(user) + end + + it 'returns project settings' do + make_request + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to eq( + 'project_name' => setting.project_name, + 'sentry_external_url' => setting.sentry_external_url, + 'api_url' => setting.api_url + ) + end + end + + context 'without a project setting' do + let(:project) { create(:project) } + + before do + project.add_maintainer(user) + end + + it 'returns 404' do + make_request + + expect(response).to have_gitlab_http_status(:not_found) + expect(json_response['message']) + .to eq('404 Error Tracking Setting Not Found') + end + end + + context 'when authenticated as reporter' do + before do + project.add_reporter(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 + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when unauthenticated' do + let(:user) { nil } + + it 'returns 401' do + make_request + + expect(response).to have_gitlab_http_status(:unauthorized) + end + end + end +end |