From b7fe2b28c1e3d5ab992976920046cbaae5032738 Mon Sep 17 00:00:00 2001 From: benbenben2 <110821832+benbenben2@users.noreply.github.com> Date: Wed, 15 Nov 2023 09:39:56 +0100 Subject: [PATCH] feat: add dq error for product quantity above 30kg (#9316) * add dq error for product quantity above 30kg * make lint * fix missing parent error --- lib/ProductOpener/DataQualityFood.pm | 4 ++++ taxonomies/data_quality.txt | 10 +++++++- tests/unit/dataqualityfood.t | 36 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/ProductOpener/DataQualityFood.pm b/lib/ProductOpener/DataQualityFood.pm index 04eb2c08fbbd3..1fbdad9f34a10 100644 --- a/lib/ProductOpener/DataQualityFood.pm +++ b/lib/ProductOpener/DataQualityFood.pm @@ -1298,6 +1298,10 @@ sub check_quantity ($product_ref) { if ((defined $product_ref->{product_quantity}) and ($product_ref->{product_quantity} ne "")) { if ($product_ref->{product_quantity} > 10 * 1000) { push @{$product_ref->{data_quality_warnings_tags}}, "en:product-quantity-over-10kg"; + + if ($product_ref->{product_quantity} > 30 * 1000) { + push @{$product_ref->{data_quality_errors_tags}}, "en:product-quantity-over-30kg"; + } } if ($product_ref->{product_quantity} < 1) { push @{$product_ref->{data_quality_warnings_tags}}, "en:product-quantity-under-1g"; diff --git a/taxonomies/data_quality.txt b/taxonomies/data_quality.txt index 692d123f16925..36f47a0c4679f 100644 --- a/taxonomies/data_quality.txt +++ b/taxonomies/data_quality.txt @@ -2794,6 +2794,14 @@ description:en:Compared to the category average, the Sugars value is abnormally ### Quantity and serving + "123456789",}; +check_quality_and_test_product_has_quality_tag( + $product_ref, + 'en:product-quantity-over-10kg', + 'raise warning because the product quantity is above 10000g', 1 +); +check_quality_and_test_product_has_quality_tag( + $product_ref, + 'en:product-quantity-over-30kg', + 'raise error because the product quantity is above 30000g', 1 +); +# product quantity warnings and errors +$product_ref = {product_quantity => "20000",}; +check_quality_and_test_product_has_quality_tag( + $product_ref, + 'en:product-quantity-over-10kg', + 'raise warning because the product quantity is above 10000g', 1 +); +check_quality_and_test_product_has_quality_tag( + $product_ref, + 'en:product-quantity-over-30kg', + 'raise error because the product quantity is above 30000g', 0 +); +$product_ref = { + product_quantity => "0.001", + quantity => "1 mg", +}; +check_quality_and_test_product_has_quality_tag( + $product_ref, + 'en:product-quantity-under-1g', + 'raise warning because the product quantity is under 1g', 1 +); +check_quality_and_test_product_has_quality_tag($product_ref, 'en:product-quantity-in-mg', + 'raise warning because the product quantity is in mg', 1); + done_testing();