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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add void to INVALID_STATES (#11730)
Matthew Kennedya2d347d294a8
diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rbindex 086b11ae64..99b9496062 100644--- a/core/app/models/spree/payment.rb+++ b/core/app/models/spree/payment.rb@@ -17,7 +17,7 @@ module SpreeNON_RISKY_AVS_CODES = ['B', 'D', 'H', 'J', 'M', 'Q', 'T', 'V', 'X', 'Y'].freezeRISKY_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).freezewith_options inverse_of: :payments dobelongs_to :order, class_name: 'Spree::Order', touch: truediff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rbindex 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 dodescribe '#paid?' dosubject { 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 dobefore { 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' doit { 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+ endcontext 'when the amount of the valid payments < the order total' dolet(: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) }+ endend- 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) }+ endendenddiff --git a/core/spec/models/spree/payment_spec.rb b/core/spec/models/spree/payment_spec.rbindex 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 doit_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)) }enddescribe 'scopes' do