diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-25 09:08:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-25 09:08:11 +0000 |
commit | 5064bf8c5647d4c4430cbb4d097cf1592416de29 (patch) | |
tree | d051bf2abe2cc7061b3a7facb6669a56ccb9cf54 /spec/controllers | |
parent | 9c83aadd2604e7e6cb1f84683f951e6b12872618 (diff) | |
download | gitlab-ce-5064bf8c5647d4c4430cbb4d097cf1592416de29.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/projects/settings/operations_controller_spec.rb | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/controllers/projects/settings/operations_controller_spec.rb b/spec/controllers/projects/settings/operations_controller_spec.rb index 62b906e8507..c9afff0b73d 100644 --- a/spec/controllers/projects/settings/operations_controller_spec.rb +++ b/spec/controllers/projects/settings/operations_controller_spec.rb @@ -295,6 +295,94 @@ describe Projects::Settings::OperationsController do end end end + + describe 'POST reset_alerting_token' do + let(:project) { create(:project) } + + before do + project.add_maintainer(user) + end + + context 'with existing alerting setting' do + let!(:alerting_setting) do + create(:project_alerting_setting, project: project) + end + + let!(:old_token) { alerting_setting.token } + + it 'returns newly reset token' do + reset_alerting_token + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['token']).to eq(alerting_setting.reload.token) + expect(old_token).not_to eq(alerting_setting.token) + end + end + + context 'without existing alerting setting' do + it 'creates a token' do + reset_alerting_token + + expect(response).to have_gitlab_http_status(:ok) + expect(project.alerting_setting).not_to be_nil + expect(json_response['token']).to eq(project.alerting_setting.token) + end + end + + context 'when update fails' do + let(:operations_update_service) { spy(:operations_update_service) } + let(:alerting_params) do + { alerting_setting_attributes: { regenerate_token: true } } + end + + before do + expect(::Projects::Operations::UpdateService) + .to receive(:new).with(project, user, alerting_params) + .and_return(operations_update_service) + expect(operations_update_service).to receive(:execute) + .and_return(status: :error) + end + + it 'returns unprocessable_entity' do + reset_alerting_token + + expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(json_response).to be_empty + end + end + + context 'with insufficient permissions' do + before do + project.add_reporter(user) + end + + it 'returns 404' do + reset_alerting_token + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'as an anonymous user' do + before do + sign_out(user) + end + + it 'returns a redirect' do + reset_alerting_token + + expect(response).to have_gitlab_http_status(:redirect) + end + end + + private + + def reset_alerting_token + post :reset_alerting_token, + params: project_params(project), + format: :json + end + end end private |