Skip to content

Commit

Permalink
Fix #bulk_product duplicate
Browse files Browse the repository at this point in the history
Remove duplicate when a product has mutiple variant in the same category
(taxon)
  • Loading branch information
rioug committed Apr 1, 2024
1 parent 678fa37 commit 100239c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/queries/product_scope_query.rb
Expand Up @@ -20,7 +20,7 @@ def bulk_products

product_query.
ransack(query_params_with_defaults).
result
result(distinct: true)
end

def find_product
Expand Down
30 changes: 23 additions & 7 deletions spec/queries/product_scope_query_spec.rb
Expand Up @@ -12,7 +12,7 @@

before { current_api_user.enterprise_roles.create(enterprise: supplier2) }

describe 'bulk update' do
describe '#bulk_products' do
let!(:product3) { create(:product, supplier: supplier2) }

it "returns a list of products" do
Expand All @@ -28,13 +28,29 @@
expect(subject).not_to include(product2, product3)
end

it "filters results by product category" do
subject = ProductScopeQuery
.new(current_api_user, { q: { variants_primary_taxon_id_eq: taxon.id } })
.bulk_products
describe "by variant category" do
it "filters results by product category" do
create(:variant, product: product2, primary_taxon: taxon)

subject = ProductScopeQuery
.new(current_api_user, { q: { variants_primary_taxon_id_eq: taxon.id } })
.bulk_products

expect(subject).to match_array([product, product2])
expect(subject).not_to include(product3)
end

expect(subject).to include(product, product2)
expect(subject).not_to include(product3)
context "with mutiple variant in the same category" do
it "doesn't duplicate products" do
create(:variant, product: product2, primary_taxon: taxon)

subject = ProductScopeQuery
.new(current_api_user, { q: { variants_primary_taxon_id_eq: taxon.id } })
.bulk_products

expect(subject).to match_array([product, product2])
end
end
end

it "filters results by import_date" do
Expand Down

0 comments on commit 100239c

Please sign in to comment.