-
-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add unit to output of /cgi/nutrients.pl (#9751)
with API documentation and tests.
- Loading branch information
1 parent
03721b6
commit fd02df6
Showing
10 changed files
with
2,666 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$ref: ../schemas/nutrients.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
description: | | ||
The unit in which the nutrient for 100g or per serving is measured. | ||
The possible values depends on the nutrient. | ||
* `g` for grams | ||
* `mg` for milligrams | ||
* `μg` for micrograms | ||
* `cl` for centiliters | ||
* `ml` for mililiters | ||
* `dv` for recommended daily intakes (aka [Dietary Reference Intake](https://en.wikipedia.org/wiki/Dietary_Reference_Intake)) | ||
* `% vol` for percentage per volume (e.g. alcohol vol per 100 ml) | ||
* `%` for percentage | ||
🤓 code: see the [Units module][units-module], | ||
and [Food:default_unit_for_nid function][default-unit] | ||
[units-module]: https://openfoodfacts.github.io/openfoodfacts-server/dev/ref-perl-pod/ProductOpener/Units.html | ||
[default-unit]: https://openfoodfacts.github.io/openfoodfacts-server/dev/ref-perl-pod/ProductOpener/Food.html#default_unit_for_nid_(_%24nid) | ||
type: string | ||
enum: ['g','mg','μg','cl','ml','dv','% vol','%'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
type: array | ||
description: | | ||
Nutrients and sub-nutrients of a product, with their name and default unit. | ||
items: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
description: id of the nutrient | ||
name: | ||
type: string | ||
description: Name of the nutrient in the requested language | ||
important: | ||
type: boolean | ||
description: Indicates if the nutrient is always shown on the nutrition facts table | ||
display_in_edit_form: | ||
type: boolean | ||
description: Indicates if the nutrient should be shown in the nutrition facts edit form | ||
unit: | ||
description: Default unit of the nutrient | ||
$ref: "./nutrient_unit.yaml" | ||
nutrients: | ||
description: | | ||
Sub-nutrients (e.g. saturated-fat is a sub-nutrient of fat). | ||
# self recursive | ||
$ref: "#/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/perl -w | ||
|
||
use ProductOpener::PerlStandards; | ||
|
||
use Test::More; | ||
use ProductOpener::APITest qw/:all/; | ||
use ProductOpener::Test qw/:all/; | ||
use ProductOpener::TestDefaults qw/:all/; | ||
|
||
use File::Basename "dirname"; | ||
|
||
use Storable qw(dclone); | ||
|
||
remove_all_users(); | ||
|
||
remove_all_products(); | ||
|
||
wait_application_ready(); | ||
|
||
# Note: expected results are stored in json files, see execute_api_tests | ||
my $tests_ref = [ | ||
{ | ||
test_case => 'default', | ||
method => 'GET', | ||
path => '/cgi/nutrients.pl', | ||
}, | ||
{ | ||
test_case => 'fr-fr', | ||
method => 'GET', | ||
path => '/cgi/nutrients.pl?cc=fr&lc=fr', | ||
}, | ||
{ | ||
test_case => 'en-us', | ||
method => 'GET', | ||
path => '/cgi/nutrients.pl?cc=us&lc=en', | ||
expected_status_code => 200, | ||
}, | ||
]; | ||
|
||
execute_api_tests(__FILE__, $tests_ref); | ||
|
||
done_testing(); |
Oops, something went wrong.