Welcome to mirror list, hosted at ThFree Co, Russian Federation.

hook_service_spec.rb « pipelines « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8d138a3d95754dfb1eceece9f1212280b5fec41e (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::Pipelines::HookService do
  describe '#execute_hooks' do
    let_it_be(:namespace) { create(:namespace) }
    let_it_be(:project) { create(:project, :repository, namespace: namespace) }
    let_it_be(:pipeline, reload: true) { create(:ci_empty_pipeline, :created, project: project) }

    let(:hook_enabled) { true }
    let!(:hook) { create(:project_hook, project: project, pipeline_events: hook_enabled) }
    let(:hook_data) { double }

    subject(:service) { described_class.new(pipeline) }

    describe 'HOOK_NAME' do
      specify { expect(described_class::HOOK_NAME).to eq(:pipeline_hooks) }
    end

    context 'with pipeline hooks enabled' do
      before do
        allow(Gitlab::DataBuilder::Pipeline).to receive(:build).with(pipeline).once.and_return(hook_data)
      end

      it 'calls pipeline.project.execute_hooks and pipeline.project.execute_integrations' do
        create(:pipelines_email_integration, project: project)

        expect(pipeline.project).to receive(:execute_hooks).with(hook_data, described_class::HOOK_NAME)
        expect(pipeline.project).to receive(:execute_integrations).with(hook_data, described_class::HOOK_NAME)

        service.execute
      end
    end

    context 'with pipeline hooks and integrations disabled' do
      let(:hook_enabled) { false }

      it 'does not call pipeline.project.execute_hooks and pipeline.project.execute_integrations' do
        expect(pipeline.project).not_to receive(:execute_hooks)
        expect(pipeline.project).not_to receive(:execute_integrations)

        service.execute
      end
    end
  end
end