forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from tvdeyen/harden-paypal-spec
Try to harden the PayPal integration spec
- Loading branch information
Showing
3 changed files
with
49 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
require 'spec_helper' | ||
|
||
describe "Checkout", type: :feature, js: true do | ||
Capybara.default_max_wait_time = 30 | ||
Capybara.default_max_wait_time = 60 | ||
let!(:store) do | ||
create(:store, payment_methods: [payment_method]).tap do |s| | ||
s.braintree_configuration.update!(paypal: true) | ||
|
@@ -22,10 +22,12 @@ | |
end | ||
|
||
it "should check out successfully using one touch" do | ||
move_through_paypal_popup | ||
expect(page).to have_content("Shipments") | ||
click_on "Place Order" | ||
expect(page).to have_content("Your order has been processed successfully") | ||
pend_if_paypal_slow do | ||
move_through_paypal_popup | ||
expect(page).to have_content("Shipments") | ||
click_on "Place Order" | ||
expect(page).to have_content("Your order has been processed successfully") | ||
end | ||
end | ||
end | ||
|
||
|
@@ -45,10 +47,12 @@ | |
click_button("Save and Continue") | ||
expect(page).to have_content("SHIPPING METHOD") | ||
click_button("Save and Continue") | ||
move_through_paypal_popup | ||
expect(page).to have_content("Shipments") | ||
click_on "Place Order" | ||
expect(page).to have_content("Your order has been processed successfully") | ||
pend_if_paypal_slow do | ||
move_through_paypal_popup | ||
expect(page).to have_content("Shipments") | ||
click_on "Place Order" | ||
expect(page).to have_content("Your order has been processed successfully") | ||
end | ||
end | ||
end | ||
|
||
|
@@ -66,21 +70,33 @@ def move_through_paypal_popup | |
click_button("paypal-button") | ||
end | ||
page.switch_to_window(popup) | ||
expect(page).to_not have_selector('body.loading') | ||
page.within_frame("injectedUl") do | ||
fill_in("email", with: "[email protected]") | ||
fill_in("password", with: "test1234") | ||
end | ||
|
||
# The check for 'body.loading' check doesn't work well from the within_frame | ||
# context, so we need to jump out before performing that check. | ||
expect(page).to_not have_selector('body.loading') | ||
page.within_frame("injectedUl") do | ||
click_button("btnLogin") | ||
# We don't control this popup window. | ||
# So javascript errors are not our errors. | ||
begin | ||
expect(page).to_not have_selector('body.loading') | ||
page.within_frame("injectedUl") do | ||
fill_in("email", with: "[email protected]") | ||
fill_in("password", with: "test1234") | ||
end | ||
|
||
# The check for 'body.loading' check doesn't work well from the within_frame | ||
# context, so we need to jump out before performing that check. | ||
expect(page).to_not have_selector('body.loading') | ||
page.within_frame("injectedUl") do | ||
click_button("btnLogin") | ||
end | ||
|
||
expect(page).to_not have_selector('body.loading') | ||
click_button("Agree & Continue") | ||
rescue Capybara::Poltergeist::JavascriptError => e | ||
pending "PayPal had javascript errors in their popup window." | ||
raise e | ||
rescue Capybara::ElementNotFound => e | ||
pending "PayPal delivered unkown HTML in their popup window." | ||
raise e | ||
end | ||
|
||
expect(page).to_not have_selector('body.loading') | ||
click_button("Agree & Continue") | ||
page.switch_to_window(page.windows.first) | ||
end | ||
|
||
|
@@ -101,4 +117,14 @@ def add_mug_to_cart | |
click_link mug.name | ||
click_button "add-to-cart-button" | ||
end | ||
|
||
def pend_if_paypal_slow | ||
yield | ||
rescue RSpec::Expectations::ExpectationNotMetError => e | ||
pending "PayPal did not answer in #{Capybara.default_max_wait_time} seconds." | ||
raise e | ||
rescue Capybara::Poltergeist::JavascriptError => e | ||
pending "PayPal delivered wrong payload because of errors in their popup window." | ||
raise e | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters