-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
refactor: #954 - split the nutrition page code for better focus #1142
refactor: #954 - split the nutrition page code for better focus #1142
Conversation
…r focus New file: * `nutrition_container.dart`: Nutrition data, for nutrient order and conversions. * `tmp_to_off_nutriments.dart`: Nutrient ids supported by `Nutriments`, to be moved to off-dart Impacted file: * `nutrition_page_loaded.dart`: moved the nutrient and conversion code to new class `NutritionContainer`
Do you have a way to capture the request made to the API? |
@stephanegigandet I'm going to create related tests on off-dart. |
@stephanegigandet The test failed, with an initial value of .203g of magnesium, that I wanted to increase to .204:
test on Wasa / magnesium// cf. https://github.com/openfoodfacts/smooth-app/pull/1142
test('Wasa issue', () async {
const String barcode = '7300400481588';
final ProductQueryConfiguration configurations =
ProductQueryConfiguration(
barcode,
language: OpenFoodFactsLanguage.FRENCH,
fields: [ProductField.ALL],
);
// Step 1: get the product
ProductResult result = await OpenFoodAPIClient.getProduct(
configurations,
user: TestConstants.TEST_USER,
);
expect(result.status, 1);
expect(result.product, isNotNull);
expect(result.product!.nutriments, isNotNull);
final double? initialMagnesium = result.product!.nutriments!.magnesium;
expect(initialMagnesium, isNotNull); // in real life: 200mg = 0.2
// Step 2: save the slightly altered product
final double nextMagnesium = initialMagnesium! + .001;
result.product!.nutriments!.magnesium = nextMagnesium;
final Product savedProduct = Product(barcode: barcode);
savedProduct.nutriments = result.product!.nutriments;
final Status status = await OpenFoodAPIClient.saveProduct(
TestConstants.TEST_USER,
savedProduct,
);
expect(status.status, 1);
expect(status.error, null);
// Step 3: check if the value was correctly saved
result = await OpenFoodAPIClient.getProduct(
configurations,
user: TestConstants.TEST_USER,
);
expect(result.status, 1);
expect(result.product, isNotNull);
expect(result.product!.nutriments, isNotNull);
final double? latestMagnesium = result.product!.nutriments!.magnesium;
expect(latestMagnesium, nextMagnesium);
}); uri: https://world.openfoodfacts.net/cgi/product_jqm2.pl headers{Accept: application/json, UserAgent: Dart API, From: - dart API test - openfoodfacts-dart - iloveflutter, authorization: Basic b2ZmOm9mZg==} request body{comment: dart API test, user_id: openfoodfacts-dart, password: iloveflutter, code: 7300400481588, lang: -, selected_images: {}, images: {}, imagesFreshnessInLanguages: null, ingredients_analysis_tags: [], nutriment_salt: 1.1, nutriment_fiber: 26.0, nutriment_sugars: 2.0, nutriment_fat: 5.0, nutriment_saturated-fat: 1.0, nutriment_proteins: 13.0, nutriment_nova-group: 3, nutriment_energy: 1396.0, nutriment_energy-kcal: 333.0, nutriment_carbohydrates: 46.0, nutriment_salt_serving: 0.11, nutriment_fiber_serving: 2.6, nutriment_sugars_serving: 0.2, nutriment_fat_serving: 0.5, nutriment_fat_unit: g, nutriment_saturated-fat_serving: 0.1, nutriment_proteins_serving: 1.3, nutriment_proteins_unit: g, nutriment_nova-group_serving: 3, nutriment_energy_serving: 140.0, nutriment_carbohydrates_serving: 4.6, nutriment_carbohydrates_unit: g, nutriment_energy_unit: kj, nutriment_energy-kcal_unit: kcal, nutriment_iron_serving: 0.0006, nutriment_iron: 0.006, nutriment_iron_unit: mg, nutriment_magnesium_serving: 0.0203, nutriment_magnesium: 0.20400000000000001, nutriment_magnesium_unit: mg, nutriment_sodium_serving: 0.044, nutriment_sodium: 0.44, nutriment_sodium_unit: g, nutriment_zinc_serving: 0.0005, nutriment_zinc: 0.005, nutriment_zinc_unit: mg, nutriment_copper_serving: 0.00006, nutriment_copper: 0.0006, nutriment_copper_unit: mg} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't say anything about if the implemenation works in combination with the BE but the code looks good
Thank you @M123-dev for your code review! |
aaah BE = Backend. Finally got it after 3 days :-) |
@teolemon Deep inside I know I would rather say "server" (I'm old-fashioned) but I read "back-end" in some comments here and there and I wanted to pretend to be cool and decided to say "BE". |
New file:
nutrition_container.dart
: Nutrition data, for nutrient order and conversions.tmp_to_off_nutriments.dart
: Nutrient ids supported byNutriments
, to be moved to off-dartImpacted file:
nutrition_page_loaded.dart
: moved the nutrient and conversion code to new classNutritionContainer
What
I needed clarity in the code and I had to split the UI and the model.
It still does not work 100% of the time, but now at least it's easier to focus on the model.
My problem: I manage to save nutrition data for green tea 8712100824630 but not for Wasa 7300400481588. How come?
Part of