diff options
Diffstat (limited to 'spec/features')
3 files changed, 191 insertions, 10 deletions
diff --git a/spec/features/merge_request/user_sees_deployment_widget_spec.rb b/spec/features/merge_request/user_sees_deployment_widget_spec.rb index 0e439c8cb2d..53598b10fb1 100644 --- a/spec/features/merge_request/user_sees_deployment_widget_spec.rb +++ b/spec/features/merge_request/user_sees_deployment_widget_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'Merge request > User sees deployment widget', :js do - describe 'when deployed to an environment' do + describe 'when merge request has associated environments' do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:merge_request) { create(:merge_request, :merged, source_project: project) } @@ -10,30 +10,126 @@ describe 'Merge request > User sees deployment widget', :js do let(:ref) { merge_request.target_branch } let(:sha) { project.commit(ref).id } let(:pipeline) { create(:ci_pipeline_without_jobs, sha: sha, project: project, ref: ref) } - let(:build) { create(:ci_build, :success, pipeline: pipeline) } - let!(:deployment) { create(:deployment, :succeed, environment: environment, sha: sha, ref: ref, deployable: build) } let!(:manual) { } before do merge_request.update!(merge_commit_sha: sha) project.add_user(user, role) sign_in(user) - visit project_merge_request_path(project, merge_request) - wait_for_requests end - it 'displays that the environment is deployed' do - wait_for_requests + context 'when deployment is to start an environment' do + context 'when deployment succeeded' do + let(:build) { create(:ci_build, :success, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :succeed, environment: environment, sha: sha, ref: ref, deployable: build) } - expect(page).to have_content("Deployed to #{environment.name}") - expect(find('.js-deploy-time')['data-original-title']).to eq(deployment.created_at.to_time.in_time_zone.to_s(:medium)) + it 'displays that the environment is deployed' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).to have_content("Deployed to #{environment.name}") + expect(find('.js-deploy-time')['data-original-title']).to eq(deployment.created_at.to_time.in_time_zone.to_s(:medium)) + end + end + + context 'when deployment failed' do + let(:build) { create(:ci_build, :failed, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :failed, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'displays that the deployment failed' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).to have_content("Failed to deploy to #{environment.name}") + expect(page).not_to have_css('.js-deploy-time') + end + end + + context 'when deployment running' do + let(:build) { create(:ci_build, :running, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :running, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'displays that the running deployment' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).to have_content("Deploying to #{environment.name}") + expect(page).not_to have_css('.js-deploy-time') + end + end + + context 'when deployment will happen' do + let(:build) { create(:ci_build, :created, pipeline: pipeline) } + let!(:deployment) { create(:deployment, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'displays that the environment name' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).to have_content("Deploying to #{environment.name}") + expect(page).not_to have_css('.js-deploy-time') + end + end + end + + context 'when deployment is to stop an environment' do + context 'when the stop action succeeded' do + let(:build) { create(:ci_build, :success, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :succeed, :stop, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'does not display deployment info' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).not_to have_css('.deployment-info') + end + end + + context 'when the stop action failed' do + let(:build) { create(:ci_build, :failed, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :failed, :stop, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'does not display deployment info' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).not_to have_css('.deployment-info') + end + end + + context 'when the stop action is running' do + let(:build) { create(:ci_build, :running, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :running, :stop, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'does not display deployment info' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).not_to have_css('.deployment-info') + end + end + + context 'when the stop action will happen' do + let(:build) { create(:ci_build, :created, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :stop, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'does not display deployment info' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).not_to have_css('.deployment-info') + end + end end context 'with stop action' do + let(:build) { create(:ci_build, :success, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :succeed, environment: environment, sha: sha, ref: ref, deployable: build) } let(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') } before do deployment.update!(on_stop: manual.name) + visit project_merge_request_path(project, merge_request) wait_for_requests end diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb index 056f4ee2e22..d12fe24714b 100644 --- a/spec/features/projects/environments/environment_spec.rb +++ b/spec/features/projects/environments/environment_spec.rb @@ -43,6 +43,58 @@ describe 'Environment' do end end + context 'when there is a successful deployment' do + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:build) { create(:ci_build, :success, pipeline: pipeline) } + + let(:deployment) do + create(:deployment, :success, environment: environment, deployable: build) + end + + it 'does show deployments' do + expect(page).to have_link("#{build.name} (##{build.id})") + end + end + + context 'when there is a running deployment' do + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:build) { create(:ci_build, pipeline: pipeline) } + + let(:deployment) do + create(:deployment, :running, environment: environment, deployable: build) + end + + it 'does show no deployments' do + expect(page).to have_content('You don\'t have any deployments right now.') + end + end + + context 'when there is a failed deployment' do + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:build) { create(:ci_build, pipeline: pipeline) } + + let(:deployment) do + create(:deployment, :failed, environment: environment, deployable: build) + end + + it 'does show no deployments' do + expect(page).to have_content('You don\'t have any deployments right now.') + end + end + + context 'when there is a successful stop action' do + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:build) { create(:ci_build, :success, pipeline: pipeline) } + + let(:deployment) do + create(:deployment, :success, :stop, environment: environment, deployable: build) + end + + it 'does show no deployments' do + expect(page).to have_content('You don\'t have any deployments right now.') + end + end + context 'with related deployable present' do let(:pipeline) { create(:ci_pipeline, project: project) } let(:build) { create(:ci_build, pipeline: pipeline) } diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb index d0ddf69d574..b3eabcb7903 100644 --- a/spec/features/projects/environments/environments_spec.rb +++ b/spec/features/projects/environments/environments_spec.rb @@ -128,7 +128,7 @@ describe 'Environments page', :js do end end - context 'when there are deployments' do + context 'when there are successful deployments' do let(:project) { create(:project, :repository) } let!(:deployment) do @@ -328,6 +328,39 @@ describe 'Environments page', :js do end end end + + context 'when there is a failed deployment' do + let(:project) { create(:project, :repository) } + + let!(:deployment) do + create(:deployment, :failed, + environment: environment, + sha: project.commit.id) + end + + it 'does not show deployments' do + visit_environments(project) + + expect(page).to have_content('No deployments yet') + end + end + + context 'when there is a successful stop action' do + let(:project) { create(:project, :repository) } + + let!(:deployment) do + create(:deployment, :success, + :stop, + environment: environment, + sha: project.commit.id) + end + + it 'does not show deployments' do + visit_environments(project) + + expect(page).to have_content('No deployments yet') + end + end end it 'does have a new environment button' do |