diff options
Diffstat (limited to 'spec/serializers/build_details_entity_spec.rb')
-rw-r--r-- | spec/serializers/build_details_entity_spec.rb | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb index 5d29452e91c..4a58f341658 100644 --- a/spec/serializers/build_details_entity_spec.rb +++ b/spec/serializers/build_details_entity_spec.rb @@ -5,14 +5,13 @@ require 'spec_helper' RSpec.describe BuildDetailsEntity do include ProjectForksHelper - let_it_be(:user) { create(:admin) } - it 'inherits from JobEntity' do expect(described_class).to be < JobEntity end describe '#as_json' do let(:project) { create(:project, :repository) } + let(:user) { project.owner } let(:pipeline) { create(:ci_pipeline, project: project) } let(:build) { create(:ci_build, :failed, pipeline: pipeline) } let(:request) { double('request', project: project) } @@ -66,6 +65,7 @@ RSpec.describe BuildDetailsEntity do before do allow(build).to receive(:merge_request).and_return(merge_request) + forked_project.add_developer(user) end let(:merge_request) do @@ -186,7 +186,7 @@ RSpec.describe BuildDetailsEntity do end context 'when the build has expired artifacts' do - let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: 7.days.ago) } + let!(:build) { create(:ci_build, :artifacts, pipeline: pipeline, artifacts_expire_at: 7.days.ago) } context 'when pipeline is unlocked' do before do @@ -218,12 +218,43 @@ RSpec.describe BuildDetailsEntity do end context 'when the build has archive type artifacts' do - let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: 7.days.from_now) } + let!(:build) { create(:ci_build, :artifacts, pipeline: pipeline, artifacts_expire_at: 7.days.from_now) } let!(:report) { create(:ci_job_artifact, :codequality, job: build) } it 'exposes artifact details' do expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path, :expire_at, :expired, :locked) end end + + context 'when the project is public and the user is a guest' do + let(:project) { create(:project, :repository, :public) } + let(:user) { create(:project_member, :guest, project: project).user } + + context 'when the build has public archive type artifacts' do + let(:build) { create(:ci_build, :artifacts) } + + it 'exposes public artifact details' do + expect(subject[:artifact].keys).to include(:download_path, :browse_path, :locked) + end + end + + context 'when the build has non public archive type artifacts' do + let(:build) { create(:ci_build, :artifacts, :non_public_artifacts, pipeline: pipeline) } + + it 'does not expose non public artifacts' do + expect(subject.keys).not_to include(:artifact) + end + + context 'with the non_public_artifacts feature flag disabled' do + before do + stub_feature_flags(non_public_artifacts: false) + end + + it 'exposes artifact details' do + expect(subject[:artifact].keys).to include(:download_path, :browse_path, :locked) + end + end + end + end end end |