2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-04 08:23:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe EnvironmentEntity do
|
2018-07-10 04:11:04 -04:00
|
|
|
let(:request) { double('request') }
|
2016-11-04 08:23:06 -04:00
|
|
|
let(:entity) do
|
2018-07-10 04:11:04 -04:00
|
|
|
described_class.new(environment, request: spy('request'))
|
2016-11-04 08:23:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:environment) { create(:environment) }
|
2019-12-17 13:07:48 -05:00
|
|
|
|
2016-11-04 08:23:06 -04:00
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
it 'exposes latest deployment' do
|
|
|
|
expect(subject).to include(:last_deployment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes core elements of environment' do
|
2016-11-17 10:08:05 -05:00
|
|
|
expect(subject).to include(:id, :name, :state, :environment_path)
|
2016-11-04 08:23:06 -04:00
|
|
|
end
|
2017-03-31 05:20:11 -04:00
|
|
|
|
2017-08-21 11:46:45 -04:00
|
|
|
it 'exposes folder path' do
|
|
|
|
expect(subject).to include(:folder_path)
|
|
|
|
end
|
|
|
|
|
2017-03-31 05:20:11 -04:00
|
|
|
context 'metrics disabled' do
|
|
|
|
before do
|
|
|
|
allow(environment).to receive(:has_metrics?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't expose metrics path" do
|
|
|
|
expect(subject).not_to include(:metrics_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'metrics enabled' do
|
|
|
|
before do
|
|
|
|
allow(environment).to receive(:has_metrics?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes metrics path' do
|
|
|
|
expect(subject).to include(:metrics_path)
|
|
|
|
end
|
|
|
|
end
|
2018-12-20 04:39:09 -05:00
|
|
|
|
|
|
|
context 'with deployment platform' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:environment) { create(:environment, project: project) }
|
|
|
|
|
|
|
|
context 'when deployment platform is a cluster' do
|
|
|
|
before do
|
|
|
|
create(:cluster,
|
|
|
|
:provided_by_gcp,
|
|
|
|
:project,
|
|
|
|
environment_scope: '*',
|
|
|
|
projects: [project])
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'includes cluster_type' do
|
2018-12-20 04:39:09 -05:00
|
|
|
expect(subject).to include(:cluster_type)
|
|
|
|
expect(subject[:cluster_type]).to eq('project_type')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-10 02:53:40 -05:00
|
|
|
|
|
|
|
context 'with auto_stop_in' do
|
|
|
|
let(:environment) { create(:environment, :will_auto_stop) }
|
|
|
|
|
|
|
|
it 'exposes auto stop related information' do
|
|
|
|
expect(subject).to include(:cancel_auto_stop_path, :auto_stop_at)
|
|
|
|
end
|
|
|
|
end
|
2016-11-04 08:23:06 -04:00
|
|
|
end
|