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
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
data = described_class.build(deployment, Time.current)
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
expect(data[:object_kind]).to eq('deployment')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns data for the given build' do
|
|
|
|
environment = create(:environment, name: "somewhere")
|
|
|
|
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
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
data = described_class.build(deployment, 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)
|
|
|
|
expect(data[:environment]).to eq("somewhere")
|
|
|
|
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)
|
|
|
|
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)
|
2021-06-08 01:23:25 +05:30
|
|
|
data = described_class.build(deployment, Time.current)
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
expect(data[:deployable_url]).to be_nil
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|