From fbfda8d07f301e9a3782ab9bcd7993c783f6a618 Mon Sep 17 00:00:00 2001 From: benbenben2 <110821832+benbenben2@users.noreply.github.com> Date: Fri, 27 Dec 2024 17:11:15 +0100 Subject: [PATCH 1/6] feat-update-product-type --- lib/ProductOpener/Products.pm | 80 ++ taxonomies/beauty/categories.txt | 1254 +++++++++++++++-------------- taxonomies/food/categories.txt | 302 ++----- taxonomies/petfood/categories.txt | 121 ++- taxonomies/product/categories.txt | 25 + tests/unit/products.t | 30 + 6 files changed, 938 insertions(+), 874 deletions(-) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index f441518b62509..75a6c63ee9c0c 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -2955,6 +2955,83 @@ sub compute_languages ($product_ref) { return; } +=head2 review_product_type ( $product_ref ) + +Reviews the product type based on the presence of specific tags in the categories field. +Updates the product type if necessary. + +=head3 Arguments + +=head4 Product reference $product_ref + +A reference to a hash containing the product details. + +=cut + +sub review_product_type ($product_ref) { + + my $error; + + if ($product_ref->{product_type} eq "beauty") { + if (has_tag($product_ref, "categories", "en:non-beauty-products")) { + if (has_tag($product_ref, "categories", "en:open-food-facts")) { + $error = change_product_type($product_ref, "food"); + } + elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { + $error = change_product_type($product_ref, "petfood"); + } + elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { + $error = change_product_type($product_ref, "product"); + } + } + } + elsif ($product_ref->{product_type} eq "food") { + if (has_tag($product_ref, "categories", "en:non-food-products")) { + if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { + $error = change_product_type($product_ref, "beauty"); + } + elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { + $error = change_product_type($product_ref, "petfood"); + } + elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { + $error = change_product_type($product_ref, "product"); + } + } + } + elsif ($product_ref->{product_type} eq "petfood") { + if (has_tag($product_ref, "categories", "en:non-pet-food-products")) { + if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { + $error = change_product_type($product_ref, "beauty"); + } + elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { + $error = change_product_type($product_ref, "food"); + } + elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { + $error = change_product_type($product_ref, "product"); + } + } + } + elsif ($product_ref->{product_type} eq "product") { + if (has_tag($product_ref, "categories", "en:non-food-products")) { + if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { + $error = change_product_type($product_ref, "beauty"); + } + elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { + $error = change_product_type($product_ref, "food"); + } + elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { + $error = change_product_type($product_ref, "petfood"); + } + } + } + + if ($error) { + $log->error("review_product_type - error", {error => $error, product_ref => $product_ref}); + } + + return; +} + =head2 process_product_edit_rules ($product_ref) Process the edit_rules (see C<@edit_rules> in in Config file). @@ -3678,6 +3755,9 @@ sub analyze_and_enrich_product_data ($product_ref, $response_ref) { compute_languages($product_ref); # need languages for allergens detection and cleaning ingredients + # change the product type of non-food categorized products (issue #11094) + review_product_type($product_ref); + # Run special analysis, score calculations that it specific to the product type if (($options{product_type} eq "food")) { diff --git a/taxonomies/beauty/categories.txt b/taxonomies/beauty/categories.txt index 1f215a51b4837..8ed1145eec6e3 100644 --- a/taxonomies/beauty/categories.txt +++ b/taxonomies/beauty/categories.txt @@ -1,810 +1,830 @@ -stopwords:fr:aux,au,de,le,du,la,a,et,avec,pour - -synonyms:en:flavoured,flavored +stopwords:fr: aux, au, de, le, du, la, a, et, avec, pour + +synonyms:en: flavoured, flavored + +en: Non beauty products +bg: Некозметични продукти +ca: Productes no de bellesa +de: Non-Beauty-Produkte, Non Beauty Produkte +es: Productos no de belleza +fi: ei kauneustuote +fr: Non beauté +hr: Neprehrambeni proizvodi za ljepotu +it: Prodotti non di bellezza +nl: Non-beauty +pt: Produtos não de beleza +ru: Непродукты для красоты, Не косметические продукты + +< en:Non beauty products +en: Open Food Facts, OFF +xx: Open Food Facts, OFF + +< en:Non beauty products +en: Open Pet Food Facts, OFF +xx: Open Pet Food Facts, OFF + +< en:Non beauty products +en: Open Products Facts, OPF +xx: Open Products Facts, OPF ###### CATEGORIE HYGIENE -en:Hygiene -fr:Hygiène -nl:Hygiëne +en: Hygiene +fr: Hygiène +nl: Hygiëne - ['en:non-food-products', 'en:open-pet-food-facts'], + product_type => 'food' +}; +ProductOpener::Products::review_product_type($product_ref); +is($product_ref->{product_type}, 'petfood'); +# beauty to product +$product_ref = { + categories_tags => ['en:non-beauty-products', 'en:open-products-facts'], + product_type => 'beauty' +}; +ProductOpener::Products::review_product_type($product_ref); +is($product_ref->{product_type}, 'product'); +# food to beauty AND product -> move to beauty (handled by alphabetical order) +$product_ref = { + categories_tags => ['en:non-food-products', 'en:open-beauty-facts', 'en:open-products-facts'], + product_type => 'food' +}; +ProductOpener::Products::review_product_type($product_ref); +is($product_ref->{product_type}, 'beauty'); +# rerun same test based on result of previous test should not do anything (missing tag "en:non-beauty-products") +$product_ref = { + categories_tags => ['en:non-food-products', 'en:open-beauty-facts', 'en:open-products-facts'], + product_type => 'beauty' +}; +ProductOpener::Products::review_product_type($product_ref); +is($product_ref->{product_type}, 'beauty'); + done_testing(); From a399c675a9f8df7f4906269a9a6b68fca272c0ab Mon Sep 17 00:00:00 2001 From: benbenben2 <110821832+benbenben2@users.noreply.github.com> Date: Fri, 27 Dec 2024 21:48:35 +0100 Subject: [PATCH 2/6] rm pet-fodd from config_off --- lib/ProductOpener/Config_off.pm | 1 - taxonomies/food/categories.txt | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ProductOpener/Config_off.pm b/lib/ProductOpener/Config_off.pm index 3203e05c0674a..82de5ee245f3b 100644 --- a/lib/ProductOpener/Config_off.pm +++ b/lib/ProductOpener/Config_off.pm @@ -613,7 +613,6 @@ $options{categories_exempted_from_nutriscore} = [ en:spices en:sugar-substitutes en:vinegars - en:pet-food en:non-food-products ) ]; diff --git a/taxonomies/food/categories.txt b/taxonomies/food/categories.txt index a5cf9e0ca5bfa..a38128098aa08 100644 --- a/taxonomies/food/categories.txt +++ b/taxonomies/food/categories.txt @@ -100,8 +100,8 @@ en: Open Beauty Facts, OBF, Cosmetics, Hygiene xx: Open Beauty Facts, OBF < en:Non food products -en: Open Pet Food Facts, OPFF -xx: Open Pet Food Facts, OPFF +en: Open Pet Food Facts, OPFF, pet food +xx: Open Pet Food Facts, OPFF, pet food < en:Non food products en: Open Products Facts, OPF From a6f204346416615ce55b92f658faeae4e45f3f96 Mon Sep 17 00:00:00 2001 From: benbenben2 <110821832+benbenben2@users.noreply.github.com> Date: Sat, 4 Jan 2025 21:34:26 +0100 Subject: [PATCH 3/6] apply suggestions --- lib/ProductOpener/Products.pm | 76 ++++++++++++++----------------- taxonomies/beauty/categories.txt | 14 ++++++ taxonomies/food/categories.txt | 16 ++++++- taxonomies/petfood/categories.txt | 18 +++++++- taxonomies/product/categories.txt | 14 ++++++ tests/unit/products.t | 4 +- 6 files changed, 96 insertions(+), 46 deletions(-) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index 75a6c63ee9c0c..b86109e1d8dd8 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -2973,55 +2973,47 @@ sub review_product_type ($product_ref) { my $error; if ($product_ref->{product_type} eq "beauty") { - if (has_tag($product_ref, "categories", "en:non-beauty-products")) { - if (has_tag($product_ref, "categories", "en:open-food-facts")) { - $error = change_product_type($product_ref, "food"); - } - elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { - $error = change_product_type($product_ref, "petfood"); - } - elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { - $error = change_product_type($product_ref, "product"); - } + if (has_tag($product_ref, "categories", "en:open-food-facts")) { + $error = change_product_type($product_ref, "food"); + } + elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { + $error = change_product_type($product_ref, "petfood"); + } + elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { + $error = change_product_type($product_ref, "product"); } } elsif ($product_ref->{product_type} eq "food") { - if (has_tag($product_ref, "categories", "en:non-food-products")) { - if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { - $error = change_product_type($product_ref, "beauty"); - } - elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { - $error = change_product_type($product_ref, "petfood"); - } - elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { - $error = change_product_type($product_ref, "product"); - } + if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { + $error = change_product_type($product_ref, "beauty"); + } + elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { + $error = change_product_type($product_ref, "petfood"); + } + elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { + $error = change_product_type($product_ref, "product"); } } elsif ($product_ref->{product_type} eq "petfood") { - if (has_tag($product_ref, "categories", "en:non-pet-food-products")) { - if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { - $error = change_product_type($product_ref, "beauty"); - } - elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { - $error = change_product_type($product_ref, "food"); - } - elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { - $error = change_product_type($product_ref, "product"); - } + if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { + $error = change_product_type($product_ref, "beauty"); + } + elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { + $error = change_product_type($product_ref, "food"); + } + elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { + $error = change_product_type($product_ref, "product"); } } elsif ($product_ref->{product_type} eq "product") { - if (has_tag($product_ref, "categories", "en:non-food-products")) { - if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { - $error = change_product_type($product_ref, "beauty"); - } - elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { - $error = change_product_type($product_ref, "food"); - } - elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { - $error = change_product_type($product_ref, "petfood"); - } + if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { + $error = change_product_type($product_ref, "beauty"); + } + elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { + $error = change_product_type($product_ref, "food"); + } + elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { + $error = change_product_type($product_ref, "petfood"); } } @@ -3756,7 +3748,9 @@ sub analyze_and_enrich_product_data ($product_ref, $response_ref) { compute_languages($product_ref); # need languages for allergens detection and cleaning ingredients # change the product type of non-food categorized products (issue #11094) - review_product_type($product_ref); + if (has_tag($product_ref, "categories", "en:incorrect-product-type")) { + review_product_type($product_ref); + } # Run special analysis, score calculations that it specific to the product type diff --git a/taxonomies/beauty/categories.txt b/taxonomies/beauty/categories.txt index 8ed1145eec6e3..d541f7aed9cd9 100644 --- a/taxonomies/beauty/categories.txt +++ b/taxonomies/beauty/categories.txt @@ -2,6 +2,20 @@ stopwords:fr: aux, au, de, le, du, la, a, et, avec, pour synonyms:en: flavoured, flavored +en: Incorrect product type +bg: Неправилен product type +ca: Tipus de producte incorrecte +de: Falscher product type +es: Tipo de producto incorrecto +fi: Väärä product type +fr: Mauvais product type +hr: Pogrešan product type +it: Tipo di prodotto errato +nl: Verkeerd product type +pt: Tipo de produto incorreto +ru: Неправильный product type + +< en: Incorrect product type en: Non beauty products bg: Некозметични продукти ca: Productes no de bellesa diff --git a/taxonomies/food/categories.txt b/taxonomies/food/categories.txt index a38128098aa08..e3e3863aba4ec 100644 --- a/taxonomies/food/categories.txt +++ b/taxonomies/food/categories.txt @@ -82,6 +82,20 @@ stopwords:de: und, mit, von # Careful: it should be the same main tag, not a synonym # Remark: add the property to the highest parent +en: Incorrect product type +bg: Неправилен product type +ca: Tipus de producte incorrecte +de: Falscher product type +es: Tipo de producto incorrecto +fi: Väärä product type +fr: Mauvais product type +hr: Pogrešan product type +it: Tipo di prodotto errato +nl: Verkeerd product type +pt: Tipo de produto incorreto +ru: Неправильный product type + +< en: Incorrect product type en: Non food products bg: Нехранителни продукти ca: Productes no alimentaris @@ -131,7 +145,7 @@ tr: Deterjan wikidata:en: Q334637 # REAL Cigarettes -< en:Non food products +< en:Open Products Facts en: Cigarettes bg: Цигари de: Zigaretten diff --git a/taxonomies/petfood/categories.txt b/taxonomies/petfood/categories.txt index 642f51ed62828..4f74a6944ee31 100755 --- a/taxonomies/petfood/categories.txt +++ b/taxonomies/petfood/categories.txt @@ -1,3 +1,17 @@ +en: Incorrect product type +bg: Неправилен product type +ca: Tipus de producte incorrecte +de: Falscher product type +es: Tipo de producto incorrecto +fi: Väärä product type +fr: Mauvais product type +hr: Pogrešan product type +it: Tipo di prodotto errato +nl: Verkeerd product type +pt: Tipo de produto incorreto +ru: Неправильный product type + +< en: Incorrect product type en: Non pet food products bg: Непродукти за храна за домашни любимци ca: Productes no alimentaris per a mascotes @@ -123,8 +137,8 @@ de: Kastriertes Katzenfutter, Futter für kastrierte und sterilisierte Katzen, F es: Comida para gatos castrados fr: Nourriture pour chats castrés, Nourriture pour chat castré hr: Hrana za kastrirane mačke -nl: Kattenvoer -nl_be: Kattenvoer +nl: Voer voor gecastreerde katten +nl_be: Voer voor gecastreerde katten ru: корм для кастрированных кошек < en:dog and cat food diff --git a/taxonomies/product/categories.txt b/taxonomies/product/categories.txt index 5a08130fc97d7..3d2e56ed27999 100644 --- a/taxonomies/product/categories.txt +++ b/taxonomies/product/categories.txt @@ -5,6 +5,20 @@ # - carbon_impact_fr_impactco2:en: co2 equivalent in kg per unit (1 product) from https://impactco2.fr/ # - carbon_impact_fr_impactco2_link:en: URL for the category on https://impactco2.fr/ +en: Incorrect product type +bg: Неправилен product type +ca: Tipus de producte incorrecte +de: Falscher product type +es: Tipo de producto incorrecto +fi: Väärä product type +fr: Mauvais product type +hr: Pogrešan product type +it: Tipo di prodotto errato +nl: Verkeerd product type +pt: Tipo de produto incorreto +ru: Неправильный product type + +< en: Incorrect product type en: Non open products facts bg: Неприложими open products facts, Неприложими факти за неотворени продукти ca: No open products facts diff --git a/tests/unit/products.t b/tests/unit/products.t index 82ebfebcc7824..91118ca877690 100644 --- a/tests/unit/products.t +++ b/tests/unit/products.t @@ -376,12 +376,12 @@ $product_ref = { }; ProductOpener::Products::review_product_type($product_ref); is($product_ref->{product_type}, 'beauty'); -# rerun same test based on result of previous test should not do anything (missing tag "en:non-beauty-products") +# rerun same test based on result of previous test, will now move to products $product_ref = { categories_tags => ['en:non-food-products', 'en:open-beauty-facts', 'en:open-products-facts'], product_type => 'beauty' }; ProductOpener::Products::review_product_type($product_ref); -is($product_ref->{product_type}, 'beauty'); +is($product_ref->{product_type}, 'product'); done_testing(); From aca642225262a992c2ec26d250740deaa88a26f2 Mon Sep 17 00:00:00 2001 From: benbenben2 <110821832+benbenben2@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:20:10 +0100 Subject: [PATCH 4/6] apply really suggestions --- lib/ProductOpener/Products.pm | 52 ++++++++--------------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index b86109e1d8dd8..6a598c50611da 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -2972,49 +2972,21 @@ sub review_product_type ($product_ref) { my $error; - if ($product_ref->{product_type} eq "beauty") { - if (has_tag($product_ref, "categories", "en:open-food-facts")) { - $error = change_product_type($product_ref, "food"); - } - elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { - $error = change_product_type($product_ref, "petfood"); - } - elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { - $error = change_product_type($product_ref, "product"); - } + my $expected_type; + if (has_tag($product_ref, "categories", "en:open-food-facts")) { + $expected_type = "food"; } - elsif ($product_ref->{product_type} eq "food") { - if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { - $error = change_product_type($product_ref, "beauty"); - } - elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { - $error = change_product_type($product_ref, "petfood"); - } - elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { - $error = change_product_type($product_ref, "product"); - } + elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { + $expected_type = "petfood"; } - elsif ($product_ref->{product_type} eq "petfood") { - if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { - $error = change_product_type($product_ref, "beauty"); - } - elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { - $error = change_product_type($product_ref, "food"); - } - elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { - $error = change_product_type($product_ref, "product"); - } + elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { + $expected_type = "product"; } - elsif ($product_ref->{product_type} eq "product") { - if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { - $error = change_product_type($product_ref, "beauty"); - } - elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { - $error = change_product_type($product_ref, "food"); - } - elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { - $error = change_product_type($product_ref, "petfood"); - } + elsif (has_tag($product_ref, "categories", "en:open-beauty-facts")) { + $expected_type = "beauty"; + } + if ($expected_type and ($product_ref->{product_type} ne expected_type)) { + $error = change_product_type($product_ref, expected_type); } if ($error) { From faf4b3b671b4c36f6c0503e6951fe52d41bde7dd Mon Sep 17 00:00:00 2001 From: benbenben2 <110821832+benbenben2@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:53:25 +0100 Subject: [PATCH 5/6] missing $ --- lib/ProductOpener/Products.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index 6a598c50611da..95a644a3141e3 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -2985,8 +2985,8 @@ sub review_product_type ($product_ref) { elsif (has_tag($product_ref, "categories", "en:open-beauty-facts")) { $expected_type = "beauty"; } - if ($expected_type and ($product_ref->{product_type} ne expected_type)) { - $error = change_product_type($product_ref, expected_type); + if ($expected_type and ($product_ref->{product_type} ne $expected_type)) { + $error = change_product_type($product_ref, $expected_type); } if ($error) { From 8b23765c85f857974ae3b36518a718632f741392 Mon Sep 17 00:00:00 2001 From: benbenben2 <110821832+benbenben2@users.noreply.github.com> Date: Wed, 8 Jan 2025 04:29:47 +0100 Subject: [PATCH 6/6] reorder conditions, improve tests code --- lib/ProductOpener/Products.pm | 10 ++++++---- tests/unit/products.t | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index 95a644a3141e3..40b84afdc071d 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -96,6 +96,7 @@ BEGIN { &compute_completeness_and_missing_tags &compute_product_history_and_completeness &compute_languages + &review_product_type &compute_changes_diff_text &compute_data_sources &compute_sort_keys @@ -2973,7 +2974,10 @@ sub review_product_type ($product_ref) { my $error; my $expected_type; - if (has_tag($product_ref, "categories", "en:open-food-facts")) { + if (has_tag($product_ref, "categories", "en:open-beauty-facts")) { + $expected_type = "beauty"; + } + elsif (has_tag($product_ref, "categories", "en:open-food-facts")) { $expected_type = "food"; } elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) { @@ -2982,9 +2986,7 @@ sub review_product_type ($product_ref) { elsif (has_tag($product_ref, "categories", "en:open-products-facts")) { $expected_type = "product"; } - elsif (has_tag($product_ref, "categories", "en:open-beauty-facts")) { - $expected_type = "beauty"; - } + if ($expected_type and ($product_ref->{product_type} ne $expected_type)) { $error = change_product_type($product_ref, $expected_type); } diff --git a/tests/unit/products.t b/tests/unit/products.t index 91118ca877690..90d49b68caaa3 100644 --- a/tests/unit/products.t +++ b/tests/unit/products.t @@ -6,6 +6,7 @@ use utf8; use Test2::V0; use Data::Dumper; $Data::Dumper::Terse = 1; +$Data::Dumper::Sortkeys = 1; use Log::Any::Adapter 'TAP'; use ProductOpener::Products qw/:all/; @@ -357,31 +358,30 @@ is(split_code("26153689"), "000/002/615/3689"); # test review_product_type, to migrate product in other flavor if category tag is provided # food to pet food $product_ref = { - categories_tags => ['en:non-food-products', 'en:open-pet-food-facts'], + categories_tags => ['en:incorrect-product-type', 'en:non-food-products', 'en:open-pet-food-facts'], product_type => 'food' }; -ProductOpener::Products::review_product_type($product_ref); -is($product_ref->{product_type}, 'petfood'); +review_product_type($product_ref); +is($product_ref->{product_type}, 'petfood') || diag Dumper $product_ref; # beauty to product $product_ref = { - categories_tags => ['en:non-beauty-products', 'en:open-products-facts'], + categories_tags => ['en:incorrect-product-type', 'en:non-beauty-products', 'en:open-products-facts'], product_type => 'beauty' }; -ProductOpener::Products::review_product_type($product_ref); -is($product_ref->{product_type}, 'product'); +review_product_type($product_ref); +is($product_ref->{product_type}, 'product') || diag Dumper $product_ref; # food to beauty AND product -> move to beauty (handled by alphabetical order) $product_ref = { - categories_tags => ['en:non-food-products', 'en:open-beauty-facts', 'en:open-products-facts'], + categories_tags => + ['en:incorrect-product-type', 'en:non-food-products', 'en:open-beauty-facts', 'en:open-products-facts'], product_type => 'food' }; -ProductOpener::Products::review_product_type($product_ref); -is($product_ref->{product_type}, 'beauty'); -# rerun same test based on result of previous test, will now move to products -$product_ref = { - categories_tags => ['en:non-food-products', 'en:open-beauty-facts', 'en:open-products-facts'], - product_type => 'beauty' -}; -ProductOpener::Products::review_product_type($product_ref); -is($product_ref->{product_type}, 'product'); +review_product_type($product_ref); +is($product_ref->{product_type}, 'beauty') || diag Dumper $product_ref; +# rerun same test based on result of previous test, +# will remain beauty because has tag beauty is evaluated first +# and tag remains after migration +review_product_type($product_ref); +is($product_ref->{product_type}, 'beauty') || diag Dumper $product_ref; done_testing();