2019-11-26 12:06:18 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-06-24 15:07:28 +00:00
|
|
|
RSpec.describe IntegrationsHelper do
|
2022-02-28 00:18:02 +00:00
|
|
|
shared_examples 'is defined for each integration event' do
|
|
|
|
Integration.available_integration_names.each do |integration|
|
|
|
|
events = Integration.integration_name_to_model(integration).new.configurable_events
|
|
|
|
events.each do |event|
|
|
|
|
context "when integration is #{integration}, event is #{event}" do
|
|
|
|
let(:integration) { integration }
|
|
|
|
let(:event) { event }
|
|
|
|
|
|
|
|
it { is_expected.not_to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#integration_event_title' do
|
|
|
|
subject { helper.integration_event_title(event) }
|
|
|
|
|
|
|
|
it_behaves_like 'is defined for each integration event'
|
|
|
|
end
|
|
|
|
|
2021-07-06 21:07:50 +00:00
|
|
|
describe '#integration_event_description' do
|
2022-02-28 00:18:02 +00:00
|
|
|
subject { helper.integration_event_description(integration, event) }
|
|
|
|
|
|
|
|
it_behaves_like 'is defined for each integration event'
|
2021-07-06 21:07:50 +00:00
|
|
|
|
|
|
|
context 'when integration is Jira' do
|
|
|
|
let(:integration) { Integrations::Jira.new }
|
2022-02-28 00:18:02 +00:00
|
|
|
let(:event) { 'merge_request_events' }
|
2021-07-06 21:07:50 +00:00
|
|
|
|
|
|
|
it { is_expected.to include('Jira') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when integration is Team City' do
|
|
|
|
let(:integration) { Integrations::Teamcity.new }
|
2022-02-28 00:18:02 +00:00
|
|
|
let(:event) { 'merge_request_events' }
|
2021-07-06 21:07:50 +00:00
|
|
|
|
|
|
|
it { is_expected.to include('TeamCity') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-17 03:09:14 +00:00
|
|
|
describe '#integration_form_data' do
|
2022-01-19 18:14:01 +00:00
|
|
|
before do
|
|
|
|
allow(helper).to receive_messages(
|
|
|
|
request: double(referer: '/services')
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-02-17 18:09:19 +00:00
|
|
|
let(:fields) do
|
|
|
|
[
|
|
|
|
:id,
|
|
|
|
:show_active,
|
|
|
|
:activated,
|
2022-03-07 09:13:09 +00:00
|
|
|
:activate_disabled,
|
2021-02-17 18:09:19 +00:00
|
|
|
:type,
|
|
|
|
:merge_request_events,
|
|
|
|
:commit_events,
|
|
|
|
:enable_comments,
|
|
|
|
:comment_detail,
|
|
|
|
:learn_more_path,
|
2022-05-12 06:07:53 +00:00
|
|
|
:about_pricing_url,
|
2021-02-17 18:09:19 +00:00
|
|
|
:trigger_events,
|
|
|
|
:fields,
|
|
|
|
:inherit_from_id,
|
|
|
|
:integration_level,
|
|
|
|
:editable,
|
|
|
|
:cancel_path,
|
|
|
|
:can_test,
|
|
|
|
:test_path,
|
2022-01-19 18:14:01 +00:00
|
|
|
:reset_path,
|
|
|
|
:form_path,
|
|
|
|
:redirect_to
|
2021-02-17 18:09:19 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2021-03-29 21:09:08 +00:00
|
|
|
let(:jira_fields) do
|
|
|
|
[
|
|
|
|
:jira_issue_transition_automatic,
|
|
|
|
:jira_issue_transition_id
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2020-07-17 03:09:14 +00:00
|
|
|
subject { helper.integration_form_data(integration) }
|
|
|
|
|
2021-06-18 15:10:16 +00:00
|
|
|
context 'with Slack integration' do
|
|
|
|
let(:integration) { build(:integrations_slack) }
|
2020-07-17 03:09:14 +00:00
|
|
|
|
2021-02-17 18:09:19 +00:00
|
|
|
it { is_expected.to include(*fields) }
|
2021-03-29 21:09:08 +00:00
|
|
|
it { is_expected.not_to include(*jira_fields) }
|
2021-01-15 06:10:42 +00:00
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject[:reset_path]).to eq(helper.scoped_reset_integration_path(integration))
|
|
|
|
end
|
2022-01-19 18:14:01 +00:00
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject[:redirect_to]).to eq('/services')
|
|
|
|
end
|
2020-07-17 03:09:14 +00:00
|
|
|
end
|
2021-03-29 21:09:08 +00:00
|
|
|
|
|
|
|
context 'Jira service' do
|
2021-06-18 15:10:16 +00:00
|
|
|
let(:integration) { build(:jira_integration) }
|
2021-03-29 21:09:08 +00:00
|
|
|
|
|
|
|
it { is_expected.to include(*fields, *jira_fields) }
|
|
|
|
end
|
2020-07-17 03:09:14 +00:00
|
|
|
end
|
2020-08-25 03:10:50 +00:00
|
|
|
|
2021-12-21 06:13:16 +00:00
|
|
|
describe '#integration_overrides_data' do
|
|
|
|
let(:integration) { build_stubbed(:jira_integration) }
|
|
|
|
let(:fields) do
|
|
|
|
[
|
|
|
|
edit_path: edit_admin_application_settings_integration_path(integration),
|
|
|
|
overrides_path: overrides_admin_application_settings_integration_path(integration, format: :json)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { helper.integration_overrides_data(integration) }
|
|
|
|
|
|
|
|
it { is_expected.to include(*fields) }
|
|
|
|
end
|
|
|
|
|
2020-12-03 00:09:53 +00:00
|
|
|
describe '#scoped_reset_integration_path' do
|
2021-06-18 15:10:16 +00:00
|
|
|
let(:integration) { build_stubbed(:jira_integration) }
|
2020-12-03 00:09:53 +00:00
|
|
|
let(:group) { nil }
|
|
|
|
|
|
|
|
subject { helper.scoped_reset_integration_path(integration, group: group) }
|
|
|
|
|
|
|
|
context 'when no group is present' do
|
|
|
|
it 'returns instance-level path' do
|
|
|
|
is_expected.to eq(reset_admin_application_settings_integration_path(integration))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when group is present' do
|
|
|
|
let(:group) { build_stubbed(:group) }
|
|
|
|
|
|
|
|
it 'returns group-level path' do
|
|
|
|
is_expected.to eq(reset_group_settings_integration_path(group, integration))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-15 06:10:42 +00:00
|
|
|
context 'when a new integration is not persisted' do
|
2021-06-18 15:10:16 +00:00
|
|
|
let_it_be(:integration) { build(:jira_integration) }
|
2020-12-03 00:09:53 +00:00
|
|
|
|
2021-01-15 06:10:42 +00:00
|
|
|
it 'returns an empty string' do
|
|
|
|
is_expected.to eq('')
|
2020-12-03 00:09:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-26 12:06:18 +00:00
|
|
|
end
|