2019-10-16 14:08:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe Deployments::CreateService do
|
2019-12-14 10:07:56 -05:00
|
|
|
let(:user) { create(:user) }
|
2019-10-16 14:08:01 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
2019-12-14 10:07:56 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:environment) { create(:environment, project: project) }
|
2019-10-16 14:08:01 -04:00
|
|
|
|
2019-12-14 10:07:56 -05:00
|
|
|
it 'creates a deployment' do
|
|
|
|
service = described_class.new(
|
|
|
|
environment,
|
|
|
|
user,
|
|
|
|
sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0',
|
|
|
|
ref: 'master',
|
|
|
|
tag: false,
|
|
|
|
status: 'success'
|
|
|
|
)
|
2019-10-16 14:08:01 -04:00
|
|
|
|
2020-10-05 02:08:45 -04:00
|
|
|
expect(Deployments::UpdateEnvironmentWorker).to receive(:perform_async)
|
|
|
|
expect(Deployments::LinkMergeRequestWorker).to receive(:perform_async)
|
|
|
|
expect(Deployments::ExecuteHooksWorker).to receive(:perform_async)
|
2019-10-16 14:08:01 -04:00
|
|
|
|
2019-12-14 10:07:56 -05:00
|
|
|
expect(service.execute).to be_persisted
|
2019-10-16 14:08:01 -04:00
|
|
|
end
|
|
|
|
|
2019-12-14 10:07:56 -05:00
|
|
|
it 'does not change the status if no status is given' do
|
|
|
|
service = described_class.new(
|
|
|
|
environment,
|
|
|
|
user,
|
|
|
|
sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0',
|
|
|
|
ref: 'master',
|
|
|
|
tag: false
|
|
|
|
)
|
2019-10-16 14:08:01 -04:00
|
|
|
|
2020-10-05 02:08:45 -04:00
|
|
|
expect(Deployments::UpdateEnvironmentWorker).not_to receive(:perform_async)
|
|
|
|
expect(Deployments::LinkMergeRequestWorker).not_to receive(:perform_async)
|
|
|
|
expect(Deployments::ExecuteHooksWorker).not_to receive(:perform_async)
|
2019-10-16 14:08:01 -04:00
|
|
|
|
2019-12-14 10:07:56 -05:00
|
|
|
expect(service.execute).to be_persisted
|
2019-10-16 14:08:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-14 10:07:56 -05:00
|
|
|
describe '#deployment_attributes' do
|
|
|
|
let(:environment) do
|
|
|
|
double(
|
|
|
|
:environment,
|
|
|
|
deployment_platform: double(:platform, cluster_id: 1),
|
|
|
|
project_id: 2,
|
|
|
|
id: 3
|
|
|
|
)
|
2019-10-16 14:08:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'only includes attributes that we want to persist' do
|
|
|
|
service = described_class.new(
|
|
|
|
environment,
|
|
|
|
user,
|
|
|
|
ref: 'master',
|
|
|
|
tag: true,
|
|
|
|
sha: '123',
|
|
|
|
foo: 'bar',
|
2019-12-14 10:07:56 -05:00
|
|
|
on_stop: 'stop'
|
2019-10-16 14:08:01 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(service.deployment_attributes).to eq(
|
|
|
|
cluster_id: 1,
|
|
|
|
project_id: 2,
|
|
|
|
environment_id: 3,
|
|
|
|
ref: 'master',
|
|
|
|
tag: true,
|
|
|
|
sha: '123',
|
|
|
|
user: user,
|
2019-12-14 10:07:56 -05:00
|
|
|
on_stop: 'stop'
|
2019-10-16 14:08:01 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|