|
33 | 33 | end |
34 | 34 | end |
35 | 35 |
|
36 | | - describe "GET /checkout/payment" do |
37 | | - let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) } |
38 | | - |
39 | | - before { allow(SolidusBolt::Users::SyncPaymentSourcesService).to receive(:call) } |
40 | | - |
41 | | - it 'returns a successful response' do |
42 | | - get '/checkout/payment' |
43 | | - |
44 | | - expect(response.status).to eq 200 |
45 | | - end |
46 | | - |
47 | | - it 'calls the service to sync payment sources' do |
48 | | - get '/checkout/payment' |
49 | | - |
50 | | - expect(SolidusBolt::Users::SyncPaymentSourcesService).to have_received(:call) |
| 36 | + describe 'GET /checkout/delivery' do |
| 37 | + subject(:deliver_order) { get '/checkout/delivery' } |
| 38 | + |
| 39 | + let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:delivery) } |
| 40 | + let(:bolt_expiration_time) { Time.now.utc - 15.minutes } |
| 41 | + let(:access_token) { 'access_token' } |
| 42 | + let(:bolt_scope) { 'bolt.account.view openid' } |
| 43 | + let!(:session) do |
| 44 | + { bolt_access_token: access_token, bolt_expiration_time: bolt_expiration_time, bolt_scope: bolt_scope } |
51 | 45 | end |
52 | | - end |
53 | | - |
54 | | - describe 'PATCH /checkout/update/confirm' do |
55 | | - subject(:confirm_order) { patch '/checkout/update/confirm' } |
56 | | - |
57 | | - let(:order) { FactoryBot.create(:order_with_totals) } |
58 | | - let(:payment) { create(:payment, amount: order.total, order: order) } |
59 | | - let(:session) { { bolt_access_token: access_token } } |
60 | | - let(:access_token) { nil } |
61 | 46 |
|
62 | 47 | before do |
63 | | - # use test preparation from solidusio/solidus/frontend/spec/controllers/spree/checkout_controller_spec.rb |
64 | | - # because Spree::TestingSupport::OrderWalkthrough.up_to(:confirm) doesn't work |
65 | 48 | order.update! user: user |
66 | | - order.update(state: 'confirm') |
67 | | - payment |
68 | | - order.create_proposed_shipments |
69 | | - order.payments.reload |
70 | 49 |
|
71 | | - # request calls Gateway#authorize - need to stub it to test our action |
72 | | - allow(SolidusBolt::Transactions::AuthorizeService).to(receive(:call).and_return({ |
73 | | - 'transaction' => { 'from_credit_card' => { 'id' => 'CreditCardId' } } |
74 | | - })) |
| 50 | + allow(SolidusBolt::Users::SyncPaymentSourcesService).to receive(:call) |
75 | 51 |
|
76 | 52 | # rubocop:disable RSpec/AnyInstance |
77 | 53 | allow_any_instance_of(ActionDispatch::Request).to receive(:session).and_return(session) |
78 | 54 | # rubocop:enable RSpec/AnyInstance |
79 | 55 | end |
80 | 56 |
|
81 | | - it 'redirects to completion route' do |
82 | | - confirm_order |
83 | | - expect(response).to redirect_to spree.order_path(order) |
| 57 | + context 'without bolt session' do |
| 58 | + let(:access_token) { nil } |
| 59 | + |
| 60 | + it 'returns a successful response' do |
| 61 | + deliver_order |
| 62 | + |
| 63 | + expect(response.status).to eq 200 |
| 64 | + end |
| 65 | + |
| 66 | + it 'skips the job call to add addresses' do |
| 67 | + expect { deliver_order }.not_to have_enqueued_job(SolidusBolt::AddAddressJob) |
| 68 | + end |
84 | 69 | end |
85 | 70 |
|
86 | | - context 'with logged in Bolt user and Bolt payment' do |
87 | | - let(:access_token) { 'accesstoken' } |
88 | | - let(:payment) { create(:bolt_payment, amount: order.total, order: order) } |
| 71 | + context 'with valid bolt_access token' do |
| 72 | + it 'returns a successful response' do |
| 73 | + deliver_order |
89 | 74 |
|
90 | | - before { allow(SolidusBolt::Users::RefreshAccessTokenService).to receive(:call).and_return(access_token) } |
| 75 | + expect(response.status).to eq 200 |
| 76 | + end |
91 | 77 |
|
92 | 78 | it 'calls the job to add addresses' do |
93 | | - expect { confirm_order }.to(have_enqueued_job(SolidusBolt::AddAddressJob).twice.with { |hash| |
| 79 | + expect { deliver_order }.to(have_enqueued_job(SolidusBolt::AddAddressJob).twice.with { |hash| |
94 | 80 | expect(hash[:order]).to eq(order) |
95 | 81 | expect(hash[:access_token]).to eq(access_token) |
96 | 82 | expect(user.addresses).to include(hash[:address]) |
97 | 83 | }) |
98 | 84 | end |
99 | 85 | end |
100 | 86 |
|
101 | | - context 'with logged in Bolt user' do |
102 | | - let(:access_token) { 'accesstoken' } |
| 87 | + context 'with expired bolt_access token' do |
| 88 | + include Devise::Test::IntegrationHelpers |
| 89 | + |
| 90 | + let(:bolt_expiration_time) { Time.now.utc + 15.minutes } |
| 91 | + |
| 92 | + before { sign_in(order.user) } |
| 93 | + |
| 94 | + it 'stores the sign in location' do |
| 95 | + deliver_order |
| 96 | + |
| 97 | + expect(session[:spree_user_return_to]).to eq('/checkout/delivery') |
| 98 | + end |
| 99 | + |
| 100 | + it 'signs out the user' do |
| 101 | + deliver_order |
| 102 | + |
| 103 | + expect(controller.spree_user_signed_in?).to be false |
| 104 | + end |
103 | 105 |
|
104 | 106 | it 'skips the job call to add addresses' do |
105 | | - expect { confirm_order }.not_to have_enqueued_job(SolidusBolt::AddAddressJob) |
| 107 | + expect { deliver_order }.not_to have_enqueued_job(SolidusBolt::AddAddressJob) |
106 | 108 | end |
107 | 109 | end |
108 | 110 |
|
109 | | - context 'with Bolt payment' do |
110 | | - let(:payment) { create(:bolt_payment, amount: order.total, order: order) } |
| 111 | + context 'with refreshed access_token' do |
| 112 | + include Devise::Test::IntegrationHelpers |
| 113 | + |
| 114 | + let(:bolt_scope) { 'bolt.account.view' } |
| 115 | + |
| 116 | + before { sign_in(order.user) } |
| 117 | + |
| 118 | + it 'stores the sign in location' do |
| 119 | + deliver_order |
| 120 | + |
| 121 | + expect(session[:spree_user_return_to]).to eq('/checkout/delivery') |
| 122 | + end |
| 123 | + |
| 124 | + it 'signs out the user' do |
| 125 | + deliver_order |
| 126 | + |
| 127 | + expect(controller.spree_user_signed_in?).to be false |
| 128 | + end |
111 | 129 |
|
112 | 130 | it 'skips the job call to add addresses' do |
113 | | - expect { confirm_order }.not_to have_enqueued_job(SolidusBolt::AddAddressJob) |
| 131 | + expect { deliver_order }.not_to have_enqueued_job(SolidusBolt::AddAddressJob) |
114 | 132 | end |
115 | 133 | end |
116 | 134 | end |
| 135 | + |
| 136 | + describe "GET /checkout/payment" do |
| 137 | + let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) } |
| 138 | + |
| 139 | + before { allow(SolidusBolt::Users::SyncPaymentSourcesService).to receive(:call) } |
| 140 | + |
| 141 | + it 'returns a successful response' do |
| 142 | + get '/checkout/payment' |
| 143 | + |
| 144 | + expect(response.status).to eq 200 |
| 145 | + end |
| 146 | + |
| 147 | + it 'calls the service to sync payment sources' do |
| 148 | + get '/checkout/payment' |
| 149 | + |
| 150 | + expect(SolidusBolt::Users::SyncPaymentSourcesService).to have_received(:call) |
| 151 | + end |
| 152 | + end |
117 | 153 | end |
0 commit comments