BigW Consortium Gitlab

Commit 45bd5391 by Grzegorz Bizon

Extend tests for service that stops environment

parent ae8a461d
...@@ -7,7 +7,7 @@ describe Ci::StopEnvironmentService, services: true do ...@@ -7,7 +7,7 @@ describe Ci::StopEnvironmentService, services: true do
let(:service) { described_class.new(project, user) } let(:service) { described_class.new(project, user) }
describe '#execute' do describe '#execute' do
context 'when environment exists' do context 'when environment with review app exists' do
before do before do
create(:environment, :with_review_app, project: project) create(:environment, :with_review_app, project: project)
end end
...@@ -17,6 +17,54 @@ describe Ci::StopEnvironmentService, services: true do ...@@ -17,6 +17,54 @@ describe Ci::StopEnvironmentService, services: true do
service.execute('master') service.execute('master')
end end
context 'when specified branch does not exist' do
it 'does not stop environment' do
expect_any_instance_of(Environment).not_to receive(:stop!)
service.execute('non/existent/branch')
end
end
context 'when no branch not specified' do
it 'does not stop environment' do
expect_any_instance_of(Environment).not_to receive(:stop!)
service.execute(nil)
end
end
context 'when environment is not stoppable' do
before do
allow_any_instance_of(Environment)
.to receive(:stoppable?).and_return(false)
end
it 'does not stop environment' do
expect_any_instance_of(Environment).not_to receive(:stop!)
service.execute('master')
end
end
end
context 'when there is no environment associated with review app' do
before do
create(:environment, project: project)
end
it 'does not stop environment' do
expect_any_instance_of(Environment).not_to receive(:stop!)
service.execute('master')
end
end
context 'when environment does not exist' do
it 'does not raise error' do
expect { service.execute('master') }
.not_to raise_error
end
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment