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
not_found!('Error Tracking Setting') unless setting
update_params = {
error_tracking_setting_attributes: { enabled: params[:active] }
}
result = ::Projects::Operations::UpdateService.new(user_project, current_user, update_params).execute
present result, with: Entities::ErrorTracking::ProjectSetting
# update_params = {
# error_tracking_setting_attributes: { enabled: params[:active] }
# }
# result = ::Projects::Operations::UpdateService.new(user_project, current_user, update_params).execute
setting.enabled = params[:active]
setting.save!
# if result[:status] == :success
present setting, with: Entities::ErrorTracking::ProjectSetting
# else
# result
# end
end
end
end
......
......@@ -12,6 +12,10 @@ describe API::ErrorTracking do
get api("/projects/#{project.id}/error_tracking/settings", user)
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
before do
project.add_maintainer(user)
......@@ -28,6 +32,14 @@ describe API::ErrorTracking do
'api_url' => setting.api_url
)
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
context 'without a project setting' do
......@@ -44,6 +56,14 @@ describe API::ErrorTracking do
expect(json_response['message'])
.to eq('404 Error Tracking Setting Not Found')
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
context 'when authenticated as reporter' do
......@@ -56,6 +76,12 @@ describe API::ErrorTracking do
expect(response).to have_gitlab_http_status(:forbidden)
end
it 'returns 403 for update request' do
make_patch_request(true)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'when authenticated as non-member' do
......@@ -64,6 +90,12 @@ describe API::ErrorTracking do
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns 404 for update request' do
make_patch_request(false)
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when unauthenticated' do
......@@ -74,6 +106,12 @@ describe API::ErrorTracking do
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'returns 401 for update request' do
make_patch_request(true)
expect(response).to have_gitlab_http_status(:unauthorized)
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