solidus_afterpay 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/Gemfile +6 -3
- data/README.md +3 -0
- data/app/controllers/solidus_afterpay/callbacks_controller.rb +5 -1
- data/app/controllers/solidus_afterpay/express_callbacks_controller.rb +5 -1
- data/app/models/solidus_afterpay/order_component_builder.rb +1 -1
- data/bin/sandbox +1 -1
- data/lib/solidus_afterpay/configuration.rb +9 -2
- data/lib/solidus_afterpay/engine.rb +1 -1
- data/lib/solidus_afterpay/testing_support/factories.rb +1 -1
- data/lib/solidus_afterpay/version.rb +1 -1
- data/solidus_afterpay.gemspec +4 -4
- metadata +11 -99
- data/spec/fixtures/vcr_casettes/create_checkout/invalid.yml +0 -65
- data/spec/fixtures/vcr_casettes/create_checkout/valid.yml +0 -64
- data/spec/fixtures/vcr_casettes/credit/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/credit/valid.yml +0 -63
- data/spec/fixtures/vcr_casettes/deferred/authorize/declined_payment.yml +0 -120
- data/spec/fixtures/vcr_casettes/deferred/authorize/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/authorize/valid.yml +0 -120
- data/spec/fixtures/vcr_casettes/deferred/capture/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/capture/valid.yml +0 -140
- data/spec/fixtures/vcr_casettes/deferred/void/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/void/valid.yml +0 -137
- data/spec/fixtures/vcr_casettes/find_order/invalid.yml +0 -64
- data/spec/fixtures/vcr_casettes/find_order/valid.yml +0 -120
- data/spec/fixtures/vcr_casettes/find_payment/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/find_payment/valid.yml +0 -140
- data/spec/fixtures/vcr_casettes/immediate/capture/declined_payment.yml +0 -120
- data/spec/fixtures/vcr_casettes/immediate/capture/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/immediate/capture/valid.yml +0 -134
- data/spec/fixtures/vcr_casettes/retrieve_configuration/valid.yml +0 -67
- data/spec/helpers/solidus_afterpay/afterpay_helper_spec.rb +0 -39
- data/spec/models/solidus_afterpay/gateway_spec.rb +0 -492
- data/spec/models/solidus_afterpay/order_component_builder_spec.rb +0 -198
- data/spec/models/solidus_afterpay/payment_method_spec.rb +0 -207
- data/spec/models/solidus_afterpay/payment_source_spec.rb +0 -61
- data/spec/models/solidus_afterpay/user_agent_generator_spec.rb +0 -22
- data/spec/models/spree/order_spec.rb +0 -158
- data/spec/presenters/solidus_afterpay/order_presenter_spec.rb +0 -34
- data/spec/presenters/solidus_afterpay/shipping_rate_presenter_spec.rb +0 -28
- data/spec/requests/solidus_afterpay/callbacks_controller_spec.rb +0 -127
- data/spec/requests/solidus_afterpay/checkouts_controller_spec.rb +0 -258
- data/spec/requests/solidus_afterpay/express_callbacks_controller_spec.rb +0 -167
- data/spec/services/solidus_afterpay/base_service_spec.rb +0 -13
- data/spec/services/solidus_afterpay/shipping_rate_builder_service_spec.rb +0 -34
- data/spec/services/solidus_afterpay/update_order_addresses_service_spec.rb +0 -82
- data/spec/services/solidus_afterpay/update_order_attributes_service_spec.rb +0 -58
- data/spec/spec_helper.rb +0 -31
- data/spec/support/auth.rb +0 -15
- data/spec/support/cache.rb +0 -5
- data/spec/support/preferences.rb +0 -33
- data/spec/support/solidus.rb +0 -1
- data/spec/support/vcr.rb +0 -18
- data/spec/views/solidus_afterpay/express_checkout_button_spec.rb +0 -33
- data/spec/views/spree/shared/afterpay_messaging_spec.rb +0 -44
@@ -1,207 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SolidusAfterpay::PaymentMethod, type: :model do
|
4
|
-
let(:payment_method) { described_class.new }
|
5
|
-
|
6
|
-
describe "#gateway_class" do
|
7
|
-
subject { payment_method.gateway_class }
|
8
|
-
|
9
|
-
it { is_expected.to eq(SolidusAfterpay::Gateway) }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#payment_source_class" do
|
13
|
-
subject { payment_method.payment_source_class }
|
14
|
-
|
15
|
-
it { is_expected.to eq(SolidusAfterpay::PaymentSource) }
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#partial_name" do
|
19
|
-
subject { payment_method.partial_name }
|
20
|
-
|
21
|
-
it { is_expected.to eq('afterpay') }
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#try_void" do
|
25
|
-
subject { payment_method.try_void(payment) }
|
26
|
-
|
27
|
-
let(:response_code) { 'RESPONSE_CODE' }
|
28
|
-
let(:payment_source) { build(:afterpay_payment_source) }
|
29
|
-
let(:payment) { build(:afterpay_payment, response_code: response_code, source: payment_source) }
|
30
|
-
|
31
|
-
let(:can_void?) { true }
|
32
|
-
let(:gateway_response_success?) { true }
|
33
|
-
let(:gateway_response) { ActiveMerchant::Billing::Response.new(gateway_response_success?, '') }
|
34
|
-
|
35
|
-
let(:gateway_options) { { originator: payment, currency: 'USD' } }
|
36
|
-
|
37
|
-
before do
|
38
|
-
allow(payment_source).to receive(:can_void?).and_return(can_void?)
|
39
|
-
allow(payment_method).to receive(:void).with(response_code, gateway_options).and_return(gateway_response)
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when the void completes successful' do
|
43
|
-
it 'returns the void response' do
|
44
|
-
is_expected.to eq(gateway_response)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when the void throws an error' do
|
49
|
-
let(:gateway_response_success?) { false }
|
50
|
-
|
51
|
-
it { is_expected.to be(false) }
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when the payment can't be voided" do
|
55
|
-
let(:can_void?) { false }
|
56
|
-
|
57
|
-
it { is_expected.to be(false) }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#excluded_product?" do
|
62
|
-
subject { payment_method.excluded_product?(product) }
|
63
|
-
|
64
|
-
let(:product) { create(:base_product) }
|
65
|
-
let(:excluded_product_ids) { product.id.to_s }
|
66
|
-
let(:payment_method) { described_class.new(preferred_excluded_products: excluded_product_ids) }
|
67
|
-
|
68
|
-
context 'when the product is excluded' do
|
69
|
-
it { is_expected.to be_truthy }
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'when the product is not excluded' do
|
73
|
-
let(:excluded_product_ids) { '' }
|
74
|
-
|
75
|
-
it { is_expected.to be_falsey }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#available_for_order?" do
|
80
|
-
subject { payment_method.available_for_order?(order) }
|
81
|
-
|
82
|
-
let(:product) { create(:base_product) }
|
83
|
-
let(:excluded_product_ids) { '' }
|
84
|
-
let(:payment_method) { create(:afterpay_payment_method, preferred_excluded_products: excluded_product_ids) }
|
85
|
-
let(:order) {
|
86
|
-
build(:order_with_line_items, currency: order_currency,
|
87
|
-
line_items_attributes: line_items_attributes)
|
88
|
-
}
|
89
|
-
let(:line_items_attributes) do
|
90
|
-
[{ product: product }]
|
91
|
-
end
|
92
|
-
let(:order_currency) { 'USD' }
|
93
|
-
|
94
|
-
context "with cache" do
|
95
|
-
context 'when order total is inside the range' do
|
96
|
-
before do
|
97
|
-
Rails.cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD")
|
98
|
-
Rails.cache.write("solidus_afterpay_configuration_maximumAmount_amount", 1000.0)
|
99
|
-
Rails.cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0)
|
100
|
-
end
|
101
|
-
|
102
|
-
it { is_expected.to be(true) }
|
103
|
-
end
|
104
|
-
|
105
|
-
context 'when order total is outside the range' do
|
106
|
-
before do
|
107
|
-
Rails.cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD")
|
108
|
-
Rails.cache.write("solidus_afterpay_configuration_maximumAmount_amount", 4.0)
|
109
|
-
Rails.cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0)
|
110
|
-
end
|
111
|
-
|
112
|
-
it { is_expected.to be(false) }
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'when order currency is different from afterpay configuration' do
|
116
|
-
before do
|
117
|
-
Rails.cache.write("solidus_afterpay_configuration_maximumAmount_amount", 1000.0)
|
118
|
-
Rails.cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0)
|
119
|
-
Rails.cache.write("solidus_afterpay_configuration_maximumAmount_currency", "EUR")
|
120
|
-
end
|
121
|
-
|
122
|
-
it { is_expected.to be(false) }
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'when order currency is the same from afterpay configuration' do
|
126
|
-
before do
|
127
|
-
Rails.cache.write("solidus_afterpay_configuration_maximumAmount_amount", 1000.0)
|
128
|
-
Rails.cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0)
|
129
|
-
Rails.cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD")
|
130
|
-
end
|
131
|
-
|
132
|
-
it { is_expected.to be(true) }
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context 'when there is no cache' do
|
137
|
-
let(:configuration) do
|
138
|
-
require 'hashie'
|
139
|
-
|
140
|
-
Hashie::Mash.new({
|
141
|
-
minimumAmount: { amount: '1', currency: 'USD' },
|
142
|
-
maximumAmount: { amount: '110', currency: 'USD' }
|
143
|
-
})
|
144
|
-
end
|
145
|
-
|
146
|
-
before do
|
147
|
-
allow(payment_method.gateway).to receive(:retrieve_configuration).and_return(configuration)
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'when order total is inside the range and the currency is the same from afterpay configuration' do
|
151
|
-
it { is_expected.to be(true) }
|
152
|
-
end
|
153
|
-
|
154
|
-
context 'when order total is outside the range' do
|
155
|
-
it do
|
156
|
-
order.update(total: 111)
|
157
|
-
is_expected.to be(false)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'when order currency is different from afterpay configuration' do
|
162
|
-
let(:order_currency) { 'EUR' }
|
163
|
-
|
164
|
-
it { is_expected.to be(false) }
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context "when the items are excluded from the payment_method" do
|
169
|
-
let(:excluded_product_ids) { product.id.to_s }
|
170
|
-
|
171
|
-
context "when the id's of all the products are excluded" do
|
172
|
-
it { is_expected.to be_falsey }
|
173
|
-
end
|
174
|
-
|
175
|
-
context "when the id of one of the products is excluded" do
|
176
|
-
let(:second_product) { create(:base_product) }
|
177
|
-
let(:line_items_attributes) do
|
178
|
-
[{ product: product }, { product: second_product }]
|
179
|
-
end
|
180
|
-
|
181
|
-
it { is_expected.to be(false) }
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context "when none of the items are excluded from the payment_method" do
|
186
|
-
let(:configuration) do
|
187
|
-
require 'hashie'
|
188
|
-
|
189
|
-
Hashie::Mash.new({
|
190
|
-
minimumAmount: { amount: '1', currency: 'USD' },
|
191
|
-
maximumAmount: { amount: '1000', currency: 'USD' }
|
192
|
-
})
|
193
|
-
end
|
194
|
-
|
195
|
-
let(:excluded_product_ids) { '' }
|
196
|
-
|
197
|
-
before do
|
198
|
-
Rails.cache.clear
|
199
|
-
allow(payment_method.gateway).to receive(:retrieve_configuration).and_return(configuration)
|
200
|
-
end
|
201
|
-
|
202
|
-
it "returns true when none of the products are excluded" do
|
203
|
-
is_expected.to be(true)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SolidusAfterpay::PaymentSource, type: :model do
|
4
|
-
let(:payment_source) { described_class.new }
|
5
|
-
|
6
|
-
describe '#actions' do
|
7
|
-
subject { payment_source.actions }
|
8
|
-
|
9
|
-
it 'supports capture, void, and credit' do
|
10
|
-
is_expected.to eq(%w[capture void credit])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#can_void?' do
|
15
|
-
subject { payment_source.can_void?(payment) }
|
16
|
-
|
17
|
-
let(:auto_capture) { true }
|
18
|
-
let(:payment_method) { build(:afterpay_payment_method, auto_capture: auto_capture) }
|
19
|
-
let(:payment) { build(:afterpay_payment, payment_method: payment_method) }
|
20
|
-
|
21
|
-
context 'with the immediate flow' do
|
22
|
-
it 'is always false' do
|
23
|
-
is_expected.to be(false)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'with the deferred flow' do
|
28
|
-
let(:auto_capture) { false }
|
29
|
-
|
30
|
-
let(:payment_state) { 'AUTH_APPROVED' }
|
31
|
-
let(:gateway_response) { { paymentState: payment_state } }
|
32
|
-
let(:gateway) { instance_double(SolidusAfterpay::Gateway, find_payment: gateway_response) }
|
33
|
-
|
34
|
-
before do
|
35
|
-
allow(payment_method).to receive(:gateway).and_return(gateway)
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when the payment exists and the payment state is voidable' do
|
39
|
-
it 'returns true' do
|
40
|
-
is_expected.to be(true)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when the payment exists when the payment state is not voidable' do
|
45
|
-
let(:payment_state) { 'NOT_VOIDABLE' }
|
46
|
-
|
47
|
-
it 'returns false' do
|
48
|
-
is_expected.to be(false)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when the payment doesn't exist" do
|
53
|
-
let(:gateway_response) { nil }
|
54
|
-
|
55
|
-
it 'returns false' do
|
56
|
-
is_expected.to be(false)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SolidusAfterpay::UserAgentGenerator do
|
4
|
-
describe '#generate' do
|
5
|
-
subject { user_agent_generator.generate }
|
6
|
-
|
7
|
-
let(:user_agent_generator) { described_class.new(merchant_id: merchant_id) }
|
8
|
-
let(:merchant_id) { 'MERCHANT_ID' }
|
9
|
-
let(:default_store) { build(:store, url: 'test.com') }
|
10
|
-
|
11
|
-
before do
|
12
|
-
stub_const('SolidusAfterpay::VERSION', '0.1.0')
|
13
|
-
allow(::Spree).to receive(:solidus_gem_version).and_return('3.0.1')
|
14
|
-
stub_const('RUBY_VERSION', '2.6.6')
|
15
|
-
allow(::Spree::Store).to receive(:default).and_return(default_store)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'includes the production javascript' do
|
19
|
-
is_expected.to eq('SolidusAfterpay/0.1.0 (Solidus/3.0.1; Ruby/2.6.6; Merchant/MERCHANT_ID) https://test.com')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Spree::Order, type: :model do
|
6
|
-
let(:store) { create(:store) }
|
7
|
-
let(:user) { create(:user, email: "solidus@example.com") }
|
8
|
-
let(:order) { create(:order, user: user, store: store) }
|
9
|
-
|
10
|
-
describe "#available_payment_methods" do
|
11
|
-
it "includes frontend payment methods" do
|
12
|
-
payment_method = Spree::PaymentMethod::Check.create!({
|
13
|
-
name: "Fake",
|
14
|
-
active: true,
|
15
|
-
available_to_users: true,
|
16
|
-
available_to_admin: false
|
17
|
-
})
|
18
|
-
expect(order.available_payment_methods).to include(payment_method)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "includes 'both' payment methods" do
|
22
|
-
payment_method = Spree::PaymentMethod::Check.create!({
|
23
|
-
name: "Fake",
|
24
|
-
active: true,
|
25
|
-
available_to_users: true,
|
26
|
-
available_to_admin: true
|
27
|
-
})
|
28
|
-
expect(order.available_payment_methods).to include(payment_method)
|
29
|
-
end
|
30
|
-
|
31
|
-
# rubocop:disable RSpec/MultipleExpectations
|
32
|
-
it "does not include a payment method twice" do
|
33
|
-
payment_method = Spree::PaymentMethod::Check.create!({
|
34
|
-
name: "Fake",
|
35
|
-
active: true,
|
36
|
-
available_to_users: true,
|
37
|
-
available_to_admin: true
|
38
|
-
})
|
39
|
-
expect(order.available_payment_methods.count).to eq(1)
|
40
|
-
expect(order.available_payment_methods).to include(payment_method)
|
41
|
-
end
|
42
|
-
# rubocop:enable RSpec/MultipleExpectations
|
43
|
-
|
44
|
-
it "does not include inactive payment methods" do
|
45
|
-
Spree::PaymentMethod::Check.create!({
|
46
|
-
name: "Fake",
|
47
|
-
active: false,
|
48
|
-
available_to_users: true,
|
49
|
-
available_to_admin: true
|
50
|
-
})
|
51
|
-
expect(order.available_payment_methods.count).to eq(0)
|
52
|
-
end
|
53
|
-
|
54
|
-
context "with more than one payment method" do
|
55
|
-
subject { order.available_payment_methods }
|
56
|
-
|
57
|
-
let!(:first_method) {
|
58
|
-
FactoryBot.create(:payment_method, available_to_users: true,
|
59
|
-
available_to_admin: true)
|
60
|
-
}
|
61
|
-
let!(:second_method) {
|
62
|
-
FactoryBot.create(:payment_method, available_to_users: true,
|
63
|
-
available_to_admin: true)
|
64
|
-
}
|
65
|
-
|
66
|
-
before do
|
67
|
-
second_method.move_to_top
|
68
|
-
end
|
69
|
-
|
70
|
-
it "respects the order of methods based on position" do
|
71
|
-
is_expected.to eq([second_method, first_method])
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'when a payment method responds to #available_for_order?' do
|
75
|
-
let(:third_method) {
|
76
|
-
FakePaymentMethod.create(name: 'Fake', available_to_users: true, available_to_admin: true)
|
77
|
-
}
|
78
|
-
|
79
|
-
before do
|
80
|
-
fake_payment_method_class = Class.new(SolidusSupport.payment_method_parent_class)
|
81
|
-
stub_const('FakePaymentMethod', fake_payment_method_class)
|
82
|
-
|
83
|
-
third_method
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when it responds with true' do
|
87
|
-
before do
|
88
|
-
FakePaymentMethod.class_eval { def available_for_order?(_order); true; end }
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'includes it in the result' do
|
92
|
-
is_expected.to eq([second_method, first_method, third_method])
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'when it responds with false' do
|
97
|
-
before do
|
98
|
-
FakePaymentMethod.class_eval { def available_for_order?(_order); false; end }
|
99
|
-
end
|
100
|
-
|
101
|
-
it "doesn't include it in the result" do
|
102
|
-
is_expected.to eq([second_method, first_method])
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'when the order has a store' do
|
109
|
-
let(:order) { create(:order) }
|
110
|
-
|
111
|
-
let!(:store_with_payment_methods) do
|
112
|
-
create(:store,
|
113
|
-
payment_methods: [payment_method_with_store])
|
114
|
-
end
|
115
|
-
let!(:payment_method_with_store) { create(:payment_method) }
|
116
|
-
let!(:store_without_payment_methods) { create(:store) }
|
117
|
-
let!(:payment_method_without_store) { create(:payment_method) }
|
118
|
-
|
119
|
-
context 'when the store has payment methods' do
|
120
|
-
before { order.update!(store: store_with_payment_methods) }
|
121
|
-
|
122
|
-
it 'returns only the matching payment methods for that store' do
|
123
|
-
expect(order.available_payment_methods).to match_array(
|
124
|
-
[payment_method_with_store]
|
125
|
-
)
|
126
|
-
end
|
127
|
-
|
128
|
-
context 'when the store has an extra payment method unavailable to users' do
|
129
|
-
let!(:admin_only_payment_method) do
|
130
|
-
create(:payment_method,
|
131
|
-
available_to_users: false,
|
132
|
-
available_to_admin: true)
|
133
|
-
end
|
134
|
-
|
135
|
-
before do
|
136
|
-
store_with_payment_methods.payment_methods << admin_only_payment_method
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'returns only the payment methods available to users for that store' do
|
140
|
-
expect(order.available_payment_methods).to match_array(
|
141
|
-
[payment_method_with_store]
|
142
|
-
)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'when the store does not have payment methods' do
|
148
|
-
before { order.update!(store: store_without_payment_methods) }
|
149
|
-
|
150
|
-
it 'returns all matching payment methods regardless of store' do
|
151
|
-
expect(order.available_payment_methods).to match_array(
|
152
|
-
[payment_method_with_store, payment_method_without_store]
|
153
|
-
)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::OrderPresenter do
|
6
|
-
describe '#line_items_tax_amount' do
|
7
|
-
subject(:line_items_tax_amount) { described_class.new(order: order).line_items_tax_amount }
|
8
|
-
|
9
|
-
describe '#line_items_tax_amount' do
|
10
|
-
before do
|
11
|
-
country = create(:country)
|
12
|
-
state = create(:state, country: country)
|
13
|
-
zone = create(:zone, country_ids: [country.id], state_ids: [state.id])
|
14
|
-
create(:tax_rate, zone: zone)
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'when the order has line items' do
|
18
|
-
let(:order) { create(:order_with_line_items, line_items_count: 2) }
|
19
|
-
|
20
|
-
it 'returns the line items tax total amout' do
|
21
|
-
expect(line_items_tax_amount).to eq(2.0)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when the order does not have line items' do
|
26
|
-
let(:order) { create(:order) }
|
27
|
-
|
28
|
-
it 'returns 0' do
|
29
|
-
expect(line_items_tax_amount).to eq(0)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::ShippingRatePresenter do
|
6
|
-
let(:order) { create(:order_with_line_items ) }
|
7
|
-
let(:shipment) { create(:shipment, order: order) }
|
8
|
-
let(:shipping_rate) { create(:shipping_rate, cost: 5, shipment: shipment) }
|
9
|
-
let(:shipping_rate_tax) { ::Spree::ShippingRateTax.create(amount: 0.75, shipping_rate: shipping_rate) }
|
10
|
-
|
11
|
-
before { shipping_rate.taxes << shipping_rate_tax }
|
12
|
-
|
13
|
-
describe '#order_amount' do
|
14
|
-
subject(:order_amount) { described_class.new(shipping_rate: shipping_rate).order_amount }
|
15
|
-
|
16
|
-
it 'returns the order total including the shipping rate' do
|
17
|
-
expect(order_amount.to_f).to eq(15.75)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#amount_with_taxes' do
|
22
|
-
subject(:amount_with_taxes) { described_class.new(shipping_rate: shipping_rate).amount_with_taxes }
|
23
|
-
|
24
|
-
it 'returns the total amount including taxes' do
|
25
|
-
expect(amount_with_taxes.to_f).to eq(5.75)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::CallbacksController, type: :request do
|
6
|
-
describe 'GET cancel' do
|
7
|
-
subject(:request) { get '/solidus_afterpay/callbacks/cancel', params: params }
|
8
|
-
|
9
|
-
let(:order) { create(:order_with_totals, state: 'payment') }
|
10
|
-
|
11
|
-
let(:params) { { order_number: order.number } }
|
12
|
-
|
13
|
-
it 'redirects to the order current checkout state page' do
|
14
|
-
request
|
15
|
-
expect(response).to redirect_to('/checkout/payment')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'GET confirm' do
|
20
|
-
subject(:request) { get '/solidus_afterpay/callbacks/confirm', params: params }
|
21
|
-
|
22
|
-
let(:order) { create(:order_with_totals, state: 'payment', user: user) }
|
23
|
-
let(:payment_method) { create(:afterpay_payment_method) }
|
24
|
-
let(:user) { create(:user) }
|
25
|
-
|
26
|
-
let(:order_token) { 'ORDER_TOKEN' }
|
27
|
-
let(:order_number) { order.number }
|
28
|
-
let(:payment_method_id) { payment_method.id }
|
29
|
-
|
30
|
-
let(:params) { { orderToken: order_token, order_number: order_number, payment_method_id: payment_method_id } }
|
31
|
-
|
32
|
-
context 'when the user is logged in', with_signed_in_user: true do
|
33
|
-
context 'with valid data' do
|
34
|
-
it 'redirects to the order next checkout state page' do
|
35
|
-
request
|
36
|
-
expect(response).to redirect_to('/checkout/confirm')
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'moves the order to its next state' do
|
40
|
-
expect { request }.to change { order.reload.state }.from('payment').to('confirm')
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'creates a payment' do
|
44
|
-
expect { request }.to change { order.payments.count }.from(0).to(1)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'sets the payment total equal to the order total' do
|
48
|
-
request
|
49
|
-
expect(order.payments.last.amount).to eq(order.total)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'creates a payment source and assigns the order token to it' do
|
53
|
-
request
|
54
|
-
expect(order.payments.last.payment_source.token).to eq(order_token)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'when the order_token is missing' do
|
59
|
-
let(:order_token) { nil }
|
60
|
-
|
61
|
-
it 'redirects to the order current checkout state page' do
|
62
|
-
request
|
63
|
-
expect(response).to redirect_to('/checkout/payment')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when the order_number is invalid' do
|
68
|
-
let(:order_number) { 'INVALID_ORDER_NUMBER' }
|
69
|
-
|
70
|
-
it 'redirects to the cart page' do
|
71
|
-
request
|
72
|
-
expect(response).to redirect_to('/cart')
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'sets a resource not found flash message' do
|
76
|
-
request
|
77
|
-
expect(flash[:notice]).to eq('The resource you were looking for could not be found.')
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when the payment_method_id is invalid' do
|
82
|
-
let(:payment_method_id) { 0 }
|
83
|
-
|
84
|
-
it 'redirects to the cart page' do
|
85
|
-
request
|
86
|
-
expect(response).to redirect_to('/cart')
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'sets a resource not found flash message' do
|
90
|
-
request
|
91
|
-
expect(flash[:notice]).to eq('The resource you were looking for could not be found.')
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'when the order is already in confirm state' do
|
96
|
-
let(:order) { create(:order_with_totals, state: 'confirm') }
|
97
|
-
|
98
|
-
it "doesn't move the order to its next state" do
|
99
|
-
expect { request }.not_to(change { order.reload.state })
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'when the order is already completed' do
|
104
|
-
let(:order) { create(:completed_order_with_totals) }
|
105
|
-
|
106
|
-
it 'redirects to the order detail page' do
|
107
|
-
request
|
108
|
-
expect(response).to redirect_to("/orders/#{order.number}")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'when the user is a guest user', with_guest_session: true do
|
114
|
-
it 'redirects to the order next checkout state page' do
|
115
|
-
request
|
116
|
-
expect(response).to redirect_to('/checkout/confirm')
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'when the user is not logged in' do
|
121
|
-
it 'redirects the user to vallalah' do
|
122
|
-
request
|
123
|
-
expect(response).to redirect_to('/cart')
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|