2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::DataBuilder::Deployment do
|
2019-07-31 22:56:46 +05:30
|
|
|
describe '.build' do
|
|
|
|
it 'returns the object kind for a deployment' do
|
2020-11-24 15:15:51 +05:30
|
|
|
deployment = build(:deployment, deployable: nil, environment: create(:environment))
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
data = described_class.build(deployment, 'success', Time.current)
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
expect(data[:object_kind]).to eq('deployment')
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it 'returns data for the given build', :aggregate_failures do
|
|
|
|
environment = create(:environment, name: 'somewhere/1', external_url: 'https://test.com')
|
2019-07-31 22:56:46 +05:30
|
|
|
project = create(:project, :repository, name: 'myproj')
|
|
|
|
commit = project.commit('HEAD')
|
|
|
|
deployment = create(:deployment, status: :failed, environment: environment, sha: commit.sha, project: project)
|
|
|
|
deployable = deployment.deployable
|
|
|
|
expected_deployable_url = Gitlab::Routing.url_helpers.project_job_url(deployable.project, deployable)
|
2021-01-03 14:25:43 +05:30
|
|
|
expected_user_url = Gitlab::Routing.url_helpers.user_url(deployment.deployed_by)
|
2019-07-31 22:56:46 +05:30
|
|
|
expected_commit_url = Gitlab::UrlBuilder.build(commit)
|
2021-06-08 01:23:25 +05:30
|
|
|
status_changed_at = Time.current
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
data = described_class.build(deployment, 'failed', status_changed_at)
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
expect(data[:status]).to eq('failed')
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(data[:status_changed_at]).to eq(status_changed_at)
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(data[:deployment_id]).to eq(deployment.id)
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(data[:deployable_id]).to eq(deployable.id)
|
|
|
|
expect(data[:deployable_url]).to eq(expected_deployable_url)
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(data[:environment]).to eq('somewhere/1')
|
|
|
|
expect(data[:environment_slug]).to eq('somewhere-1-78avk6')
|
|
|
|
expect(data[:environment_external_url]).to eq('https://test.com')
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(data[:project]).to eq(project.hook_attrs)
|
|
|
|
expect(data[:short_sha]).to eq(deployment.short_sha)
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(data[:user]).to eq(deployment.deployed_by.hook_attrs)
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(data[:user_url]).to eq(expected_user_url)
|
|
|
|
expect(data[:commit_url]).to eq(expected_commit_url)
|
|
|
|
expect(data[:commit_title]).to eq(commit.title)
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(data[:ref]).to eq(deployment.ref)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
it 'does not include the deployable URL when there is no deployable' do
|
|
|
|
deployment = create(:deployment, status: :failed, deployable: nil)
|
2022-08-13 15:12:31 +05:30
|
|
|
data = described_class.build(deployment, 'failed', Time.current)
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
expect(data[:deployable_url]).to be_nil
|
|
|
|
end
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
context 'when commit does not exist in the repository' do
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:deployment) { create(:deployment, project: project) }
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
subject(:data) { described_class.build(deployment, 'created', Time.current) }
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
project.repository.remove
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for commit_url' do
|
|
|
|
expect(data[:commit_url]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for commit_title' do
|
|
|
|
expect(data[:commit_title]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when deployed_by is nil' do
|
|
|
|
let_it_be(:deployment) { create(:deployment, user: nil, deployable: nil) }
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
subject(:data) { described_class.build(deployment, 'created', Time.current) }
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
deployment.user = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for user' do
|
|
|
|
expect(data[:user]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for user_url' do
|
|
|
|
expect(data[:user_url]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|