This commit is contained in:
Feruz Oripov
2024-02-26 23:44:58 +05:00
parent ef17fd7d80
commit 67cd6ea6ed
7 changed files with 11 additions and 7 deletions

View File

@@ -20,7 +20,7 @@ class CustomersWithBalanceQuery
# The resulting orders are in states that belong after the checkout. Only these can be considered
# for a customer's balance.
def left_join_complete_orders
<<~SQL
<<~SQL.squish
LEFT JOIN spree_orders ON spree_orders.customer_id = customers.id
AND #{finalized_states.to_sql}
SQL

View File

@@ -29,7 +29,7 @@ class OutstandingBalanceQuery
# Arel doesn't support CASE statements until v7.1.0 so we'll have to wait with SQL literals
# a little longer. See https://github.com/rails/arel/pull/400 for details.
def statement
<<~SQL
<<~SQL.squish
CASE WHEN "spree_orders"."state" IN #{non_fulfilled_states_group.to_sql} THEN "spree_orders"."payment_total"
WHEN "spree_orders"."state" IS NOT NULL THEN "spree_orders"."payment_total" - "spree_orders"."total"
ELSE 0 END

View File

@@ -6,7 +6,7 @@ class PaymentsRequiringActionQuery
end
def call
Spree::Payment.joins(:order).where("spree_orders.user_id = ?", user.id).
Spree::Payment.joins(:order).where(spree_orders: { user_id: user.id }).
requires_authorization
end

View File

@@ -4,6 +4,7 @@ require 'spec_helper'
describe CompleteVisibleOrdersQuery do
subject { described_class.new(order_permissions).call }
let(:filter_canceled) { false }
describe '#call' do

View File

@@ -64,7 +64,8 @@ describe CustomersWithBalanceQuery do
context 'when orders are in delivery state' do
before do
create(:order, customer: customers, total: order_total, payment_total: 0, state: 'delivery')
create(:order, customer: customers, total: order_total, payment_total: 50, state: 'delivery')
create(:order, customer: customers, total: order_total, payment_total: 50,
state: 'delivery')
end
it 'returns the customer balance' do

View File

@@ -4,6 +4,7 @@ require 'spec_helper'
describe OutstandingBalanceQuery do
subject { described_class.new(relation) }
let(:result) { subject.call }
describe '#statement' do
@@ -12,7 +13,7 @@ describe OutstandingBalanceQuery do
it 'returns the CASE statement necessary to compute the order balance' do
normalized_sql_statement = normalize(subject.statement)
expect(normalized_sql_statement).to eq(normalize(<<-SQL))
expect(normalized_sql_statement).to eq(normalize(<<-SQL.squish))
CASE WHEN "spree_orders"."state" IN ('canceled', 'returned') THEN "spree_orders"."payment_total"
WHEN "spree_orders"."state" IS NOT NULL THEN "spree_orders"."payment_total" - "spree_orders"."total"
ELSE 0 END

View File

@@ -3,9 +3,10 @@
require 'spec_helper'
describe PaymentsRequiringActionQuery do
subject { described_class.new(user).call }
let(:user) { create(:user) }
let(:order) { create(:order, user:) }
subject { described_class.new(user).call }
describe '#call' do
context "payment has a cvv_response_message" do
@@ -27,7 +28,7 @@ describe PaymentsRequiringActionQuery do
end
it "does not find the payment" do
expect(subject.all).to_not include(payment)
expect(subject.all).not_to include(payment)
end
end
end