2019-09-30 09:06:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-23 15:10:07 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe BuildDetailsEntity do
|
2017-09-29 08:04:50 +00:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2021-12-13 21:14:32 +00:00
|
|
|
it 'inherits from Ci::JobEntity' do
|
|
|
|
expect(described_class).to be < Ci::JobEntity
|
2017-05-23 15:10:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#as_json' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
2022-01-27 06:11:50 +00:00
|
|
|
let(:user) { project.first_owner }
|
2017-07-19 11:11:39 +00:00
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
let(:build) { create(:ci_build, :failed, pipeline: pipeline) }
|
2020-04-14 03:09:39 +00:00
|
|
|
let(:request) { double('request', project: project) }
|
2017-07-19 11:11:39 +00:00
|
|
|
|
|
|
|
let(:entity) do
|
|
|
|
described_class.new(build, request: request,
|
|
|
|
current_user: user,
|
|
|
|
project: project)
|
|
|
|
end
|
|
|
|
|
2017-05-23 15:10:07 +00:00
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
2017-07-19 11:11:39 +00:00
|
|
|
it 'contains the needed key value pairs' do
|
2021-12-14 15:17:06 +00:00
|
|
|
expect(subject).to include(:coverage, :erased_at, :finished_at, :duration)
|
2017-07-19 11:11:39 +00:00
|
|
|
expect(subject).to include(:runner, :pipeline)
|
|
|
|
expect(subject).to include(:raw_path, :new_issue_path)
|
|
|
|
end
|
|
|
|
|
2017-05-23 15:10:07 +00:00
|
|
|
context 'when the user has access to issues and merge requests' do
|
2017-07-19 11:11:39 +00:00
|
|
|
context 'when merge request orginates from the same project' do
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project, source_branch: build.ref)
|
|
|
|
end
|
2017-05-26 08:31:42 +00:00
|
|
|
|
2017-07-19 11:11:39 +00:00
|
|
|
before do
|
|
|
|
allow(build).to receive(:merge_request).and_return(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the needed key value pairs' do
|
|
|
|
expect(subject).to include(:merge_request)
|
|
|
|
expect(subject).to include(:new_issue_path)
|
|
|
|
end
|
|
|
|
|
2017-07-20 07:18:45 +00:00
|
|
|
it 'exposes correct details of the merge request' do
|
|
|
|
expect(subject[:merge_request][:iid]).to eq merge_request.iid
|
2017-07-19 11:11:39 +00:00
|
|
|
end
|
2017-05-23 15:10:07 +00:00
|
|
|
|
2017-07-19 11:11:39 +00:00
|
|
|
it 'has a correct merge request path' do
|
|
|
|
expect(subject[:merge_request][:path]).to include project.full_path
|
|
|
|
end
|
2017-05-29 07:58:20 +00:00
|
|
|
end
|
|
|
|
|
2017-07-19 11:11:39 +00:00
|
|
|
context 'when merge request is from a fork' do
|
2017-09-29 08:04:50 +00:00
|
|
|
let(:forked_project) { fork_project(project) }
|
2017-07-19 11:11:39 +00:00
|
|
|
|
2017-09-29 08:04:50 +00:00
|
|
|
let(:pipeline) { create(:ci_pipeline, project: forked_project) }
|
2017-07-19 11:11:39 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(build).to receive(:merge_request).and_return(merge_request)
|
2021-01-08 15:10:26 +00:00
|
|
|
forked_project.add_developer(user)
|
2017-07-19 11:11:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:merge_request) do
|
2017-09-29 08:04:50 +00:00
|
|
|
create(:merge_request, source_project: forked_project,
|
2017-07-19 11:11:39 +00:00
|
|
|
target_project: project,
|
|
|
|
source_branch: build.ref)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the needed key value pairs' do
|
|
|
|
expect(subject).to include(:merge_request)
|
|
|
|
expect(subject).to include(:new_issue_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes details of the merge request' do
|
2017-07-20 07:18:45 +00:00
|
|
|
expect(subject[:merge_request][:iid]).to eq merge_request.iid
|
2017-07-19 11:11:39 +00:00
|
|
|
end
|
|
|
|
|
2017-07-21 11:09:13 +00:00
|
|
|
it 'has a merge request path to a target project' do
|
2017-07-19 11:11:39 +00:00
|
|
|
expect(subject[:merge_request][:path])
|
2017-07-21 11:09:13 +00:00
|
|
|
.to include project.full_path
|
2017-07-19 11:11:39 +00:00
|
|
|
end
|
2017-05-29 07:58:20 +00:00
|
|
|
end
|
|
|
|
|
2017-07-20 09:42:13 +00:00
|
|
|
context 'when the build has not been erased' do
|
|
|
|
let(:build) { create(:ci_build, :erasable, project: project) }
|
2017-05-29 07:58:20 +00:00
|
|
|
|
2017-07-20 09:42:13 +00:00
|
|
|
it 'exposes a build erase path' do
|
2017-05-29 07:58:20 +00:00
|
|
|
expect(subject).to include(:erase_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the build has been erased' do
|
2017-07-20 09:42:13 +00:00
|
|
|
let(:build) { create(:ci_build, :erased, project: project) }
|
2017-05-29 07:58:20 +00:00
|
|
|
|
2017-07-20 09:42:13 +00:00
|
|
|
it 'exposes the user who erased the build' do
|
2017-05-29 07:58:20 +00:00
|
|
|
expect(subject).to include(:erased_by)
|
|
|
|
end
|
2017-05-23 15:10:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user can only read the build' do
|
2017-05-26 08:31:42 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2017-05-23 15:10:07 +00:00
|
|
|
it "won't display the paths to issues and merge requests" do
|
|
|
|
expect(subject['new_issue_path']).to be_nil
|
|
|
|
expect(subject['merge_request_path']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-03-27 04:01:35 +00:00
|
|
|
|
|
|
|
context 'when the build has failed' do
|
|
|
|
let(:build) { create(:ci_build, :created) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
build.drop!(:unmet_prerequisites)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(failure_reason: 'unmet_prerequisites') }
|
2019-10-17 18:08:05 +00:00
|
|
|
it { is_expected.to include(callout_message: CommitStatusPresenter.callout_failure_messages[:unmet_prerequisites]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the build has failed due to a missing dependency' do
|
|
|
|
let!(:test1) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test1', stage_idx: 0) }
|
|
|
|
let!(:test2) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test2', stage_idx: 1) }
|
|
|
|
let!(:build) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) }
|
|
|
|
let(:message) { subject[:callout_message] }
|
|
|
|
|
|
|
|
before do
|
2021-08-12 15:09:58 +00:00
|
|
|
build.pipeline.unlocked!
|
2019-10-17 18:08:05 +00:00
|
|
|
build.drop!(:missing_dependency_failure)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(failure_reason: 'missing_dependency_failure') }
|
|
|
|
|
|
|
|
it 'includes the failing dependencies in the callout message' do
|
2019-10-18 12:06:56 +00:00
|
|
|
expect(message).to include('test1')
|
|
|
|
expect(message).to include('test2')
|
2019-10-17 18:08:05 +00:00
|
|
|
end
|
2019-03-27 04:01:35 +00:00
|
|
|
end
|
2019-05-06 13:20:20 +00:00
|
|
|
|
|
|
|
context 'when a build has environment with latest deployment' do
|
|
|
|
let(:build) do
|
|
|
|
create(:ci_build, :running, environment: environment.name, pipeline: pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:environment) do
|
|
|
|
create(:environment, project: project, name: 'staging', state: :available)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:deployment, :success, environment: environment, project: project)
|
|
|
|
|
|
|
|
allow(request).to receive(:project).and_return(project)
|
|
|
|
end
|
|
|
|
|
2019-05-06 15:30:57 +00:00
|
|
|
it 'does not serialize latest deployment commit and associated builds' do
|
2019-05-06 13:20:20 +00:00
|
|
|
response = subject.with_indifferent_access
|
|
|
|
|
|
|
|
response.dig(:deployment_status, :environment, :last_deployment).tap do |deployment|
|
2019-05-10 17:02:00 +00:00
|
|
|
expect(deployment).not_to include(:commit, :manual_actions, :scheduled_actions)
|
2019-05-06 13:20:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-05-01 22:29:15 +00:00
|
|
|
|
|
|
|
context 'when the build has reports' do
|
|
|
|
let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
|
|
|
|
|
|
|
|
it 'exposes the report artifacts' do
|
2019-05-25 00:08:53 +00:00
|
|
|
expect(subject[:reports].count).to eq(1)
|
|
|
|
expect(subject[:reports].first[:file_type]).to eq('codequality')
|
2019-05-01 22:29:15 +00:00
|
|
|
end
|
|
|
|
end
|
2020-02-03 21:09:00 +00:00
|
|
|
|
|
|
|
context 'when the build has no archive type artifacts' do
|
|
|
|
let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
|
|
|
|
|
|
|
|
it 'does not expose any artifact actions path' do
|
|
|
|
expect(subject[:artifact].keys).not_to include(:download_path, :browse_path, :keep_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-11 18:10:06 +00:00
|
|
|
context 'when the build has expired artifacts' do
|
2021-01-08 15:10:26 +00:00
|
|
|
let!(:build) { create(:ci_build, :artifacts, pipeline: pipeline, artifacts_expire_at: 7.days.ago) }
|
2020-08-11 18:10:06 +00:00
|
|
|
|
2020-09-01 18:10:48 +00:00
|
|
|
context 'when pipeline is unlocked' do
|
|
|
|
before do
|
|
|
|
build.pipeline.unlocked!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'artifact locked is false' do
|
|
|
|
expect(subject.dig(:artifact, :locked)).to eq(false)
|
|
|
|
end
|
2020-08-11 18:10:06 +00:00
|
|
|
|
2020-09-01 18:10:48 +00:00
|
|
|
it 'does not expose any artifact actions path' do
|
|
|
|
expect(subject[:artifact].keys).not_to include(:download_path, :browse_path, :keep_path)
|
|
|
|
end
|
2020-08-11 18:10:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the pipeline is artifacts_locked' do
|
|
|
|
before do
|
2020-09-01 18:10:48 +00:00
|
|
|
build.pipeline.artifacts_locked!
|
2020-08-11 18:10:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'artifact locked is true' do
|
|
|
|
expect(subject.dig(:artifact, :locked)).to eq(true)
|
|
|
|
end
|
|
|
|
|
2020-09-01 18:10:48 +00:00
|
|
|
it 'exposes download, browse and keep artifact actions path' do
|
|
|
|
expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path)
|
2020-08-11 18:10:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-03 21:09:00 +00:00
|
|
|
context 'when the build has archive type artifacts' do
|
2021-01-08 15:10:26 +00:00
|
|
|
let!(:build) { create(:ci_build, :artifacts, pipeline: pipeline, artifacts_expire_at: 7.days.from_now) }
|
2020-02-03 21:09:00 +00:00
|
|
|
let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
|
|
|
|
|
|
|
|
it 'exposes artifact details' do
|
2020-08-11 18:10:06 +00:00
|
|
|
expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path, :expire_at, :expired, :locked)
|
2020-02-03 21:09:00 +00:00
|
|
|
end
|
|
|
|
end
|
2020-12-21 00:10:18 +00:00
|
|
|
|
|
|
|
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
|
2017-05-23 15:10:07 +00:00
|
|
|
end
|
|
|
|
end
|