mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding specs for orders by ditributor query
This commit is contained in:
@@ -79,4 +79,43 @@ describe Spree.user_class do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "retrieving orders for /account page" do
|
||||
let!(:u1) { create(:user) }
|
||||
let!(:u2) { create(:user) }
|
||||
let!(:distributor1) { create(:distributor_enterprise) }
|
||||
let!(:distributor2) { create(:distributor_enterprise) }
|
||||
let!(:d1o1) { create(:completed_order_with_totals, distributor: distributor1, user_id: u1.id)}
|
||||
let!(:d1o2) { create(:completed_order_with_totals, distributor: distributor1, user_id: u1.id)}
|
||||
let!(:d1_order_for_u2) { create(:completed_order_with_totals, distributor: distributor1, user_id: u2.id)}
|
||||
let!(:d1o3) { create(:order, state: 'cart', distributor: distributor1, user_id: u1.id)}
|
||||
let!(:d2o1) { create(:completed_order_with_totals, distributor: distributor2, user_id: u2.id)}
|
||||
|
||||
let!(:completed_payment) { create(:payment, order: d1o1, state: 'completed')}
|
||||
let!(:payment) { create(:payment, order: d1o2, state: 'invalid')}
|
||||
|
||||
it "returns enterprises that the user has ordered from" do
|
||||
expect(u1.enterprises_ordered_from).to eq [distributor1.id]
|
||||
end
|
||||
|
||||
it "returns orders and payments for the user, organised by distributor" do
|
||||
expect(u1.orders_by_distributor).to include distributor1
|
||||
expect(u1.orders_by_distributor.first.distributed_orders).to include d1o1
|
||||
end
|
||||
|
||||
it "doesn't return irrelevant distributors" do
|
||||
expect(u1.orders_by_distributor).not_to include distributor2
|
||||
end
|
||||
it "doesn't return other users' orders" do
|
||||
expect(u1.orders_by_distributor.first.distributed_orders).not_to include d1_order_for_u2
|
||||
end
|
||||
|
||||
it "doesn't return uncompleted orders" do
|
||||
expect(u1.orders_by_distributor.first.distributed_orders).not_to include d1o3
|
||||
end
|
||||
|
||||
it "doesn't return uncompleted payments" do
|
||||
expect(u1.orders_by_distributor.first.distributed_orders.map{|o| o.payments}.flatten).not_to include payment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user