integrations_helper_spec.rb 2.49 KB
Newer Older
1 2 3 4
# frozen_string_literal: true

require 'spec_helper'

Alex Kalderimis's avatar
Alex Kalderimis committed
5
RSpec.describe IntegrationsHelper do
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
  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

22
  describe '#integration_form_data' do
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    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

46 47 48 49 50 51 52
    let(:jira_fields) do
      [
        :jira_issue_transition_automatic,
        :jira_issue_transition_id
      ]
    end

53 54
    subject { helper.integration_form_data(integration) }

55
    context 'with Slack integration' do
Alex Kalderimis's avatar
Alex Kalderimis committed
56
      let(:integration) { build(:integrations_slack) }
57

58
      it { is_expected.to include(*fields) }
59
      it { is_expected.not_to include(*jira_fields) }
60 61 62 63

      specify do
        expect(subject[:reset_path]).to eq(helper.scoped_reset_integration_path(integration))
      end
64
    end
65 66

    context 'Jira service' do
67
      let(:integration) { build(:jira_integration) }
68 69 70

      it { is_expected.to include(*fields, *jira_fields) }
    end
71
  end
72

73
  describe '#scoped_reset_integration_path' do
74
    let(:integration) { build_stubbed(:jira_integration) }
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    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

93
    context 'when a new integration is not persisted' do
94
      let_it_be(:integration) { build(:jira_integration) }
95

96 97
      it 'returns an empty string' do
        is_expected.to eq('')
98 99 100
      end
    end
  end
101
end