build_entity_spec.rb 1.27 KB
Newer Older
1 2 3
require 'spec_helper'

describe BuildEntity do
4
  let(:user) { create(:user) }
5
  let(:build) { create(:ci_build) }
6 7 8
  let(:request) { double('request') }

  before do
9
    allow(request).to receive(:current_user).and_return(user)
10
  end
11

12
  let(:entity) do
13
    described_class.new(build, request: request)
14 15
  end

16 17
  subject { entity.as_json }

18 19 20
  it 'contains paths to build page and retry action' do
    expect(subject).to include(:build_path, :retry_path)
  end
21

22 23 24 25 26
  it 'does not contain sensitive information' do
    expect(subject).not_to include(/token/)
    expect(subject).not_to include(/variables/)
  end

27 28 29 30
  it 'contains whether it is playable' do
    expect(subject[:playable]).to eq build.playable?
  end

31 32 33
  it 'contains timestamps' do
    expect(subject).to include(:created_at, :updated_at)
  end
34

35
  it 'contains details' do
36 37
    expect(subject).to include :status
    expect(subject[:status]).to include :icon, :favicon, :text, :label
38 39
  end

40 41 42
  context 'when build is a regular job' do
    it 'does not contain path to play action' do
      expect(subject).not_to include(:play_path)
43
    end
44 45 46 47 48
  end

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

49 50
    it 'contains path to play action' do
      expect(subject).to include(:play_path)
51 52 53
    end
  end
end