Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add void to INVALID_STATES (#11730)

Matthew Kennedya2d347d294a8
diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rb
index 086b11ae64..99b9496062 100644
--- a/core/app/models/spree/payment.rb
+++ b/core/app/models/spree/payment.rb
@@ -17,7 +17,7 @@ module Spree
NON_RISKY_AVS_CODES = ['B', 'D', 'H', 'J', 'M', 'Q', 'T', 'V', 'X', 'Y'].freeze
RISKY_AVS_CODES = ['A', 'C', 'E', 'F', 'G', 'I', 'K', 'L', 'N', 'O', 'P', 'R', 'S', 'U', 'W', 'Z'].freeze
- INVALID_STATES = %w(failed invalid).freeze
+ INVALID_STATES = %w(failed invalid void).freeze
with_options inverse_of: :payments do
belongs_to :order, class_name: 'Spree::Order', touch: true
diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb
index 50afc1450d..973046441b 100644
--- a/core/spec/models/spree/order_spec.rb
+++ b/core/spec/models/spree/order_spec.rb
@@ -1578,6 +1578,7 @@ describe Spree::Order, type: :model do
describe '#paid?' do
subject { order.paid? }
+ let!(:payment_0) { create(:payment, order: order, amount: amount) }
let!(:payment_1) { create(:payment, order: order, amount: amount) }
let!(:payment_2) { create(:payment, order: order, amount: amount) }
let(:amount) { 100 }
@@ -1586,22 +1587,111 @@ describe Spree::Order, type: :model do
before { payment_1.complete }
- context 'when all order valid payments were completed' do
- before { payment_2.complete }
+ context 'when all order valid payments are completed' do
+ before do
+ payment_1.complete
+ payment_2.complete
+ end
+
+ context 'when the amount of the valid payments < the order total' do
+ let(:total) { 201 }
+
+ it { expect(subject).to eq(false) }
+ end
+
+ context 'when the amount of the valid payments == the order total' do
+ let(:total) { 200 }
+
+ it { expect(subject).to eq(true) }
+ end
+
+ context 'when the amount of the valid payments > the order total' do
+ let(:total) { 199 }
- context 'when the amount of the valid payments >= the order total' do
it { expect(subject).to eq(true) }
end
+ end
+
+ context 'when not all order payments are completed one is void' do
+ before do
+ payment_0.void
+ payment_1.complete
+ payment_2.complete
+ end
context 'when the amount of the valid payments < the order total' do
let(:total) { 201 }
it { expect(subject).to eq(false) }
end
+
+ context 'when the amount of the valid payments == the order total' do
+ let(:total) { 200 }
+
+ it { expect(subject).to eq(true) }
+ end
+
+ context 'when the amount of the valid payments > the order total' do
+ let(:total) { 199 }
+
+ it { expect(subject).to eq(true) }
+ end
end
- context 'when not all order valid payments were completed' do
- it { expect(subject).to eq(false) }
+ context 'when not all order payments are completed one is failed' do
+ before do
+ payment_0.state = 'failed'
+ payment_0.save!
+
+ payment_1.complete
+ payment_2.complete
+ end
+
+ context 'when the amount of the valid payments < the order total' do
+ let(:total) { 201 }
+
+ it { expect(subject).to eq(false) }
+ end
+
+ context 'when the amount of the valid payments == the order total' do
+ let(:total) { 200 }
+
+ it { expect(subject).to eq(true) }
+ end
+
+ context 'when the amount of the valid payments > the order total' do
+ let(:total) { 199 }
+
+ it { expect(subject).to eq(true) }
+ end
+ end
+
+ context 'when not all order payments are completed one is invalid' do
+ before do
+ payment_0.state = 'invalid'
+ payment_0.save!
+
+ payment_1.complete
+ payment_2.complete
+ end
+
+ context 'when the amount of the valid payments < the order total' do
+ let(:total) { 201 }
+
+ it { expect(subject).to eq(false) }
+ end
+
+ context 'when the amount of the valid payments == the order total' do
+ let(:total) { 200 }
+
+ it { expect(subject).to eq(true) }
+ end
+
+ context 'when the amount of the valid payments > the order total' do
+ let(:total) { 199 }
+
+ it { expect(subject).to eq(true) }
+ end
end
end
diff --git a/core/spec/models/spree/payment_spec.rb b/core/spec/models/spree/payment_spec.rb
index d86caa3f3a..37dba7872c 100644
--- a/core/spec/models/spree/payment_spec.rb
+++ b/core/spec/models/spree/payment_spec.rb
@@ -50,7 +50,7 @@ describe Spree::Payment, type: :model do
it_behaves_like 'metadata'
describe 'Constants' do
- it { expect(Spree::Payment::INVALID_STATES).to eq(%w(failed invalid)) }
+ it { expect(Spree::Payment::INVALID_STATES).to eq(%w(failed invalid void)) }
end
describe 'scopes' do