Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add data quality warning for serving size without digit #8057

7 changes: 7 additions & 0 deletions lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,13 @@ sub check_nutrition_data ($product_ref) {
"en:nutrition-data-prepared-without-category-dried-products-to-be-rehydrated";
}
}

if ( (defined $product_ref->{serving_size})
and ($product_ref->{serving_size} ne "")
and ($product_ref->{serving_size} !~ /\d/))
{
push @{$product_ref->{data_quality_errors_tags}}, "en:serving-size-is-missing-digits";
}
if ( $nutrition_data
and (defined $product_ref->{nutrition_data_per})
and ($product_ref->{nutrition_data_per} eq 'serving'))
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/dataqualityfood.t
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,20 @@ check_quality_and_test_product_has_quality_tag(
'nutriment should have positive value (except nutrition-score)', 0
);

# serving size should contains digits
$product_ref = {serving_size => "serving_size"};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:serving-size-is-missing-digits',
'serving size should contains digits', 1
);
$product_ref = {serving_size => "120g"};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:serving-size-is-missing-digits',
'serving size should contains digits', 0
);

done_testing();