-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdefault_checkout_spec.rb
102 lines (74 loc) · 3.37 KB
/
default_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
require 'rails_helper'
RSpec.feature 'The default cart check out' do
scenario 'allows to fill all the needed informations in one step' do
create(:shipping_method, name: 'Fake shipping carrier', identifier: 'fake-shipping-calculator')
create(:payment_method, name: 'Fake payment gateway', identifier: 'fake-payment-gateway')
cart = create_filled_cart
visit checkout_path(cart_key: cart.identifier)
fill_in Customer.human_attribute_name(:email), with: '[email protected]'
within(:css, '[data-address-form="shipping"]') do
select 'M.', from: Address.human_attribute_name(:civility)
fill_in Address.human_attribute_name(:first_name), with: 'Jean'
fill_in Address.human_attribute_name(:last_name), with: 'Val'
fill_in Address.human_attribute_name(:address), with: '1 rue de la rue'
fill_in Address.human_attribute_name(:zip), with: '75001'
fill_in Address.human_attribute_name(:city), with: 'Paris'
select 'France', from: Address.human_attribute_name(:country)
end
# Choose the shipping method
choose 'Fake shipping carrier'
# Choose the payment method
choose 'Fake payment gateway'
# Accept terms
check 'terms-checkbox'
click_on t('stall.checkout.informations.validate')
expect(page).to have_content t('stall.checkout.payment.title')
cart.reload
expect(cart.customer.email).to eq('[email protected]')
expect(cart.shipping_address.address).to eq('1 rue de la rue')
expect(cart.billing_address).to eq(cart.shipping_address)
expect(cart.shipment.shipping_method.name).to eq('Fake shipping carrier')
expect(cart.shipment.price.to_i).not_to eq(0)
expect(cart.payment.payment_method.name).to eq('Fake payment gateway')
end
scenario 'shows the payment form to access target gateway' do
payment_method = create(:payment_method, name: 'Fake payment gateway', identifier: 'fake-payment-gateway')
cart = create_filled_cart
cart.state = :payment
cart.build_payment(payment_method: payment_method)
cart.save!
visit checkout_step_path(cart.wizard.route_key, cart)
expect(page).to have_content('Pay')
end
scenario 'displays back the payment button form if the payment was aborted' do
payment_method = create_payment_method
cart = create_filled_cart
cart.state = :payment
cart.build_payment(payment_method: payment_method)
cart.save!
visit process_checkout_step_path(cart.wizard.route_key, cart)
expect(page).to have_content('Pay')
end
scenario 'redirects to a thanks screen if the payment succeeded' do
payment_method = create_payment_method
cart = create_filled_cart
cart.state = :payment
cart.build_payment(payment_method: payment_method)
cart.save!
visit process_checkout_step_path(cart.wizard.route_key, cart, succeeded: true)
expect(cart.reload.state).to eq(:payment_return)
expect(page).to have_content(t('stall.checkout.payment_return.title'))
end
def create_filled_cart
book = create(:book, title: 'Alice in wonderland')
visit books_path
within(:css, "[data-book-id='#{ book.id }']") do
click_on t('stall.line_items.form.add_to_cart')
end
token = find(:xpath, '//div[@data-cart-token]')['data-cart-token']
Cart.find_by_token!(token)
end
def create_payment_method
create(:payment_method, name: 'Fake payment gateway', identifier: 'fake-payment-gateway')
end
end