Skip to content

Commit

Permalink
fix: Dq saturated fat only if fat defined (#9463)
Browse files Browse the repository at this point in the history
dq_serving_size_cant_be_parsed
  • Loading branch information
benbenben2 committed Dec 5, 2023
1 parent 5ed2c36 commit 2a668c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/ProductOpener/DataQualityFood.pm
Expand Up @@ -1241,14 +1241,9 @@ sub check_nutrition_data ($product_ref) {
"en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars";
}

if (
(
(defined $product_ref->{nutriments}{"saturated-fat_100g"})
? $product_ref->{nutriments}{"saturated-fat_100g"}
: 0
)
> (((defined $product_ref->{nutriments}{"fat_100g"}) ? $product_ref->{nutriments}{"fat_100g"} : 0) + 0.001)
)
if ( (defined $product_ref->{nutriments}{"saturated-fat_100g"})
and (defined $product_ref->{nutriments}{"fat_100g"})
and ($product_ref->{nutriments}{"saturated-fat_100g"} > ($product_ref->{nutriments}{"fat_100g"} + 0.001)))
{

push @{$product_ref->{data_quality_errors_tags}}, "en:nutrition-saturated-fat-greater-than-fat";
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/dataqualityfood.t
Expand Up @@ -1018,6 +1018,31 @@ check_quality_and_test_product_has_quality_tag(
'1 kcal = 4.184 kJ, value in kcal is between 165*3.7-2=608.5 and 165*4.7+2=777.5', 1
);

# nutrition - saturated fat is greater than fat
## trigger the error because saturated-fat_100g is greated than fat
$product_ref = {
nutriments => {
fat_100g => 0,
"saturated-fat_100g" => 1,
}
};
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-saturated-fat-greater-than-fat',
'saturated fat greater than fat', 1
);
## if undefined fat, error should not be triggered
$product_ref = {
nutriments => {
"saturated-fat_100g" => 1,
}
};
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-saturated-fat-greater-than-fat',
'saturated fat may be greater than fat but fat is missing', 0
);

# category with expected nutriscore grade. Prerequisite: "expected_nutriscore_grade:en:c" under "en:Extra-virgin olive oils" category, in the taxonomy
# category with expected nutriscore grade. Different nutriscore grade as compared to the expected nutriscore grade
$product_ref = {
Expand Down

0 comments on commit 2a668c1

Please sign in to comment.