diff --git a/spec/requests/projects/google_cloud/databases_controller_spec.rb b/spec/requests/projects/google_cloud/databases_controller_spec.rb index e91a51ce2efbc0aecfd1fe71f6f6f290e23222ae..98e8361060059ce5c7eec4b01a58da06982dd476 100644 --- a/spec/requests/projects/google_cloud/databases_controller_spec.rb +++ b/spec/requests/projects/google_cloud/databases_controller_spec.rb @@ -94,23 +94,33 @@ post project_google_cloud_databases_path(project) end - it 'calls EnableCloudsqlService and redirects on error' do - expect_next_instance_of(::GoogleCloud::EnableCloudsqlService) do |service| - expect(service).to receive(:execute) - .and_return({ status: :error, message: 'error' }) + context 'when EnableCloudsqlService fails' do + before do + allow_next_instance_of(::GoogleCloud::EnableCloudsqlService) do |service| + allow(service).to receive(:execute) + .and_return({ status: :error, message: 'error' }) + end end - subject + it 'redirects and track event on error' do + subject + + expect(response).to redirect_to(project_google_cloud_databases_path(project)) + + expect_snowplow_event( + category: 'Projects::GoogleCloud::DatabasesController', + action: 'error_enable_cloudsql_services', + label: nil, + project: project, + user: user + ) + end - expect(response).to redirect_to(project_google_cloud_databases_path(project)) + it 'shows a flash alert' do + subject - expect_snowplow_event( - category: 'Projects::GoogleCloud::DatabasesController', - action: 'error_enable_cloudsql_services', - label: nil, - project: project, - user: user - ) + expect(flash[:alert]).to eq(s_('CloudSeed|Google Cloud Error - error')) + end end context 'when EnableCloudsqlService is successful' do @@ -121,23 +131,33 @@ end end - it 'calls CreateCloudsqlInstanceService and redirects on error' do - expect_next_instance_of(::GoogleCloud::CreateCloudsqlInstanceService) do |service| - expect(service).to receive(:execute) - .and_return({ status: :error, message: 'error' }) + context 'when CreateCloudsqlInstanceService fails' do + before do + allow_next_instance_of(::GoogleCloud::CreateCloudsqlInstanceService) do |service| + allow(service).to receive(:execute) + .and_return({ status: :error, message: 'error' }) + end end - subject + it 'redirects and track event on error' do + subject - expect(response).to redirect_to(project_google_cloud_databases_path(project)) + expect(response).to redirect_to(project_google_cloud_databases_path(project)) - expect_snowplow_event( - category: 'Projects::GoogleCloud::DatabasesController', - action: 'error_create_cloudsql_instance', - label: nil, - project: project, - user: user - ) + expect_snowplow_event( + category: 'Projects::GoogleCloud::DatabasesController', + action: 'error_create_cloudsql_instance', + label: nil, + project: project, + user: user + ) + end + + it 'shows a flash warning' do + subject + + expect(flash[:warning]).to eq(s_('CloudSeed|Google Cloud Error - error')) + end end context 'when CreateCloudsqlInstanceService is successful' do @@ -161,6 +181,18 @@ user: user ) end + + it 'shows a flash notice' do + subject + + expect(flash[:notice]) + .to eq( + s_( + 'CloudSeed|Cloud SQL instance creation request successful. ' \ + 'Expected resolution time is ~5 minutes.' + ) + ) + end end end end