mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add spec to cover SQL query issue with OCs where the only products from the coordinator inventory are renderer
This commit is contained in:
@@ -7,8 +7,9 @@ describe ExchangeProductsRenderer do
|
||||
|
||||
describe "#exchange_products" do
|
||||
describe "for an incoming exchange" do
|
||||
let(:exchange) { order_cycle.exchanges.incoming.first }
|
||||
|
||||
it "loads products" do
|
||||
exchange = order_cycle.exchanges.incoming.first
|
||||
products = renderer.exchange_products(true, exchange.sender)
|
||||
|
||||
expect(products.first.supplier.name).to eq exchange.variants.first.product.supplier.name
|
||||
@@ -16,14 +17,34 @@ describe ExchangeProductsRenderer do
|
||||
end
|
||||
|
||||
describe "for an outgoing exchange" do
|
||||
let(:exchange) { order_cycle.exchanges.outgoing.first }
|
||||
|
||||
it "loads products" do
|
||||
exchange = order_cycle.exchanges.outgoing.first
|
||||
products = renderer.exchange_products(false, exchange.receiver)
|
||||
|
||||
suppliers = [exchange.variants[0].product.supplier.name, exchange.variants[1].product.supplier.name]
|
||||
expect(suppliers).to include products.first.supplier.name
|
||||
expect(suppliers).to include products.second.supplier.name
|
||||
end
|
||||
|
||||
context "showing products from coordinator inventory only" do
|
||||
before { order_cycle.update prefers_product_selection_from_coordinator_inventory_only: true }
|
||||
|
||||
it "loads no products if there are no products from the coordinator inventory" do
|
||||
products = renderer.exchange_products(false, exchange.receiver)
|
||||
|
||||
expect(products).to be_empty
|
||||
end
|
||||
|
||||
it "loads products from the coordinator inventory" do
|
||||
# Add variant already in the exchange to the coordinator's inventory
|
||||
exchange.variants.first.inventory_items = [create(:inventory_item, enterprise: order_cycle.coordinator)]
|
||||
|
||||
products = renderer.exchange_products(false, exchange.receiver)
|
||||
|
||||
expect(products).to eq [exchange.variants.first.product]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user