2020-03-13 05:09:23 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe Admin::IntegrationsController do
|
2020-03-13 05:09:23 -04:00
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#edit' do
|
|
|
|
Service.available_services_names.each do |integration_name|
|
|
|
|
context "#{integration_name}" do
|
|
|
|
it 'successfully displays the template' do
|
|
|
|
get :edit, params: { id: integration_name }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to render_template(:edit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-09-25 17:09:51 -04:00
|
|
|
|
|
|
|
context 'when GitLab.com' do
|
|
|
|
before do
|
|
|
|
allow(::Gitlab).to receive(:com?) { true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404' do
|
|
|
|
get :edit, params: { id: Service.available_services_names.sample }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 05:09:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update' do
|
2020-08-28 05:10:32 -04:00
|
|
|
include JiraServiceHelper
|
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
let(:integration) { create(:jira_service, :instance) }
|
|
|
|
|
2020-03-13 05:09:23 -04:00
|
|
|
before do
|
2020-08-28 05:10:32 -04:00
|
|
|
stub_jira_service_test
|
2020-05-20 14:08:00 -04:00
|
|
|
allow(PropagateIntegrationWorker).to receive(:perform_async)
|
|
|
|
|
2020-08-27 11:10:21 -04:00
|
|
|
put :update, params: { id: integration.class.to_param, service: { url: url } }
|
2020-03-13 05:09:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'valid params' do
|
|
|
|
let(:url) { 'https://jira.gitlab-example.com' }
|
|
|
|
|
|
|
|
it 'updates the integration' do
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(integration.reload.url).to eq(url)
|
|
|
|
end
|
2020-05-20 14:08:00 -04:00
|
|
|
|
|
|
|
it 'calls to PropagateIntegrationWorker' do
|
2020-09-25 17:09:51 -04:00
|
|
|
expect(PropagateIntegrationWorker).to have_received(:perform_async).with(integration.id)
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
2020-03-13 05:09:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid params' do
|
2020-04-21 11:21:10 -04:00
|
|
|
let(:url) { 'invalid' }
|
2020-03-13 05:09:23 -04:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'does not update the integration' do
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to render_template(:edit)
|
|
|
|
expect(integration.reload.url).not_to eq(url)
|
2020-03-13 05:09:23 -04:00
|
|
|
end
|
2020-05-20 14:08:00 -04:00
|
|
|
|
|
|
|
it 'does not call to PropagateIntegrationWorker' do
|
|
|
|
expect(PropagateIntegrationWorker).not_to have_received(:perform_async)
|
|
|
|
end
|
2020-03-13 05:09:23 -04:00
|
|
|
end
|
|
|
|
end
|
2020-12-02 19:09:53 -05:00
|
|
|
|
|
|
|
describe '#reset' do
|
|
|
|
let(:integration) { create(:jira_service, :instance) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
post :reset, params: { id: integration.class.to_param }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200 OK' do
|
|
|
|
expected_json = {}.to_json
|
|
|
|
|
|
|
|
expect(flash[:notice]).to eq('This integration, and inheriting projects were reset.')
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response.body).to eq(expected_json)
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 05:09:23 -04:00
|
|
|
end
|