summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/status/build/manual_spec.rb
blob: 8f5d155831454ffd3d5eaff40e65ae8e6469d988 (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
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Status::Build::Manual, feature_category: :continuous_integration do
  let_it_be(:user) { create(:user) }
  let_it_be(:job) { create(:ci_build, :manual) }

  subject do
    described_class.new(Gitlab::Ci::Status::Core.new(job, user))
  end

  describe '#illustration' do
    it { expect(subject.illustration).to include(:image, :size, :title, :content) }

    context 'when the user can trigger the job' do
      before do
        job.project.add_maintainer(user)
      end

      context 'when the job has not been played' do
        it 'instructs the user about possible actions' do
          expect(subject.illustration[:content]).to eq(
            _(
              'This job does not start automatically and must be started manually. ' \
              'You can add CI/CD variables below for last-minute configuration changes before starting the job.'
            )
          )
        end
      end

      context 'when the job is retryable' do
        before do
          job.update!(status: :failed)
        end

        it 'instructs the user about possible actions' do
          expect(subject.illustration[:content]).to eq(
            _("You can modify this job's CI/CD variables before running it again.")
          )
        end
      end
    end

    context 'when the user can not trigger the job because of outdated deployment' do
      before do
        allow(job).to receive(:outdated_deployment?).and_return(true)
      end

      it { expect(subject.illustration[:content]).to match /This deployment job does not run automatically and must be started manually, but it's older than the latest deployment, and therefore can't run/ }
    end

    context 'when the user can not trigger the job due to another reason' do
      it 'informs the user' do
        expect(subject.illustration[:content]).to eq(
          _("This job does not run automatically and must be started manually, but you do not have access to it.")
        )
      end
    end
  end

  describe '.matches?' do
    subject { described_class.matches?(build, user) }

    context 'when build is manual' do
      let(:build) { create(:ci_build, :manual) }

      it 'is a correct match' do
        expect(subject).to be true
      end
    end

    context 'when build is not manual' do
      let(:build) { create(:ci_build) }

      it 'does not match' do
        expect(subject).to be false
      end
    end
  end
end