Commit 988e0b53 authored by Rajendra Kadam's avatar Rajendra Kadam

Add patch api for enabling error tracking settings

parent e1531b35
...@@ -39,12 +39,18 @@ module API ...@@ -39,12 +39,18 @@ module API
not_found!('Error Tracking Setting') unless setting not_found!('Error Tracking Setting') unless setting
update_params = { # update_params = {
error_tracking_setting_attributes: { enabled: params[:active] } # error_tracking_setting_attributes: { enabled: params[:active] }
} # }
result = ::Projects::Operations::UpdateService.new(user_project, current_user, update_params).execute
# result = ::Projects::Operations::UpdateService.new(user_project, current_user, update_params).execute
present result, with: Entities::ErrorTracking::ProjectSetting setting.enabled = params[:active]
setting.save!
# if result[:status] == :success
present setting, with: Entities::ErrorTracking::ProjectSetting
# else
# result
# end
end end
end end
end end
......
...@@ -12,6 +12,10 @@ describe API::ErrorTracking do ...@@ -12,6 +12,10 @@ describe API::ErrorTracking do
get api("/projects/#{project.id}/error_tracking/settings", user) get api("/projects/#{project.id}/error_tracking/settings", user)
end end
def make_patch_request(active)
patch api("/projects/#{project.id}/error_tracking/settings", user), params: { active: active }
end
context 'when authenticated as maintainer' do context 'when authenticated as maintainer' do
before do before do
project.add_maintainer(user) project.add_maintainer(user)
...@@ -28,6 +32,14 @@ describe API::ErrorTracking do ...@@ -28,6 +32,14 @@ describe API::ErrorTracking do
'api_url' => setting.api_url 'api_url' => setting.api_url
) )
end end
it 'returns active is invalid if non boolean' do
make_patch_request("randomstring")
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error'])
.to eq('active is invalid')
end
end end
context 'without a project setting' do context 'without a project setting' do
...@@ -44,6 +56,14 @@ describe API::ErrorTracking do ...@@ -44,6 +56,14 @@ describe API::ErrorTracking do
expect(json_response['message']) expect(json_response['message'])
.to eq('404 Error Tracking Setting Not Found') .to eq('404 Error Tracking Setting Not Found')
end end
it 'returns 404 for update request' do
make_patch_request(true)
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message'])
.to eq('404 Error Tracking Setting Not Found')
end
end end
context 'when authenticated as reporter' do context 'when authenticated as reporter' do
...@@ -56,6 +76,12 @@ describe API::ErrorTracking do ...@@ -56,6 +76,12 @@ describe API::ErrorTracking do
expect(response).to have_gitlab_http_status(:forbidden) expect(response).to have_gitlab_http_status(:forbidden)
end end
it 'returns 403 for update request' do
make_patch_request(true)
expect(response).to have_gitlab_http_status(:forbidden)
end
end end
context 'when authenticated as non-member' do context 'when authenticated as non-member' do
...@@ -64,6 +90,12 @@ describe API::ErrorTracking do ...@@ -64,6 +90,12 @@ describe API::ErrorTracking do
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns 404 for update request' do
make_patch_request(false)
expect(response).to have_gitlab_http_status(:not_found)
end
end end
context 'when unauthenticated' do context 'when unauthenticated' do
...@@ -74,6 +106,12 @@ describe API::ErrorTracking do ...@@ -74,6 +106,12 @@ describe API::ErrorTracking do
expect(response).to have_gitlab_http_status(:unauthorized) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it 'returns 401 for update request' do
make_patch_request(true)
expect(response).to have_gitlab_http_status(:unauthorized)
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment