This commit is contained in:
Feruz Oripov
2024-02-27 00:29:59 +05:00
parent 67cd6ea6ed
commit 3cf75fce72
5 changed files with 33 additions and 33 deletions

View File

@@ -3,7 +3,7 @@
require 'spec_helper'
describe CompleteOrdersWithBalanceQuery do
subject { described_class.new(user).call }
subject(:result) { described_class.new(user).call }
describe '#call' do
let(:user) { order.user }
@@ -28,16 +28,16 @@ describe CompleteOrdersWithBalanceQuery do
allow(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
expect(outstanding_balance).to receive(:call)
subject
result
end
it 'returns complete orders including their balance' do
order = subject.first
order = result.first
expect(order[:balance_value]).to eq(-1.0)
end
it 'sorts them by their completed_at with the most recent first' do
expect(subject.pluck(:id)).to eq([other_order.id, order.id])
expect(result.pluck(:id)).to eq([other_order.id, order.id])
end
end
@@ -48,11 +48,11 @@ describe CompleteOrdersWithBalanceQuery do
allow(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
expect(outstanding_balance).to receive(:call)
subject
result
end
it 'returns an empty array' do
expect(subject).to be_empty
expect(result).to be_empty
end
end
end

View File

@@ -3,7 +3,7 @@
require 'spec_helper'
describe CompleteVisibleOrdersQuery do
subject { described_class.new(order_permissions).call }
subject(:result) { described_class.new(order_permissions).call }
let(:filter_canceled) { false }
@@ -21,7 +21,7 @@ describe CompleteVisibleOrdersQuery do
let(:cart_order) { create(:order, distributor: enterprise) }
it 'does not return it' do
expect(subject).not_to include(cart_order)
expect(result).not_to include(cart_order)
end
end
@@ -29,13 +29,13 @@ describe CompleteVisibleOrdersQuery do
let(:complete_order) { create(:order, completed_at: 1.day.ago, distributor: enterprise) }
it 'does not return it' do
expect(subject).to include(complete_order)
expect(result).to include(complete_order)
end
end
it 'calls #visible_orders' do
expect(order_permissions).to receive(:visible_orders).and_call_original
subject
result
end
end
end

View File

@@ -3,7 +3,7 @@
require 'spec_helper'
describe CustomersWithBalanceQuery do
subject { described_class.new(Customer.where(id: customers)).call }
subject(:result) { described_class.new(Customer.where(id: customers)).call }
describe '#call' do
let(:customers) { create(:customer) }
@@ -15,7 +15,7 @@ describe CustomersWithBalanceQuery do
allow(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
expect(outstanding_balance).to receive(:statement)
subject
result
end
describe 'arguments' do
@@ -23,8 +23,8 @@ describe CustomersWithBalanceQuery do
let(:customers) { create_pair(:customer) }
it 'returns balance' do
expect(subject.pluck(:id).sort).to eq([customers.first.id, customers.second.id].sort)
expect(subject.map(&:balance_value)).to eq([0, 0])
expect(result.pluck(:id).sort).to eq([customers.first.id, customers.second.id].sort)
expect(result.map(&:balance_value)).to eq([0, 0])
end
end
@@ -32,7 +32,7 @@ describe CustomersWithBalanceQuery do
let(:customers) { Customer.none }
it 'returns empty customers collection' do
expect(subject).to eq([])
expect(result).to eq([])
end
end
end
@@ -44,7 +44,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(0)
end
end
@@ -56,7 +56,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(0)
end
end
@@ -69,7 +69,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(0)
end
end
@@ -81,7 +81,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(0)
end
end
@@ -95,7 +95,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(-total)
end
end
@@ -111,7 +111,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(payment_total - total)
end
end
@@ -133,7 +133,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(payment_total - non_canceled_orders_total)
end
end
@@ -149,7 +149,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(payment_total - total)
end
end
@@ -165,7 +165,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(payment_total - total)
end
end
@@ -181,7 +181,7 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(payment_total - total)
end
end
@@ -198,14 +198,14 @@ describe CustomersWithBalanceQuery do
end
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(payment_total - non_returned_orders_total)
end
end
context 'when there are no orders' do
it 'returns the customer balance' do
customer = subject.first
customer = result.first
expect(customer.balance_value).to eq(0)
end
end

View File

@@ -3,15 +3,15 @@
require 'spec_helper'
describe OutstandingBalanceQuery do
subject { described_class.new(relation) }
subject(:query) { described_class.new(relation) }
let(:result) { subject.call }
let(:result) { query.call }
describe '#statement' do
let(:relation) { Spree::Order.none }
it 'returns the CASE statement necessary to compute the order balance' do
normalized_sql_statement = normalize(subject.statement)
normalized_sql_statement = normalize(query.statement)
expect(normalized_sql_statement).to eq(normalize(<<-SQL.squish))
CASE WHEN "spree_orders"."state" IN ('canceled', 'returned') THEN "spree_orders"."payment_total"

View File

@@ -3,7 +3,7 @@
require 'spec_helper'
describe PaymentsRequiringActionQuery do
subject { described_class.new(user).call }
subject(:result) { described_class.new(user).call }
let(:user) { create(:user) }
let(:order) { create(:order, user:) }
@@ -18,7 +18,7 @@ describe PaymentsRequiringActionQuery do
end
it "finds the payment" do
expect(subject.all).to include(payment)
expect(result.all).to include(payment)
end
end
@@ -28,7 +28,7 @@ describe PaymentsRequiringActionQuery do
end
it "does not find the payment" do
expect(subject.all).not_to include(payment)
expect(result.all).not_to include(payment)
end
end
end