|
29 | 29 | Spree::CheckoutController.any_instance.stub(:current_order => order) |
30 | 30 | Spree::CheckoutController.any_instance.stub(:try_spree_current_user => user) |
31 | 31 | Spree::CheckoutController.any_instance.stub(:skip_state_validation? => true) |
| 32 | + Spree::OrdersController.any_instance.stub(try_spree_current_user: user) |
32 | 33 |
|
33 | 34 | # Capybara should wait up to 10 seconds for async. changes to be applied |
34 | 35 | Capybara.default_max_wait_time = 10 |
|
42 | 43 |
|
43 | 44 | # This will pass the CC data to the server and the StripeGateway class handles it |
44 | 45 | it "can process a valid payment (without JS)" do |
45 | | - fill_in "Card Number", :with => "4242 4242 4242 4242" |
46 | | - fill_in "Card Code", :with => "123" |
47 | | - fill_in "Expiration", :with => "01 / #{Time.now.year + 1}" |
| 46 | + fill_in 'card_number', with: '4242 4242 4242 4242' |
| 47 | + fill_in 'card_code', with: '123' |
| 48 | + fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}" |
48 | 49 | click_button "Save and Continue" |
49 | 50 | expect(page.current_url).to include("/checkout/confirm") |
50 | 51 | click_button "Place Order" |
51 | | - expect(page).to have_content("Your order has been processed successfully") |
| 52 | + order = Spree::Order.complete.last |
| 53 | + expect(page.current_url).to include("/orders/#{order.number}") |
| 54 | + expect(page).to have_content(order.number) |
52 | 55 | end |
53 | 56 |
|
54 | 57 | # This will fetch a token from Stripe.com and then pass that to the webserver. |
55 | 58 | # The server then processes the payment using that token. |
56 | 59 | it "can process a valid payment (with JS)", :js => true do |
57 | | - fill_in "Card Number", :with => "4242 4242 4242 4242" |
| 60 | + fill_in 'card_number', with: '4242 4242 4242 4242' |
58 | 61 | # Otherwise ccType field does not get updated correctly |
59 | 62 | page.execute_script("$('.cardNumber').trigger('change')") |
60 | | - fill_in "Card Code", :with => "123" |
61 | | - fill_in "Expiration", :with => "01 / #{Time.now.year + 1}" |
| 63 | + fill_in 'card_code', with: '123' |
| 64 | + fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}" |
62 | 65 | click_button "Save and Continue" |
63 | 66 | wait_for_stripe # Wait for Stripe API to return + form to submit |
64 | 67 | expect(page).to have_css('#checkout_form_confirm') |
65 | 68 | expect(page.current_url).to include("/checkout/confirm") |
66 | 69 | click_button "Place Order" |
67 | | - expect(page).to have_content("Your order has been processed successfully") |
| 70 | + order = Spree::Order.complete.last |
| 71 | + expect(page.current_url).to include("/orders/#{order.number}") |
| 72 | + expect(page).to have_content(order.number) |
68 | 73 | end |
69 | 74 |
|
70 | 75 | it "shows an error with an invalid credit card number", :js => true do |
71 | 76 | # Card number is NOT valid. Fails Luhn checksum |
72 | | - fill_in "Card Number", :with => "4242 4242 4242 4249" |
| 77 | + fill_in 'card_number', with: '4242 4242 4242 4249' |
73 | 78 | click_button "Save and Continue" |
74 | 79 | wait_for_stripe |
75 | 80 | expect(page).to have_content("Your card number is incorrect") |
76 | 81 | expect(page).to have_css('.has-error #card_number.error') |
77 | 82 | end |
78 | 83 |
|
79 | 84 | it "shows an error with invalid security fields", :js => true do |
80 | | - fill_in "Card Number", :with => "4242 4242 4242 4242" |
81 | | - fill_in "Expiration", :with => "01 / #{Time.now.year + 1}" |
82 | | - fill_in "Card Code", :with => "99" |
| 85 | + fill_in 'card_number', with: '4242 4242 4242 4242' |
| 86 | + fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}" |
| 87 | + fill_in 'card_code', with: '99' |
83 | 88 | click_button "Save and Continue" |
84 | 89 | wait_for_stripe |
85 | 90 | expect(page).to have_content("Your card's security code is invalid.") |
86 | 91 | expect(page).to have_css('.has-error #card_code.error') |
87 | 92 | end |
88 | 93 |
|
89 | 94 | it "shows an error with invalid expiry month field", :js => true do |
90 | | - fill_in "Card Number", :with => "4242 4242 4242 4242" |
91 | | - fill_in "Expiration", :with => "00 / #{Time.now.year + 1}" |
92 | | - fill_in "Card Code", :with => "123" |
| 95 | + fill_in 'card_number', with: '4242 4242 4242 4242' |
| 96 | + fill_in 'card_expiry', :with => "00 / #{Time.now.year + 1}" |
| 97 | + fill_in 'card_code', with: '123' |
93 | 98 | click_button "Save and Continue" |
94 | 99 | wait_for_stripe |
95 | 100 | expect(page).to have_content("Your card's expiration month is invalid.") |
96 | 101 | expect(page).to have_css('.has-error #card_expiry.error') |
97 | 102 | end |
98 | 103 |
|
99 | 104 | it "shows an error with invalid expiry year field", :js => true do |
100 | | - fill_in "Card Number", :with => "4242 4242 4242 4242" |
101 | | - fill_in "Expiration", :with => "12 / " |
102 | | - fill_in "Card Code", :with => "123" |
| 105 | + fill_in 'card_number', with: '4242 4242 4242 4242' |
| 106 | + fill_in 'card_expiry', with: '12 / ' |
| 107 | + fill_in 'card_code', with: '123' |
103 | 108 | click_button "Save and Continue" |
104 | 109 | wait_for_stripe |
105 | 110 | expect(page).to have_content("Your card's expiration year is invalid.") |
|
0 commit comments