Fix exchange products renderer and specs

This commit is contained in:
Gaetan Craig-Riou
2024-03-05 16:53:46 +11:00
parent 04fb49bc25
commit a873fa692b
2 changed files with 11 additions and 9 deletions

View File

@@ -30,7 +30,7 @@ class ExchangeProductsRenderer
end
def supplied_products(enterprises_query_matcher)
products_relation = Spree::Product.where(supplier_id: enterprises_query_matcher).order(:name)
products_relation = Spree::Product.in_supplier(enterprises_query_matcher).order(:name)
filter_visible(products_relation)
end
@@ -95,7 +95,7 @@ class ExchangeProductsRenderer
return enterprises if enterprises.empty?
enterprises.includes(
supplied_products: [:supplier, :variants, :image]
supplied_products: [{ variants: :supplier }, :image]
)
end
end

View File

@@ -14,7 +14,9 @@ RSpec.describe ExchangeProductsRenderer do
it "loads products" do
products = renderer.exchange_products(true, exchange.sender)
expect(products.first.supplier.name).to eq exchange.variants.first.product.supplier.name
expect(products.first.variants.first.supplier.name).to eq(
exchange.variants.first.supplier.name
)
end
it "loads products in order" do
@@ -31,10 +33,10 @@ RSpec.describe ExchangeProductsRenderer do
it "loads products" do
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
suppliers = [exchange.variants[0].supplier.name,
exchange.variants[1].supplier.name]
expect(suppliers).to include products.first.variants.first.supplier.name
expect(suppliers).to include products.second.variants.first.supplier.name
end
it "loads products in order" do
@@ -74,8 +76,8 @@ RSpec.describe ExchangeProductsRenderer do
exchange = order_cycle.exchanges.incoming.first
variants = renderer.exchange_variants(true, exchange.sender)
expect(variants.first.product.supplier.name)
.to eq exchange.variants.first.product.supplier.name
expect(variants.first.supplier.name)
.to eq exchange.variants.first.supplier.name
end
describe "when OC is showing only the coordinators inventory" do