forked from solidusio/solidus_auth_devise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout_spec.rb
183 lines (143 loc) · 6.65 KB
/
checkout_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# frozen_string_literal: true
RSpec.feature 'Checkout', :js, type: :feature do
given!(:store) { create(:store) }
given!(:country) { create(:country, name: 'United States', states_required: true) }
given!(:state) { create(:state, name: 'Maryland', country: country) }
given!(:shipping_method) do
shipping_method = create(:shipping_method)
calculator = Spree::Calculator::Shipping::PerItem.create!(calculable: shipping_method, preferred_amount: 10)
shipping_method.calculator = calculator
shipping_method.tap(&:save)
end
given!(:zone) { create(:zone) }
given!(:address) { create(:address, state: state, country: country) }
given!(:payment_method){ create :check_payment_method }
background do
@product = create(:product, name: 'RoR Mug')
@product.master.stock_items.first.set_count_on_hand(1)
# Bypass gateway error on checkout | ..or stub a gateway
Spree::Config[:allow_checkout_on_gateway_error] = true
visit spree.root_path
end
# Regression test for https://github.com/solidusio/solidus/issues/1588
scenario 'leaving and returning to address step' do
Spree::Auth::Config.set(registration_step: true)
click_link 'RoR Mug'
click_button 'Add To Cart'
within('h1') { expect(page).to have_text 'Shopping Cart' }
click_button 'Checkout'
within '#guest_checkout' do
fill_in 'Email', with: 'test@example.com'
end
click_on 'Continue'
click_on 'Cart'
click_on 'Checkout'
expect(page).to have_content "Billing Address"
end
context 'without payment being required' do
scenario 'allow a visitor to checkout as guest, without registration' do
click_link 'RoR Mug'
click_button 'Add To Cart'
within('h1') { expect(page).to have_text 'Shopping Cart' }
click_button 'Checkout'
expect(page).to have_content(/Checkout as a Guest/i)
within('#guest_checkout') { fill_in 'Email', with: 'spree@test.com' }
click_button 'Continue'
expect(page).to have_text(/Billing Address/i)
expect(page).to have_text(/Shipping Address/i)
str_addr = 'bill_address'
select 'United States', from: "order_#{str_addr}_attributes_country_id"
%w(firstname lastname address1 city zipcode phone).each do |field|
fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
end
select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
check 'order_use_billing'
click_button 'Save and Continue'
click_button 'Save and Continue'
click_button 'Save and Continue'
click_button 'Place Order'
expect(page).to have_text 'Your order has been processed successfully'
end
scenario 'associate an uncompleted guest order with user after logging in' do
user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
click_link 'RoR Mug'
click_button 'Add To Cart'
visit spree.login_path
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
click_button 'Login'
click_link 'Cart'
expect(page).to have_text 'RoR Mug'
within('h1') { expect(page).to have_text 'Shopping Cart' }
click_button 'Checkout'
str_addr = 'bill_address'
select 'United States', from: "order_#{str_addr}_attributes_country_id"
%w(firstname lastname address1 city zipcode phone).each do |field|
fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
end
select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
check 'order_use_billing'
click_button 'Save and Continue'
click_button 'Save and Continue'
click_button 'Save and Continue'
click_button 'Place Order'
expect(page).to have_text 'Your order has been processed successfully'
expect(Spree::Order.first.user).to eq user
end
# Regression test for #890
scenario 'associate an incomplete guest order with user after successful password reset' do
create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
click_link 'RoR Mug'
click_button 'Add To Cart'
visit spree.login_path
click_link 'Forgot Password?'
fill_in 'spree_user_email', with: 'email@person.com'
click_button 'Reset my password'
# Need to do this now because the token stored in the DB is the encrypted version
# The 'plain-text' version is sent in the email and there's one way to get that!
reset_password_email = ActionMailer::Base.deliveries.first
token_url_regex = /\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
token = token_url_regex.match(reset_password_email.body.to_s)[1]
visit spree.edit_spree_user_password_path(reset_password_token: token)
fill_in 'Password', with: 'password'
fill_in 'Password Confirmation', with: 'password'
click_button 'Update'
click_link 'Cart'
click_button 'Checkout'
str_addr = 'bill_address'
select 'United States', from: "order_#{str_addr}_attributes_country_id"
%w(firstname lastname address1 city zipcode phone).each do |field|
fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
end
select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
check 'order_use_billing'
click_button 'Save and Continue'
expect(page).not_to have_text 'Email is invalid'
end
scenario 'allow a user to register during checkout' do
click_link 'RoR Mug'
click_button 'Add To Cart'
click_button 'Checkout'
expect(page).to have_text 'Registration'
click_link 'Create a new account'
fill_in 'Email', with: 'email@person.com'
fill_in 'Password', with: 'spree123'
fill_in 'Password Confirmation', with: 'spree123'
click_button 'Create'
expect(page).to have_text 'You have signed up successfully.'
str_addr = 'bill_address'
select 'United States', from: "order_#{str_addr}_attributes_country_id"
%w(firstname lastname address1 city zipcode phone).each do |field|
fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
end
select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
check 'order_use_billing'
click_button 'Save and Continue'
click_button 'Save and Continue'
click_button 'Save and Continue'
click_button 'Place Order'
expect(page).to have_text 'Your order has been processed successfully'
expect(Spree::Order.first.user).to eq Spree::User.find_by(email: 'email@person.com')
end
end
end