2019-11-26 07:06:18 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-06-24 11:07:28 -04:00
|
|
|
RSpec.describe IntegrationsHelper do
|
2021-07-06 17:07:50 -04:00
|
|
|
describe '#integration_event_description' do
|
|
|
|
subject(:description) { helper.integration_event_description(integration, 'merge_request_events') }
|
|
|
|
|
|
|
|
context 'when integration is Jira' do
|
|
|
|
let(:integration) { Integrations::Jira.new }
|
|
|
|
|
|
|
|
it { is_expected.to include('Jira') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when integration is Team City' do
|
|
|
|
let(:integration) { Integrations::Teamcity.new }
|
|
|
|
|
|
|
|
it { is_expected.to include('TeamCity') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-16 23:09:14 -04:00
|
|
|
describe '#integration_form_data' do
|
2021-02-17 13:09:19 -05:00
|
|
|
let(:fields) do
|
|
|
|
[
|
|
|
|
:id,
|
|
|
|
:show_active,
|
|
|
|
:activated,
|
|
|
|
:type,
|
|
|
|
:merge_request_events,
|
|
|
|
:commit_events,
|
|
|
|
:enable_comments,
|
|
|
|
:comment_detail,
|
|
|
|
:learn_more_path,
|
|
|
|
:trigger_events,
|
|
|
|
:fields,
|
|
|
|
:inherit_from_id,
|
|
|
|
:integration_level,
|
|
|
|
:editable,
|
|
|
|
:cancel_path,
|
|
|
|
:can_test,
|
|
|
|
:test_path,
|
|
|
|
:reset_path
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2021-03-29 17:09:08 -04:00
|
|
|
let(:jira_fields) do
|
|
|
|
[
|
|
|
|
:jira_issue_transition_automatic,
|
|
|
|
:jira_issue_transition_id
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2020-07-16 23:09:14 -04:00
|
|
|
subject { helper.integration_form_data(integration) }
|
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
context 'with Slack integration' do
|
|
|
|
let(:integration) { build(:integrations_slack) }
|
2020-07-16 23:09:14 -04:00
|
|
|
|
2021-02-17 13:09:19 -05:00
|
|
|
it { is_expected.to include(*fields) }
|
2021-03-29 17:09:08 -04:00
|
|
|
it { is_expected.not_to include(*jira_fields) }
|
2021-01-15 01:10:42 -05:00
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject[:reset_path]).to eq(helper.scoped_reset_integration_path(integration))
|
|
|
|
end
|
2020-07-16 23:09:14 -04:00
|
|
|
end
|
2021-03-29 17:09:08 -04:00
|
|
|
|
|
|
|
context 'Jira service' do
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:integration) { build(:jira_integration) }
|
2021-03-29 17:09:08 -04:00
|
|
|
|
|
|
|
it { is_expected.to include(*fields, *jira_fields) }
|
|
|
|
end
|
2020-07-16 23:09:14 -04:00
|
|
|
end
|
2020-08-24 23:10:50 -04:00
|
|
|
|
2020-12-02 19:09:53 -05:00
|
|
|
describe '#scoped_reset_integration_path' do
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:integration) { build_stubbed(:jira_integration) }
|
2020-12-02 19:09:53 -05: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 01:10:42 -05:00
|
|
|
context 'when a new integration is not persisted' do
|
2021-06-18 11:10:16 -04:00
|
|
|
let_it_be(:integration) { build(:jira_integration) }
|
2020-12-02 19:09:53 -05:00
|
|
|
|
2021-01-15 01:10:42 -05:00
|
|
|
it 'returns an empty string' do
|
|
|
|
is_expected.to eq('')
|
2020-12-02 19:09:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-08-31 17:10:43 -04:00
|
|
|
|
|
|
|
describe '#jira_issue_breadcrumb_link' do
|
|
|
|
let(:issue_reference) { nil }
|
|
|
|
|
|
|
|
subject { helper.jira_issue_breadcrumb_link(issue_reference) }
|
|
|
|
|
|
|
|
context 'when issue_reference contains HTML' do
|
|
|
|
let(:issue_reference) { "<script>alert('XSS')</script>" }
|
|
|
|
|
|
|
|
it 'escapes issue reference' do
|
|
|
|
is_expected.not_to include(issue_reference)
|
|
|
|
is_expected.to include(html_escape(issue_reference))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-26 07:06:18 -05:00
|
|
|
end
|