deployment_entity_spec.rb 2.47 KB
Newer Older
1 2
require 'spec_helper'

3
describe DeploymentEntity do
4 5 6 7
  let(:user) { developer }
  let(:developer) { create(:user) }
  let(:reporter) { create(:user) }
  let(:project) { create(:project) }
8
  let(:request) { double('request') }
9 10 11
  let(:deployment) { create(:deployment, deployable: build, project: project) }
  let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
  let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
12 13
  let(:entity) { described_class.new(deployment, request: request) }
  subject { entity.as_json }
14 15

  before do
16 17
    project.add_developer(developer)
    project.add_reporter(reporter)
Fatih Acet's avatar
Fatih Acet committed
18
    allow(request).to receive(:current_user).and_return(user)
19
    allow(request).to receive(:project).and_return(project)
20
  end
Shinya Maeda's avatar
Shinya Maeda committed
21

22
  it 'exposes internal deployment id' do
23 24 25 26 27 28
    expect(subject).to include(:iid)
  end

  it 'exposes nested information about branch' do
    expect(subject[:ref][:name]).to eq 'master'
  end
29 30 31 32

  it 'exposes creation date' do
    expect(subject).to include(:created_at)
  end
Shinya Maeda's avatar
Shinya Maeda committed
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  context 'when the pipeline has another manual action' do
    let(:other_build) { create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline) }
    let!(:other_deployment) { create(:deployment, deployable: other_build) }

    it 'returns another manual action' do
      expect(subject[:manual_actions].count).to eq(1)
      expect(subject[:manual_actions].first[:name]).to eq('another deploy')
    end

    context 'when user is a reporter' do
      let(:user) { reporter }

      it 'returns another manual action' do
        expect(subject[:manual_actions]).not_to be_present
      end
    end
  end

Shinya Maeda's avatar
Shinya Maeda committed
52 53 54 55 56 57
  describe 'scheduled_actions' do
    let(:project) { create(:project, :repository) }
    let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
    let(:build) { create(:ci_build, :success, pipeline: pipeline) }
    let(:deployment) { create(:deployment, deployable: build) }

58 59
    context 'when the same pipeline has a scheduled action' do
      let(:other_build) { create(:ci_build, :schedulable, :success, pipeline: pipeline, name: 'other build') }
Shinya Maeda's avatar
Shinya Maeda committed
60 61
      let!(:other_deployment) { create(:deployment, deployable: other_build) }

62
      it 'returns other scheduled actions' do
Shinya Maeda's avatar
Shinya Maeda committed
63 64 65 66
        expect(subject[:scheduled_actions][0][:name]).to eq 'other build'
      end
    end

67
    context 'when the same pipeline does not have a scheduled action' do
Shinya Maeda's avatar
Shinya Maeda committed
68 69 70 71 72
      it 'does not return other actions' do
        expect(subject[:scheduled_actions]).to be_empty
      end
    end
  end
73
end