2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-06 07:21:49 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe Admin::ServicesController do
|
2017-01-06 07:21:49 -05:00
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
2017-01-06 07:21:49 -05:00
|
|
|
|
|
|
|
describe 'GET #edit' do
|
2020-06-19 20:08:42 -04:00
|
|
|
let(:service) do
|
2020-03-24 14:07:55 -04:00
|
|
|
create(:jira_service, :template)
|
|
|
|
end
|
2017-01-06 07:21:49 -05:00
|
|
|
|
2020-03-24 14:07:55 -04:00
|
|
|
it 'successfully displays the template' do
|
|
|
|
get :edit, params: { id: service.id }
|
2017-01-06 07:21:49 -05:00
|
|
|
|
2020-03-24 14:07:55 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-01-06 07:21:49 -05:00
|
|
|
end
|
2020-06-19 20:08:42 -04:00
|
|
|
|
|
|
|
context 'when integration does not exists' do
|
|
|
|
it 'redirects to the admin application integration page' do
|
|
|
|
get :edit, params: { id: 'invalid' }
|
|
|
|
|
|
|
|
expect(response).to redirect_to(admin_application_settings_services_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when instance integration exists' do
|
|
|
|
before do
|
|
|
|
create(:jira_service, :instance)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to the admin application integration page' do
|
|
|
|
get :edit, params: { id: service.id }
|
|
|
|
|
|
|
|
expect(response).to redirect_to(admin_application_settings_services_path)
|
|
|
|
end
|
|
|
|
end
|
2017-01-06 07:21:49 -05:00
|
|
|
end
|
2017-05-04 12:11:28 -04:00
|
|
|
|
|
|
|
describe "#update" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2020-03-14 02:09:14 -04:00
|
|
|
let!(:service_template) do
|
2017-05-04 12:11:28 -04:00
|
|
|
RedmineService.create(
|
2020-03-14 02:09:14 -04:00
|
|
|
project: nil,
|
2017-05-04 12:11:28 -04:00
|
|
|
active: false,
|
2020-02-11 13:08:58 -05:00
|
|
|
template: true,
|
2017-05-04 12:11:28 -04:00
|
|
|
properties: {
|
|
|
|
project_url: 'http://abc',
|
|
|
|
issues_url: 'http://abc',
|
|
|
|
new_issue_url: 'http://abc'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-05-05 12:01:33 -04:00
|
|
|
it 'calls the propagation worker when service is active' do
|
2020-03-14 02:09:14 -04:00
|
|
|
expect(PropagateServiceTemplateWorker).to receive(:perform_async).with(service_template.id)
|
2017-05-04 12:11:28 -04:00
|
|
|
|
2020-03-14 02:09:14 -04:00
|
|
|
put :update, params: { id: service_template.id, service: { active: true } }
|
2017-05-04 12:11:28 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-05-04 12:11:28 -04:00
|
|
|
end
|
|
|
|
|
2017-05-05 12:01:33 -04:00
|
|
|
it 'does not call the propagation worker when service is not active' do
|
2020-02-11 13:08:58 -05:00
|
|
|
expect(PropagateServiceTemplateWorker).not_to receive(:perform_async)
|
2017-05-04 12:11:28 -04:00
|
|
|
|
2020-03-14 02:09:14 -04:00
|
|
|
put :update, params: { id: service_template.id, service: { properties: {} } }
|
2017-05-04 12:11:28 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-05-04 12:11:28 -04:00
|
|
|
end
|
|
|
|
end
|
2017-01-06 07:21:49 -05:00
|
|
|
end
|