From 9bf0667d04c76f69a3bb0c7ce53fe516084d5751 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 24 Feb 2022 16:27:03 +0000 Subject: [PATCH 1/4] Moves failed response stub into registered user context --- .../consumer/shopping/checkout_paypal_spec.rb | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/spec/system/consumer/shopping/checkout_paypal_spec.rb b/spec/system/consumer/shopping/checkout_paypal_spec.rb index dbf3b8eb53..310c0b06c8 100644 --- a/spec/system/consumer/shopping/checkout_paypal_spec.rb +++ b/spec/system/consumer/shopping/checkout_paypal_spec.rb @@ -46,26 +46,15 @@ describe "Check out with Paypal", js: true do add_product_to_cart order, product end - context "as a guest" do - it "fails with an error message" do - visit checkout_path - checkout_as_guest - fill_out_form(free_shipping.name, paypal.name, save_default_addresses: false) - - stub_paypal_response success: false - - place_order - expect(page).to have_content "PayPal failed." - end - end - context "as a registered user" do - before { login_as user } - - it "completes the checkout after successful Paypal payment" do + before do + login_as user visit checkout_path fill_out_details fill_out_form(free_shipping.name, paypal.name, save_default_addresses: false) + end + + it "completes the checkout after successful Paypal payment" do # Normally the checkout would redirect to Paypal, a form would be filled out there, and the # user would be redirected back to #confirm_paypal_path. Here we skip the PayPal part and @@ -84,5 +73,12 @@ describe "Check out with Paypal", js: true do expect(order.reload.state).to eq "complete" expect(order.payments.count).to eq 1 end + + it "fails with an error message" do + stub_paypal_response success: false + + place_order + expect(page).to have_content "PayPal failed." + end end end From 10217e2ec884393225ade56b4f329a9aaa5a57f2 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 24 Feb 2022 17:20:11 +0000 Subject: [PATCH 2/4] Sets guest and logged-in user as shared examples --- .../consumer/shopping/checkout_paypal_spec.rb | 71 ++++++++++++------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/spec/system/consumer/shopping/checkout_paypal_spec.rb b/spec/system/consumer/shopping/checkout_paypal_spec.rb index 310c0b06c8..b8e65482a8 100644 --- a/spec/system/consumer/shopping/checkout_paypal_spec.rb +++ b/spec/system/consumer/shopping/checkout_paypal_spec.rb @@ -46,39 +46,56 @@ describe "Check out with Paypal", js: true do add_product_to_cart order, product end - context "as a registered user" do - before do - login_as user - visit checkout_path - fill_out_details - fill_out_form(free_shipping.name, paypal.name, save_default_addresses: false) - end + shared_examples "users which " do |user_type| + context "checkout #{user_type}" do + before do + fill_out_details + fill_out_form(free_shipping.name, paypal.name, save_default_addresses: false) + end - it "completes the checkout after successful Paypal payment" do - - # Normally the checkout would redirect to Paypal, a form would be filled out there, and the - # user would be redirected back to #confirm_paypal_path. Here we skip the PayPal part and - # jump straight to being redirected back to OFN with a "confirmed" payment. - stub_paypal_response( - success: true, - redirect: payment_gateways_confirm_paypal_path( - payment_method_id: paypal.id, token: "t123", PayerID: 'p123' + it "completes the checkout after successful Paypal payment" do + # Normally the checkout would redirect to Paypal, a form would be filled out there, and the + # user would be redirected back to #confirm_paypal_path. Here we skip the PayPal part and + # jump straight to being redirected back to OFN with a "confirmed" payment. + stub_paypal_response( + success: true, + redirect: payment_gateways_confirm_paypal_path( + payment_method_id: paypal.id, token: "t123", PayerID: 'p123' + ) ) - ) - stub_paypal_confirm + stub_paypal_confirm - place_order - expect(page).to have_content "Your order has been processed successfully" + place_order + expect(page).to have_content "Your order has been processed successfully" - expect(order.reload.state).to eq "complete" - expect(order.payments.count).to eq 1 + expect(order.reload.state).to eq "complete" + expect(order.payments.count).to eq 1 + end + + it "fails with an error message" do + stub_paypal_response success: false + + place_order + expect(page).to have_content "PayPal failed." + end + end + end + + describe "shared_examples" do + context "as a guest user" do + before do + visit checkout_path + checkout_as_guest + end + it_behaves_like "users which ", "as guest" end - it "fails with an error message" do - stub_paypal_response success: false - - place_order - expect(page).to have_content "PayPal failed." + context "as a logged in user" do + before do + login_as user + visit checkout_path + end + it_behaves_like "users which ", "after logging in" end end end From 751e817deb519f2c543d5a26659a36cb60de9942 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 25 Feb 2022 16:32:31 +0000 Subject: [PATCH 3/4] Renames shared_examples --- spec/system/consumer/shopping/checkout_paypal_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/consumer/shopping/checkout_paypal_spec.rb b/spec/system/consumer/shopping/checkout_paypal_spec.rb index b8e65482a8..40beb2ce27 100644 --- a/spec/system/consumer/shopping/checkout_paypal_spec.rb +++ b/spec/system/consumer/shopping/checkout_paypal_spec.rb @@ -46,8 +46,8 @@ describe "Check out with Paypal", js: true do add_product_to_cart order, product end - shared_examples "users which " do |user_type| - context "checkout #{user_type}" do + shared_examples "checking out with paypal" do |user_type| + context "#{user_type}" do before do fill_out_details fill_out_form(free_shipping.name, paypal.name, save_default_addresses: false) @@ -87,7 +87,7 @@ describe "Check out with Paypal", js: true do visit checkout_path checkout_as_guest end - it_behaves_like "users which ", "as guest" + it_behaves_like "checking out with paypal", "as guest" end context "as a logged in user" do @@ -95,7 +95,7 @@ describe "Check out with Paypal", js: true do login_as user visit checkout_path end - it_behaves_like "users which ", "after logging in" + it_behaves_like "checking out with paypal", "after logging-in" end end end From 8ac2035d0c01e217a93b9aa9c830665bf866f162 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 25 Feb 2022 16:47:17 +0000 Subject: [PATCH 4/4] Addresses style issue --- spec/system/consumer/shopping/checkout_paypal_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/consumer/shopping/checkout_paypal_spec.rb b/spec/system/consumer/shopping/checkout_paypal_spec.rb index 40beb2ce27..950d2153b7 100644 --- a/spec/system/consumer/shopping/checkout_paypal_spec.rb +++ b/spec/system/consumer/shopping/checkout_paypal_spec.rb @@ -47,7 +47,7 @@ describe "Check out with Paypal", js: true do end shared_examples "checking out with paypal" do |user_type| - context "#{user_type}" do + context user_type.to_s do before do fill_out_details fill_out_form(free_shipping.name, paypal.name, save_default_addresses: false)