diff options
Diffstat (limited to 'spec/requests/projects/google_cloud/databases_controller_spec.rb')
-rw-r--r-- | spec/requests/projects/google_cloud/databases_controller_spec.rb | 84 |
1 files changed, 58 insertions, 26 deletions
diff --git a/spec/requests/projects/google_cloud/databases_controller_spec.rb b/spec/requests/projects/google_cloud/databases_controller_spec.rb index e91a51ce2ef..98e83610600 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 @@ RSpec.describe Projects::GoogleCloud::DatabasesController, :snowplow, feature_ca 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 @@ RSpec.describe Projects::GoogleCloud::DatabasesController, :snowplow, feature_ca 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 @@ RSpec.describe Projects::GoogleCloud::DatabasesController, :snowplow, feature_ca 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 |