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

pipeline_trigger_service_spec.rb « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e60d04738c6c328f4ebcfbb75b129c84d668341 (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
71
require 'spec_helper'

describe Ci::PipelineTriggerService, services: true do
  let(:project) { create(:project, :repository) }

  before do
    stub_ci_pipeline_to_return_yaml_file
  end

  describe '#execute' do
    let(:user) { create(:user) }
    let(:trigger) { create(:ci_trigger, project: project, owner: user) }
    let(:result) { described_class.new(project, user, params).execute }

    let(:params) do
      { token: token, ref: ref, variables: variables }
    end

    before do
      project.add_developer(user)
    end

    context 'when params have an existsed trigger token' do
      let(:token) { trigger.token }

      context 'when params have an existsed ref' do
        let(:ref) { 'master' }
        let(:variables) {}

        it 'triggers a pipeline' do
          expect { result }.to change { Ci::Pipeline.count }.by(1)
          expect(result[:pipeline].ref).to eq(ref)
          expect(result[:pipeline].project).to eq(project)
          expect(result[:pipeline].user).to eq(trigger.owner)
          expect(result[:status]).to eq(:success)
        end

        context 'when params have a variable' do
          let(:variables) { { 'AAA' => 'AAA123' } }

          it 'has a variable' do
            expect { result }.to change { Ci::PipelineVariable.count }.by(1)
            expect(result[:pipeline].variables.first.key).to eq(variables.keys.first)
            expect(result[:pipeline].variables.first.value).to eq(variables.values.first)
          end
        end
      end

      context 'when params have a non-existsed ref' do
        let(:ref) { 'invalid-ref' }
        let(:variables) {}

        it 'does not trigger a pipeline' do
          expect { result }.not_to change { Ci::Pipeline.count }
          expect(result[:http_status]).to eq(400)
        end
      end
    end

    context 'when params have a non-existsed trigger token' do
      let(:token) { 'invalid-token' }
      let(:ref) {}
      let(:variables) {}

      it 'does not trigger a pipeline' do
        expect { result }.not_to change { Ci::Pipeline.count }
        expect(result).to be_nil
      end
    end
  end
end