summaryrefslogtreecommitdiff
path: root/spec/finders/alert_management/http_integrations_finder_spec.rb
blob: d65de2cdbbd5f5a39b58cf51f328eb5bb1798e12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe AlertManagement::HttpIntegrationsFinder do
  let_it_be(:project) { create(:project) }
  let_it_be_with_reload(:integration) { create(:alert_management_http_integration, project: project ) }
  let_it_be(:extra_integration) { create(:alert_management_http_integration, project: project ) }
  let_it_be(:alt_project_integration) { create(:alert_management_http_integration) }

  let(:params) { {} }

  describe '#execute' do
    subject(:execute) { described_class.new(project, params).execute }

    context 'empty params' do
      it { is_expected.to contain_exactly(integration) }
    end

    context 'endpoint_identifier param given' do
      let(:params) { { endpoint_identifier: integration.endpoint_identifier } }

      it { is_expected.to contain_exactly(integration) }

      context 'matches an unavailable integration' do
        let(:params) { { endpoint_identifier: extra_integration.endpoint_identifier } }

        it { is_expected.to be_empty }
      end

      context 'but unknown' do
        let(:params) { { endpoint_identifier: 'unknown' } }

        it { is_expected.to be_empty }
      end

      context 'but blank' do
        let(:params) { { endpoint_identifier: nil } }

        it { is_expected.to contain_exactly(integration) }
      end
    end

    context 'active param given' do
      let(:params) { { active: true } }

      it { is_expected.to contain_exactly(integration) }

      context 'when integration is disabled' do
        before do
          integration.update!(active: false)
        end

        it { is_expected.to be_empty }
      end

      context 'but blank' do
        let(:params) { { active: nil } }

        it { is_expected.to contain_exactly(integration) }
      end
    end

    context 'project has no integrations' do
      subject(:execute) { described_class.new(create(:project), params).execute }

      it { is_expected.to be_empty }
    end
  end
end