From 3ce29b4a5b09a6a9be367570889a1a863da04489 Mon Sep 17 00:00:00 2001 From: Jesus Bermudez Velazquez Date: Mon, 4 Nov 2024 16:28:16 +0000 Subject: [PATCH 1/2] Add stub request Error gets built automagically by rspec, no need to { error: }.to_json --- .../v3/systems/products_controller_spec.rb | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb b/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb index 6d6e15d97..243436c73 100644 --- a/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb +++ b/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb @@ -72,9 +72,15 @@ context 'when verification provider returns false' do before do - expect(InstanceVerification::Providers::Example).to receive(:new) - .with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, instance_data).and_return(plugin_double) - expect(plugin_double).to receive(:instance_valid?).and_return(false) + stub_request(:post, scc_activate_url) + .to_return( + status: 200, + body: { error: 'Unexpected instance verification error has occurred' }.to_json, + headers: {} + ) + # expect(InstanceVerification::Providers::Example).to receive(:new) + # .with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, instance_data).and_return(plugin_double) + # expect(plugin_double).to receive(:instance_valid?).and_return(false) post url, params: payload, headers: headers end @@ -86,9 +92,16 @@ context 'when verification provider raises an unhandled exception' do before do - expect(InstanceVerification::Providers::Example).to receive(:new) - .with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, instance_data).and_return(plugin_double) - expect(plugin_double).to receive(:instance_valid?).and_raise('Custom plugin error') + stub_request(:post, scc_activate_url) + .to_return( + status: 422, + body: { error: 'Unexpected instance verification error has occurred' }.to_json, + headers: {} + ) + + # expect(InstanceVerification::Providers::Example).to receive(:new) + # .with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, instance_data).and_return(plugin_double) + # expect(plugin_double).to receive(:instance_valid?).and_raise('Custom plugin error') post url, params: payload, headers: headers end @@ -623,7 +636,7 @@ .with({ headers: scc_headers, body: payload.merge({ byos_mode: 'byos' }) }) .and_return( status: 401, - body: { error: 'error_message' }.to_json, + body: 'Migration target not allowed on this instance type', headers: {} ) request From 3ceb78994a56db40d1e5284798d4eac525410a14 Mon Sep 17 00:00:00 2001 From: Jesus Bermudez Velazquez Date: Tue, 5 Nov 2024 14:45:59 +0000 Subject: [PATCH 2/2] Remove commented expects Expect was too granular and specific --- .../api/connect/v3/systems/products_controller_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb b/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb index 243436c73..9ccbcb1c2 100644 --- a/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb +++ b/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb @@ -78,9 +78,6 @@ body: { error: 'Unexpected instance verification error has occurred' }.to_json, headers: {} ) - # expect(InstanceVerification::Providers::Example).to receive(:new) - # .with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, instance_data).and_return(plugin_double) - # expect(plugin_double).to receive(:instance_valid?).and_return(false) post url, params: payload, headers: headers end @@ -99,9 +96,6 @@ headers: {} ) - # expect(InstanceVerification::Providers::Example).to receive(:new) - # .with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, instance_data).and_return(plugin_double) - # expect(plugin_double).to receive(:instance_valid?).and_raise('Custom plugin error') post url, params: payload, headers: headers end