mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-24 05:38:52 +00:00
Test customer balance query with guest orders
Guest orders also have an associated customer record that is created by Spree::Order#ensure_customer at checkout. Subsequent orders will use that one due to Spree::Order#associate_customer.
This commit is contained in:
@@ -9,7 +9,7 @@ FactoryBot.define do
|
||||
user
|
||||
bill_address
|
||||
completed_at { nil }
|
||||
email { user.email }
|
||||
email { user&.email || customer.email }
|
||||
|
||||
factory :order_with_totals do
|
||||
after(:create) do |order|
|
||||
|
||||
@@ -12,14 +12,28 @@ describe CustomersWithBalance do
|
||||
let(:total) { 200.00 }
|
||||
let(:order_total) { 100.00 }
|
||||
|
||||
before do
|
||||
create(:order, customer: customer, total: order_total, payment_total: 0)
|
||||
create(:order, customer: customer, total: order_total, payment_total: 0)
|
||||
context 'when non-guest order' do
|
||||
before do
|
||||
create(:order, customer: customer, total: order_total, payment_total: 0)
|
||||
create(:order, customer: customer, total: order_total, payment_total: 0)
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(-total)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(-total)
|
||||
context 'when guest order' do
|
||||
before do
|
||||
create(:order, customer: customer, user: nil, total: order_total, payment_total: 0)
|
||||
create(:order, customer: customer, user: nil, total: order_total, payment_total: 0)
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(-total)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,14 +42,34 @@ describe CustomersWithBalance do
|
||||
let(:order_total) { 100.00 }
|
||||
let(:payment_total) { order_total }
|
||||
|
||||
before do
|
||||
create(:order, customer: customer, total: order_total, payment_total: 0)
|
||||
create(:order, customer: customer, total: order_total, payment_total: payment_total)
|
||||
context 'when non-guest order' do
|
||||
before do
|
||||
create(:order, customer: customer, total: order_total, payment_total: 0)
|
||||
create(:order, customer: customer, total: order_total, payment_total: payment_total)
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(payment_total - total)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(payment_total - total)
|
||||
context 'when guest order' do
|
||||
before do
|
||||
create(:order, customer: customer, user: nil, total: order_total, payment_total: 0)
|
||||
create(
|
||||
:order,
|
||||
customer: customer,
|
||||
user: nil,
|
||||
total: order_total,
|
||||
payment_total: payment_total
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(payment_total - total)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,17 +79,44 @@ describe CustomersWithBalance do
|
||||
let(:payment_total) { 100.00 }
|
||||
let(:complete_orders_total) { order_total }
|
||||
|
||||
before do
|
||||
create(:order, customer: customer, total: order_total, payment_total: 0)
|
||||
create(
|
||||
:order,
|
||||
customer: customer,
|
||||
total: order_total,
|
||||
payment_total: order_total,
|
||||
state: 'canceled'
|
||||
)
|
||||
context 'when non-guest order' do
|
||||
before do
|
||||
create(:order, customer: customer, total: order_total, payment_total: 0)
|
||||
create(
|
||||
:order,
|
||||
customer: customer,
|
||||
total: order_total,
|
||||
payment_total: order_total,
|
||||
state: 'canceled'
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(payment_total - complete_orders_total)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when guest order' do
|
||||
before do
|
||||
create(:order, customer: customer, user: nil, total: order_total, payment_total: 0)
|
||||
create(
|
||||
:order,
|
||||
customer: customer,
|
||||
user: nil,
|
||||
total: order_total,
|
||||
payment_total: order_total,
|
||||
state: 'canceled'
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(payment_total - complete_orders_total)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = customers_with_balance.query.first
|
||||
expect(customer.balance_value).to eq(payment_total - complete_orders_total)
|
||||
|
||||
Reference in New Issue
Block a user