Add spec to test the correct customer is linked

This commit is contained in:
Gaetan Craig-Riou
2026-03-10 13:57:16 +11:00
parent fe00d1f813
commit bca5ee226d

View File

@@ -39,6 +39,21 @@ RSpec.describe EnterprisesController do
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to be_nil
end
context "when customer doesn't belong to the order's distributor" do
it "sets the order's customer to distributor's customer" do
expected_customer = create(:customer, user:, enterprise: distributor)
# Make sure the order is linked to a customer
customer = create(:customer)
order.customer = customer
order.save!
expect do
get :shop, params: { id: distributor }
end.to change { controller.current_order.customer }.to(expected_customer)
end
end
end
it "sorts order cycles by the distributor's preferred ordering attr" do