2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Admin::ServicesController do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe 'GET #edit' do
|
2020-07-28 23:09:34 +05:30
|
|
|
let(:service) do
|
2020-04-22 19:07:51 +05:30
|
|
|
create(:jira_service, :template)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'successfully displays the template' do
|
|
|
|
get :edit, params: { id: service.id }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update" do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2020-04-08 14:13:33 +05:30
|
|
|
let!(:service_template) do
|
2017-08-17 22:00:37 +05:30
|
|
|
RedmineService.create(
|
2020-04-08 14:13:33 +05:30
|
|
|
project: nil,
|
2017-08-17 22:00:37 +05:30
|
|
|
active: false,
|
|
|
|
template: true,
|
|
|
|
properties: {
|
|
|
|
project_url: 'http://abc',
|
|
|
|
issues_url: 'http://abc',
|
|
|
|
new_issue_url: 'http://abc'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls the propagation worker when service is active' do
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(PropagateServiceTemplateWorker).to receive(:perform_async).with(service_template.id)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
put :update, params: { id: service_template.id, service: { active: true } }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not call the propagation worker when service is not active' do
|
|
|
|
expect(PropagateServiceTemplateWorker).not_to receive(:perform_async)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
put :update, params: { id: service_template.id, service: { properties: {} } }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|