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

fix: Dq saturated fat only if fat defined #9463

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1245,14 +1245,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
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,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
Loading