debian-mirror-gitlab/spec/controllers/admin/integrations_controller_spec.rb

109 lines
3.1 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Admin::IntegrationsController do
2020-04-08 14:13:33 +05:30
let(:admin) { create(:admin) }
before do
sign_in(admin)
end
2021-12-11 22:18:48 +05:30
it_behaves_like Integrations::Actions do
2021-11-11 11:23:49 +05:30
let(:integration_attributes) { { instance: true, project: nil } }
let(:routing_params) do
{ id: integration.to_param }
end
end
2020-04-08 14:13:33 +05:30
describe '#edit' do
2021-09-30 23:02:18 +05:30
Integration.available_integration_names.each do |integration_name|
2023-01-13 00:05:48 +05:30
context integration_name.to_s do
2020-04-08 14:13:33 +05:30
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
2021-01-03 14:25:43 +05:30
context 'when GitLab.com' do
before do
allow(::Gitlab).to receive(:com?) { true }
end
it 'returns 404' do
2021-09-30 23:02:18 +05:30
get :edit, params: { id: Integration.available_integration_names.sample }
2021-01-03 14:25:43 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
end
2020-04-08 14:13:33 +05:30
end
describe '#update' do
2022-07-23 23:45:48 +05:30
include JiraIntegrationHelpers
2020-11-24 15:15:51 +05:30
2021-09-30 23:02:18 +05:30
let(:integration) { create(:jira_integration, :instance) }
2020-04-08 14:13:33 +05:30
before do
2021-09-30 23:02:18 +05:30
stub_jira_integration_test
2020-06-23 00:09:42 +05:30
allow(PropagateIntegrationWorker).to receive(:perform_async)
2021-10-27 15:23:28 +05:30
put :update, params: { id: integration.class.to_param, service: params }
2020-04-08 14:13:33 +05:30
end
context 'valid params' do
2021-10-27 15:23:28 +05:30
let(:params) { { url: 'https://jira.gitlab-example.com', password: 'password' } }
2020-04-08 14:13:33 +05:30
it 'updates the integration' do
expect(response).to have_gitlab_http_status(:found)
2021-10-27 15:23:28 +05:30
expect(integration.reload).to have_attributes(params)
2020-04-08 14:13:33 +05:30
end
2020-06-23 00:09:42 +05:30
it 'calls to PropagateIntegrationWorker' do
2021-01-03 14:25:43 +05:30
expect(PropagateIntegrationWorker).to have_received(:perform_async).with(integration.id)
2020-06-23 00:09:42 +05:30
end
2020-04-08 14:13:33 +05:30
end
context 'invalid params' do
2021-10-27 15:23:28 +05:30
let(:params) { { url: 'invalid', password: 'password' } }
2020-04-08 14:13:33 +05:30
it 'does not update the integration' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
2021-10-27 15:23:28 +05:30
expect(integration.reload).not_to have_attributes(params)
2020-04-08 14:13:33 +05:30
end
2020-06-23 00:09:42 +05:30
it 'does not call to PropagateIntegrationWorker' do
expect(PropagateIntegrationWorker).not_to have_received(:perform_async)
end
2020-04-08 14:13:33 +05:30
end
end
2021-02-22 17:27:13 +05:30
describe '#reset' do
2021-09-30 23:02:18 +05:30
let_it_be(:integration) { create(:jira_integration, :instance) }
let_it_be(:inheriting_integration) { create(:jira_integration, inherit_from_id: integration.id) }
2021-02-22 17:27:13 +05:30
subject do
post :reset, params: { id: integration.class.to_param }
end
it 'returns 200 OK', :aggregate_failures do
subject
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
it 'deletes the integration and all inheriting integrations' do
2021-09-04 01:27:46 +05:30
expect { subject }.to change { Integrations::Jira.for_instance.count }.by(-1)
.and change { Integrations::Jira.inherit_from_id(integration.id).count }.by(-1)
2021-02-22 17:27:13 +05:30
end
end
2020-04-08 14:13:33 +05:30
end