debian-mirror-gitlab/spec/helpers/integrations_helper_spec.rb

205 lines
5.7 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
2021-09-30 23:02:18 +05:30
RSpec.describe IntegrationsHelper do
2022-05-07 20:08:51 +05:30
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-09-30 23:02:18 +05:30
describe '#integration_event_description' do
2022-05-07 20:08:51 +05:30
subject { helper.integration_event_description(integration, event) }
it_behaves_like 'is defined for each integration event'
2021-09-30 23:02:18 +05:30
context 'when integration is Jira' do
let(:integration) { Integrations::Jira.new }
2022-05-07 20:08:51 +05:30
let(:event) { 'merge_request_events' }
2021-09-30 23:02:18 +05:30
it { is_expected.to include('Jira') }
end
context 'when integration is Team City' do
let(:integration) { Integrations::Teamcity.new }
2022-05-07 20:08:51 +05:30
let(:event) { 'merge_request_events' }
2021-09-30 23:02:18 +05:30
it { is_expected.to include('TeamCity') }
end
end
2020-07-28 23:09:34 +05:30
describe '#integration_form_data' do
2022-03-02 08:16:31 +05:30
before do
allow(helper).to receive_messages(
request: double(referer: '/services')
)
end
2021-04-17 20:07:23 +05:30
let(:fields) do
[
:id,
:show_active,
:activated,
2022-05-07 20:08:51 +05:30
:activate_disabled,
2021-04-17 20:07:23 +05:30
:type,
:merge_request_events,
:commit_events,
:enable_comments,
:comment_detail,
:learn_more_path,
2022-07-16 23:28:13 +05:30
:about_pricing_url,
2021-04-17 20:07:23 +05:30
:trigger_events,
:fields,
:inherit_from_id,
:integration_level,
:editable,
:cancel_path,
:can_test,
:test_path,
2022-03-02 08:16:31 +05:30
:reset_path,
:form_path,
:redirect_to
2021-04-17 20:07:23 +05:30
]
end
2021-04-29 21:17:54 +05:30
let(:jira_fields) do
[
:jira_issue_transition_automatic,
:jira_issue_transition_id
]
end
2020-07-28 23:09:34 +05:30
subject { helper.integration_form_data(integration) }
2021-09-30 23:02:18 +05:30
context 'with Slack integration' do
let(:integration) { build(:integrations_slack) }
2021-04-17 20:07:23 +05:30
it { is_expected.to include(*fields) }
2021-04-29 21:17:54 +05:30
it { is_expected.not_to include(*jira_fields) }
2021-03-08 18:12:59 +05:30
specify do
expect(subject[:reset_path]).to eq(helper.scoped_reset_integration_path(integration))
end
2022-03-02 08:16:31 +05:30
specify do
expect(subject[:redirect_to]).to eq('/services')
end
2020-07-28 23:09:34 +05:30
end
2021-04-29 21:17:54 +05:30
context 'Jira service' do
2021-09-30 23:02:18 +05:30
let(:integration) { build(:jira_integration) }
2021-04-29 21:17:54 +05:30
it { is_expected.to include(*fields, *jira_fields) }
end
2020-01-01 13:55:28 +05:30
end
2020-11-24 15:15:51 +05:30
2022-03-02 08:16:31 +05:30
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
2021-02-22 17:27:13 +05:30
describe '#scoped_reset_integration_path' do
2021-09-30 23:02:18 +05:30
let(:integration) { build_stubbed(:jira_integration) }
2021-02-22 17:27:13 +05:30
let(:group) { nil }
subject { helper.scoped_reset_integration_path(integration, group: group) }
2020-11-24 15:15:51 +05:30
context 'when no group is present' do
2021-02-22 17:27:13 +05:30
it 'returns instance-level path' do
is_expected.to eq(reset_admin_application_settings_integration_path(integration))
end
2020-11-24 15:15:51 +05:30
end
context 'when group is present' do
let(:group) { build_stubbed(:group) }
2021-02-22 17:27:13 +05:30
it 'returns group-level path' do
is_expected.to eq(reset_group_settings_integration_path(group, integration))
2020-11-24 15:15:51 +05:30
end
2021-02-22 17:27:13 +05:30
end
2020-11-24 15:15:51 +05:30
2021-03-08 18:12:59 +05:30
context 'when a new integration is not persisted' do
2021-09-30 23:02:18 +05:30
let_it_be(:integration) { build(:jira_integration) }
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
it 'returns an empty string' do
is_expected.to eq('')
2021-02-22 17:27:13 +05:30
end
end
2020-11-24 15:15:51 +05:30
end
2023-01-13 00:05:48 +05:30
describe '#integration_issue_type' do
using RSpec::Parameterized::TableSyntax
let_it_be(:issue) { create(:issue) }
where(:issue_type, :expected_i18n_issue_type) do
"issue" | _('Issue')
"incident" | _('Incident')
"test_case" | _('Test case')
"requirement" | _('Requirement')
"task" | _('Task')
end
with_them do
before do
2023-06-20 00:43:36 +05:30
issue.assign_attributes(issue_type: issue_type, work_item_type: WorkItems::Type.default_by_type(issue_type))
issue.save!(validate: false)
2023-01-13 00:05:48 +05:30
end
it "return the correct i18n issue type" do
expect(described_class.integration_issue_type(issue.issue_type)).to eq(expected_i18n_issue_type)
end
end
it "only consider these enumeration values are valid" do
expected_valid_types = %w[issue incident test_case requirement task objective key_result]
expect(Issue.issue_types.keys).to contain_exactly(*expected_valid_types)
end
end
describe '#integration_todo_target_type' do
using RSpec::Parameterized::TableSyntax
let!(:todo) { create(:todo, commit_id: '123') }
where(:target_type, :expected_i18n_target_type) do
"Commit" | _("Commit")
"Issue" | _("Issue")
"MergeRequest" | _("Merge Request")
'Epic' | _('Epic')
DesignManagement::Design.name | _('design')
AlertManagement::Alert.name | _('alert')
end
with_them do
before do
todo.update!(target_type: target_type)
end
it { expect(described_class.integration_todo_target_type(todo.target_type)).to eq(expected_i18n_target_type) }
end
end
2020-01-01 13:55:28 +05:30
end