Skip to content
Snippets Groups Projects
Commit cf1d4237 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 0ac82f99
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,13 +3,13 @@
require 'spec_helper'
 
describe API::ErrorTracking do
let(:user) { create(:user) }
let_it_be(: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
make_request
 
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq(
Loading
Loading
@@ -23,7 +23,7 @@ describe API::ErrorTracking do
 
shared_examples 'returns 404' do
it 'returns correct project settings' do
subject
make_request
 
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message'])
Loading
Loading
@@ -32,7 +32,9 @@ describe API::ErrorTracking do
end
 
describe "PATCH /projects/:id/error_tracking/settings" do
def make_patch_request(**params)
let(:params) { { active: false } }
def make_request
patch api("/projects/#{project.id}/error_tracking/settings", user), params: params
end
 
Loading
Loading
@@ -42,26 +44,39 @@ describe API::ErrorTracking do
end
 
context 'patch settings' do
subject do
make_patch_request(active: false)
it_behaves_like 'returns project settings'
it 'updates enabled flag' do
expect(setting).to be_enabled
make_request
expect(json_response).to include('active' => false)
expect(setting.reload).not_to be_enabled
end
 
it_behaves_like 'returns project settings'
context 'active is invalid' do
let(:params) { { active: "randomstring" } }
 
it 'returns active is invalid if non boolean' do
make_patch_request(active: "randomstring")
it 'returns active is invalid if non boolean' do
make_request
 
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error'])
.to eq('active is invalid')
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error'])
.to eq('active is invalid')
end
end
 
it 'returns 400 if active is empty' do
make_patch_request(active: '')
context 'active is empty' do
let(:params) { { active: '' } }
it 'returns 400' do
make_request
 
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error'])
.to eq('active is empty')
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error'])
.to eq('active is empty')
end
end
end
 
Loading
Loading
@@ -73,10 +88,6 @@ describe API::ErrorTracking do
end
 
context 'patch settings' do
subject do
make_patch_request(active: true)
end
it_behaves_like 'returns 404'
end
end
Loading
Loading
@@ -87,10 +98,12 @@ describe API::ErrorTracking do
project.add_reporter(user)
end
 
it 'returns 403 for update request' do
make_patch_request(active: true)
context 'patch request' do
it 'returns 403' do
make_request
 
expect(response).to have_gitlab_http_status(:forbidden)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
 
Loading
Loading
@@ -99,28 +112,34 @@ describe API::ErrorTracking do
project.add_developer(user)
end
 
it 'returns 403 for update request' do
make_patch_request(active: true)
context 'patch request' do
it 'returns 403' do
make_request
 
expect(response).to have_gitlab_http_status(:forbidden)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
 
context 'when authenticated as non-member' do
it 'returns 404 for update request' do
make_patch_request(active: false)
context 'patch request' do
it 'returns 404' do
make_request
 
expect(response).to have_gitlab_http_status(:not_found)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
 
context 'when unauthenticated' do
let(:user) { nil }
 
it 'returns 401 for update request' do
make_patch_request(active: true)
context 'patch request' do
it 'returns 401 for update request' do
make_request
 
expect(response).to have_gitlab_http_status(:unauthorized)
expect(response).to have_gitlab_http_status(:unauthorized)
end
end
end
end
Loading
Loading
@@ -136,10 +155,6 @@ describe API::ErrorTracking do
end
 
context 'get settings' do
subject do
make_request
end
it_behaves_like 'returns project settings'
end
end
Loading
Loading
@@ -152,10 +167,6 @@ describe API::ErrorTracking do
end
 
context 'get settings' do
subject do
make_request
end
it_behaves_like 'returns 404'
end
end
Loading
Loading
Loading
Loading
@@ -5,6 +5,26 @@ require 'spec_helper'
describe Projects::Alerting::NotifyService do
let_it_be(:project, reload: true) { create(:project) }
 
before do
# We use `let_it_be(:project)` so we make sure to clear caches
project.clear_memoization(:licensed_feature_available)
end
shared_examples 'processes incident issues' do |amount|
let(:create_incident_service) { spy }
it 'processes issues' do
expect(IncidentManagement::ProcessAlertWorker)
.to receive(:perform_async)
.with(project.id, kind_of(Hash))
.exactly(amount).times
Sidekiq::Testing.inline! do
expect(subject.status).to eq(:success)
end
end
end
shared_examples 'does not process incident issues' do |http_status:|
it 'does not process issues' do
expect(IncidentManagement::ProcessAlertWorker)
Loading
Loading
@@ -29,6 +49,36 @@ describe Projects::Alerting::NotifyService do
 
subject { service.execute(token) }
 
it_behaves_like 'does not process incident issues', http_status: 403
context 'with activated Alerts Service' do
let!(:alerts_service) { create(:alerts_service, project: project) }
context 'with valid token' do
let(:token) { alerts_service.token }
context 'with a valid payload' do
it_behaves_like 'processes incident issues', 1
end
context 'with an invalid payload' do
before do
allow(Gitlab::Alerting::NotificationPayloadParser)
.to receive(:call)
.and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError)
end
it_behaves_like 'does not process incident issues', http_status: 400
end
end
context 'with invalid token' do
it_behaves_like 'does not process incident issues', http_status: 401
end
end
context 'with deactivated Alerts Service' do
let!(:alerts_service) { create(:alerts_service, :inactive, project: project) }
it_behaves_like 'does not process incident issues', http_status: 403
end
end
end
Loading
Loading
@@ -32,8 +32,7 @@ Service.available_services_names.each do |service|
{
'github' => :github_project_service_integration,
'jenkins' => :jenkins_integration,
'jenkins_deprecated' => :jenkins_integration,
'alerts' => :incident_management
'jenkins_deprecated' => :jenkins_integration
}
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment