Skip to content

Commit

Permalink
Merge pull request #342 from spark-solutions/fix/spree-4-1
Browse files Browse the repository at this point in the history
Fixed Specs for Spree 4.1 new UI
  • Loading branch information
damianlegawiec authored Jan 30, 2020
2 parents a8409fb + f124837 commit b39a150
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
41 changes: 23 additions & 18 deletions spec/features/stripe_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Spree::CheckoutController.any_instance.stub(:current_order => order)
Spree::CheckoutController.any_instance.stub(:try_spree_current_user => user)
Spree::CheckoutController.any_instance.stub(:skip_state_validation? => true)
Spree::OrdersController.any_instance.stub(try_spree_current_user: user)

# Capybara should wait up to 10 seconds for async. changes to be applied
Capybara.default_max_wait_time = 10
Expand All @@ -42,64 +43,68 @@

# This will pass the CC data to the server and the StripeGateway class handles it
it "can process a valid payment (without JS)" do
fill_in "Card Number", :with => "4242 4242 4242 4242"
fill_in "Card Code", :with => "123"
fill_in "Expiration", :with => "01 / #{Time.now.year + 1}"
fill_in 'card_number', with: '4242 4242 4242 4242'
fill_in 'card_code', with: '123'
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
click_button "Save and Continue"
expect(page.current_url).to include("/checkout/confirm")
click_button "Place Order"
expect(page).to have_content("Your order has been processed successfully")
order = Spree::Order.complete.last
expect(page.current_url).to include("/orders/#{order.number}")
expect(page).to have_content(order.number)
end

# This will fetch a token from Stripe.com and then pass that to the webserver.
# The server then processes the payment using that token.
it "can process a valid payment (with JS)", :js => true do
fill_in "Card Number", :with => "4242 4242 4242 4242"
fill_in 'card_number', with: '4242 4242 4242 4242'
# Otherwise ccType field does not get updated correctly
page.execute_script("$('.cardNumber').trigger('change')")
fill_in "Card Code", :with => "123"
fill_in "Expiration", :with => "01 / #{Time.now.year + 1}"
fill_in 'card_code', with: '123'
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
click_button "Save and Continue"
wait_for_stripe # Wait for Stripe API to return + form to submit
expect(page).to have_css('#checkout_form_confirm')
expect(page.current_url).to include("/checkout/confirm")
click_button "Place Order"
expect(page).to have_content("Your order has been processed successfully")
order = Spree::Order.complete.last
expect(page.current_url).to include("/orders/#{order.number}")
expect(page).to have_content(order.number)
end

it "shows an error with an invalid credit card number", :js => true do
# Card number is NOT valid. Fails Luhn checksum
fill_in "Card Number", :with => "4242 4242 4242 4249"
fill_in 'card_number', with: '4242 4242 4242 4249'
click_button "Save and Continue"
wait_for_stripe
expect(page).to have_content("Your card number is incorrect")
expect(page).to have_css('.has-error #card_number.error')
end

it "shows an error with invalid security fields", :js => true do
fill_in "Card Number", :with => "4242 4242 4242 4242"
fill_in "Expiration", :with => "01 / #{Time.now.year + 1}"
fill_in "Card Code", :with => "99"
fill_in 'card_number', with: '4242 4242 4242 4242'
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
fill_in 'card_code', with: '99'
click_button "Save and Continue"
wait_for_stripe
expect(page).to have_content("Your card's security code is invalid.")
expect(page).to have_css('.has-error #card_code.error')
end

it "shows an error with invalid expiry month field", :js => true do
fill_in "Card Number", :with => "4242 4242 4242 4242"
fill_in "Expiration", :with => "00 / #{Time.now.year + 1}"
fill_in "Card Code", :with => "123"
fill_in 'card_number', with: '4242 4242 4242 4242'
fill_in 'card_expiry', :with => "00 / #{Time.now.year + 1}"
fill_in 'card_code', with: '123'
click_button "Save and Continue"
wait_for_stripe
expect(page).to have_content("Your card's expiration month is invalid.")
expect(page).to have_css('.has-error #card_expiry.error')
end

it "shows an error with invalid expiry year field", :js => true do
fill_in "Card Number", :with => "4242 4242 4242 4242"
fill_in "Expiration", :with => "12 / "
fill_in "Card Code", :with => "123"
fill_in 'card_number', with: '4242 4242 4242 4242'
fill_in 'card_expiry', with: '12 / '
fill_in 'card_code', with: '123'
click_button "Save and Continue"
wait_for_stripe
expect(page).to have_content("Your card's expiration year is invalid.")
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
reset_spree_preferences
create(:store)
end

config.after do
Expand Down

0 comments on commit b39a150

Please sign in to comment.