From d06ecabadf8f4fcecf6ce1dac43785ae6ecb843c Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Thu, 11 Jul 2024 20:43:22 +0300 Subject: [PATCH] use ingredientinfo api, for image + new source and remote id fields also update fixtures accordingly --- lib/models/nutrition/ingredient.dart | 18 ++++++ lib/models/nutrition/ingredient.g.dart | 9 +++ lib/providers/nutrition.dart | 5 +- lib/screens/home_tabs_screen.dart | 6 +- .../nutrition/ingredient_10065_response.json | 18 ------ .../nutrition/ingredient_58300_response.json | 18 ------ .../nutrition/ingredient_59887_response.json | 18 ------ .../nutrition/ingredientinfo_10065.json | 56 +++++++++++++++++ .../nutrition/ingredientinfo_58300.json | 56 +++++++++++++++++ .../nutrition/ingredientinfo_59887.json | 56 +++++++++++++++++ .../nutrition/ingredientinfo_right_code.json | 63 +++++++++++++++++++ ...de.json => ingredientinfo_wrong_code.json} | 0 ...nutritional_plan_info_detail_response.json | 9 +++ .../search_ingredient_right_code.json | 25 -------- test/nutrition/nutrition_provider_test.dart | 6 +- .../nutritional_meal_item_form_test.dart | 17 ++--- test_data/nutritional_plans.dart | 21 +++++++ 17 files changed, 307 insertions(+), 94 deletions(-) delete mode 100644 test/fixtures/nutrition/ingredient_10065_response.json delete mode 100644 test/fixtures/nutrition/ingredient_58300_response.json delete mode 100644 test/fixtures/nutrition/ingredient_59887_response.json create mode 100644 test/fixtures/nutrition/ingredientinfo_10065.json create mode 100644 test/fixtures/nutrition/ingredientinfo_58300.json create mode 100644 test/fixtures/nutrition/ingredientinfo_59887.json create mode 100644 test/fixtures/nutrition/ingredientinfo_right_code.json rename test/fixtures/nutrition/{search_ingredient_wrong_code.json => ingredientinfo_wrong_code.json} (100%) delete mode 100644 test/fixtures/nutrition/search_ingredient_right_code.json diff --git a/lib/models/nutrition/ingredient.dart b/lib/models/nutrition/ingredient.dart index 3acf8624..1a0981f8 100644 --- a/lib/models/nutrition/ingredient.dart +++ b/lib/models/nutrition/ingredient.dart @@ -24,9 +24,24 @@ part 'ingredient.g.dart'; @JsonSerializable() class Ingredient { + // fields returned by django api that we ignore here: + // uuid, last_updated, last_imported, weight_units, language + // all license fields + @JsonKey(required: true) final int id; + // some ingredients don't have these 3 fields set. E.g. USDA entries that + // have been removed upstream, or manually added ingredients. + @JsonKey(required: true, name: 'remote_id') + final String? remoteId; + + @JsonKey(required: true, name: 'source_name') + final String? sourceName; + + @JsonKey(required: true, name: 'source_url') + final String? sourceUrl; + /// Barcode of the product @JsonKey(required: true) final String? code; @@ -73,6 +88,9 @@ class Ingredient { IngredientImage? image; Ingredient({ + required this.remoteId, + required this.sourceName, + required this.sourceUrl, required this.id, required this.code, required this.name, diff --git a/lib/models/nutrition/ingredient.g.dart b/lib/models/nutrition/ingredient.g.dart index 92df4273..f3f21074 100644 --- a/lib/models/nutrition/ingredient.g.dart +++ b/lib/models/nutrition/ingredient.g.dart @@ -11,6 +11,9 @@ Ingredient _$IngredientFromJson(Map json) { json, requiredKeys: const [ 'id', + 'remote_id', + 'source_name', + 'source_url', 'code', 'name', 'created', @@ -25,6 +28,9 @@ Ingredient _$IngredientFromJson(Map json) { ], ); return Ingredient( + remoteId: json['remote_id'] as String?, + sourceName: json['source_name'] as String?, + sourceUrl: json['source_url'] as String?, id: (json['id'] as num).toInt(), code: json['code'] as String?, name: json['name'] as String, @@ -46,6 +52,9 @@ Ingredient _$IngredientFromJson(Map json) { Map _$IngredientToJson(Ingredient instance) => { 'id': instance.id, + 'remote_id': instance.remoteId, + 'source_name': instance.sourceName, + 'source_url': instance.sourceUrl, 'code': instance.code, 'name': instance.name, 'created': instance.created.toIso8601String(), diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index b9806449..f6bd5af9 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -39,6 +39,7 @@ class NutritionPlansProvider with ChangeNotifier { static const _mealPath = 'meal'; static const _mealItemPath = 'mealitem'; static const _ingredientPath = 'ingredient'; + static const _ingredientInfoPath = 'ingredientinfo'; static const _ingredientSearchPath = 'ingredient/search'; static const _nutritionDiaryPath = 'nutritiondiary'; static const _ingredientImagePath = 'ingredient-image'; @@ -298,7 +299,7 @@ class NutritionPlansProvider with ChangeNotifier { // Get ingredient from the server and save to cache } on StateError { final data = await baseProvider.fetch( - baseProvider.makeUrl(_ingredientPath, id: ingredientId), + baseProvider.makeUrl(_ingredientInfoPath, id: ingredientId), ); ingredient = Ingredient.fromJson(data); _ingredients.add(ingredient); @@ -370,7 +371,7 @@ class NutritionPlansProvider with ChangeNotifier { // Send the request final data = await baseProvider.fetch( - baseProvider.makeUrl(_ingredientPath, query: {'code': code}), + baseProvider.makeUrl(_ingredientInfoPath, query: {'code': code}), ); if (data['count'] == 0) { diff --git a/lib/screens/home_tabs_screen.dart b/lib/screens/home_tabs_screen.dart index 9a4c3f25..765703be 100644 --- a/lib/screens/home_tabs_screen.dart +++ b/lib/screens/home_tabs_screen.dart @@ -94,7 +94,7 @@ class _HomeTabsScreenState extends State with SingleTickerProvid exercisesProvider.fetchAndSetInitialData(), ]); } catch (e) { - log('fire! fire!'); + log('Exception loading base data'); log(e.toString()); } @@ -109,7 +109,7 @@ class _HomeTabsScreenState extends State with SingleTickerProvid measurementProvider.fetchAndSetAllCategoriesAndEntries(), ]); } catch (e) { - log('fire! fire!'); + log('Exception loading plans, weight, measurements and gallery'); log(e.toString()); } @@ -121,7 +121,7 @@ class _HomeTabsScreenState extends State with SingleTickerProvid await nutritionPlansProvider.fetchAndSetPlanFull(plan.id!); } } catch (e) { - log('fire! fire!'); + log('Exception loading current nutritional plan'); log(e.toString()); } diff --git a/test/fixtures/nutrition/ingredient_10065_response.json b/test/fixtures/nutrition/ingredient_10065_response.json deleted file mode 100644 index 6653d12a..00000000 --- a/test/fixtures/nutrition/ingredient_10065_response.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": 10065, - "code": "0043647440020", - "name": "'Old Times' Orange Fine Cut Marmalade", - "created": "2020-12-20T01:00:00+01:00", - "last_update": "2022-08-09T10:23:11+02:00", - "energy": 269, - "protein": "0.000", - "carbohydrates": "67.000", - "carbohydrates_sugar": "66.000", - "fat": "0.000", - "fat_saturated": "0.000", - "fiber": null, - "sodium": "0.000", - "license": 5, - "license_author": "Open Food Facts", - "language": 2 -} \ No newline at end of file diff --git a/test/fixtures/nutrition/ingredient_58300_response.json b/test/fixtures/nutrition/ingredient_58300_response.json deleted file mode 100644 index 7ff1f8f6..00000000 --- a/test/fixtures/nutrition/ingredient_58300_response.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": 58300, - "code": "4071800000992", - "name": "1688 Mehrkorn", - "created": "2020-12-20T01:00:00+02:00", - "last_update": "2022-08-09T18:55:00+02:00", - "energy": 229, - "protein": "7.680", - "carbohydrates": "35.700", - "carbohydrates_sugar": "2.320", - "fat": "4.820", - "fat_saturated": "0.714", - "fiber": "6.960", - "sodium": "0.000", - "license": 5, - "license_author": "Open Food Facts", - "language": 2 -} \ No newline at end of file diff --git a/test/fixtures/nutrition/ingredient_59887_response.json b/test/fixtures/nutrition/ingredient_59887_response.json deleted file mode 100644 index 2287c32b..00000000 --- a/test/fixtures/nutrition/ingredient_59887_response.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": 59887, - "code": "4311501354155", - "name": "Baked Beans", - "created": "2020-12-20T23:10:54+01:00", - "last_update": "2022-08-09T13:32:41+01:00", - "energy": 86, - "protein": "4.400", - "carbohydrates": "11.000", - "carbohydrates_sugar": "5.300", - "fat": "0.100", - "fat_saturated": "0.000", - "fiber": "5.000", - "sodium": "0.480", - "license": 5, - "license_author": "Open Food Facts", - "language": 1 -} \ No newline at end of file diff --git a/test/fixtures/nutrition/ingredientinfo_10065.json b/test/fixtures/nutrition/ingredientinfo_10065.json new file mode 100644 index 00000000..b10e4e9e --- /dev/null +++ b/test/fixtures/nutrition/ingredientinfo_10065.json @@ -0,0 +1,56 @@ +{ + "id": 10065, + "uuid": "cd134608-3fbf-4d54-bf9d-ecc56e4271f2", + "remote_id": "0043647440020", + "source_name": "Open Food Facts", + "source_url": "https://world.openfoodfacts.org/api/v2/product/0043647440020.json", + "code": "0043647440020", + "name": "'Old Times' Orange Fine Cut Marmalade", + "created": "2020-12-20T01:00:00+01:00", + "last_update": "2024-06-07T06:04:05.211180+02:00", + "last_imported": "2020-12-20T14:44:55.854000+01:00", + "energy": 269, + "protein": "0.000", + "carbohydrates": "67.000", + "carbohydrates_sugar": "66.000", + "fat": "0.000", + "fat_saturated": "0.000", + "fiber": null, + "sodium": "0.000", + "weight_units": [], + "language": { + "id": 2, + "short_name": "en", + "full_name": "English", + "full_name_en": "English" + }, + "image": { + "id": 7545, + "uuid": "c7a43097-da62-4a35-95f4-fe466e68cbc6", + "ingredient_id": 10065, + "ingredient_uuid": "cd134608-3fbf-4d54-bf9d-ecc56e4271f2", + "image": "https://wger.de/media/ingredients/10065/c7a43097-da62-4a35-95f4-fe466e68cbc6.jpg", + "created": "2023-04-21T20:13:01.136749+02:00", + "last_update": "2023-04-21T20:13:01.151137+02:00", + "size": 43397, + "width": 219, + "height": 400, + "license": 1, + "license_title": "Photo", + "license_object_url": "https://world.openfoodfacts.org/cgi/product_image.pl?code=0043647440020&id=2", + "license_author": "tacinte", + "license_author_url": "https://world.openfoodfacts.org/photographer/tacinte", + "license_derivative_source_url": "" + }, + "license": { + "id": 5, + "full_name": "Open Data Commons Open Database License", + "short_name": "ODbL", + "url": "https://opendatacommons.org/licenses/odbl/" + }, + "license_title": "'Old Times' Orange Fine Cut Marmalade", + "license_object_url": "", + "license_author": "", + "license_author_url": "", + "license_derivative_source_url": "" +} \ No newline at end of file diff --git a/test/fixtures/nutrition/ingredientinfo_58300.json b/test/fixtures/nutrition/ingredientinfo_58300.json new file mode 100644 index 00000000..9e02c618 --- /dev/null +++ b/test/fixtures/nutrition/ingredientinfo_58300.json @@ -0,0 +1,56 @@ +{ + "id": 58300, + "uuid": "151a8d44-735e-4f9b-9e22-7dc4c604154a", + "remote_id": "4071800000992", + "source_name": "Open Food Facts", + "source_url": "https://world.openfoodfacts.org/api/v2/product/4071800000992.json", + "code": "4071800000992", + "name": "1688 Mehrkorn", + "created": "2020-12-20T01:00:00+01:00", + "last_update": "2024-06-07T06:06:48.259950+02:00", + "last_imported": "2020-12-20T14:46:58.971000+01:00", + "energy": 229, + "protein": "7.680", + "carbohydrates": "35.700", + "carbohydrates_sugar": "2.320", + "fat": "4.820", + "fat_saturated": "0.714", + "fiber": "6.960", + "sodium": "0.000", + "weight_units": [], + "language": { + "id": 1, + "short_name": "de", + "full_name": "Deutsch", + "full_name_en": "German" + }, + "image": { + "id": 10862, + "uuid": "a5b6766f-b606-451c-b806-24eb3a8597ea", + "ingredient_id": 58300, + "ingredient_uuid": "151a8d44-735e-4f9b-9e22-7dc4c604154a", + "image": "https://wger.de/media/ingredients/58300/a5b6766f-b606-451c-b806-24eb3a8597ea.jpg", + "created": "2023-05-08T11:37:13.876341+02:00", + "last_update": "2023-05-08T11:37:13.891457+02:00", + "size": 33617, + "width": 400, + "height": 225, + "license": 1, + "license_title": "Photo", + "license_object_url": "https://world.openfoodfacts.org/cgi/product_image.pl?code=4071800000992&id=15", + "license_author": "kiliweb", + "license_author_url": "https://world.openfoodfacts.org/photographer/kiliweb", + "license_derivative_source_url": "" + }, + "license": { + "id": 5, + "full_name": "Open Data Commons Open Database License", + "short_name": "ODbL", + "url": "https://opendatacommons.org/licenses/odbl/" + }, + "license_title": "1688 Mehrkorn", + "license_object_url": "", + "license_author": "", + "license_author_url": "", + "license_derivative_source_url": "" +} \ No newline at end of file diff --git a/test/fixtures/nutrition/ingredientinfo_59887.json b/test/fixtures/nutrition/ingredientinfo_59887.json new file mode 100644 index 00000000..6c18b0fa --- /dev/null +++ b/test/fixtures/nutrition/ingredientinfo_59887.json @@ -0,0 +1,56 @@ +{ + "id": 59887, + "uuid": "2efa101b-d6f7-4755-838d-b3bb5c483b02", + "remote_id": "4311501354155", + "source_name": "Open Food Facts", + "source_url": "https://world.openfoodfacts.org/api/v2/product/4311501354155.json", + "code": "4311501354155", + "name": "Baked Beans", + "created": "2020-12-20T01:00:00+01:00", + "last_update": "2024-06-07T06:40:23.364866+02:00", + "last_imported": "2020-12-20T14:47:03.728000+01:00", + "energy": 86, + "protein": "4.400", + "carbohydrates": "11.000", + "carbohydrates_sugar": "5.300", + "fat": "0.600", + "fat_saturated": "0.100", + "fiber": "9.100", + "sodium": "0.260", + "weight_units": [], + "language": { + "id": 1, + "short_name": "de", + "full_name": "Deutsch", + "full_name_en": "German" + }, + "image": { + "id": 1718, + "uuid": "493bc593-4813-4bae-b92a-a4e1fbee5e44", + "ingredient_id": 59887, + "ingredient_uuid": "2efa101b-d6f7-4755-838d-b3bb5c483b02", + "image": "https://wger.de/media/ingredients/59887/493bc593-4813-4bae-b92a-a4e1fbee5e44.jpg", + "created": "2023-04-09T01:45:50.874157+02:00", + "last_update": "2023-04-09T01:45:50.911258+02:00", + "size": 27752, + "width": 286, + "height": 400, + "license": 1, + "license_title": "Photo", + "license_object_url": "https://world.openfoodfacts.org/cgi/product_image.pl?code=4311501354155&id=6", + "license_author": "kiliweb", + "license_author_url": "https://world.openfoodfacts.org/photographer/kiliweb", + "license_derivative_source_url": "" + }, + "license": { + "id": 5, + "full_name": "Open Data Commons Open Database License", + "short_name": "ODbL", + "url": "https://opendatacommons.org/licenses/odbl/" + }, + "license_title": "Baked Beans", + "license_object_url": "https://world.openfoodfacts.org/product/4311501354155/", + "license_author": "", + "license_author_url": "", + "license_derivative_source_url": "" +} \ No newline at end of file diff --git a/test/fixtures/nutrition/ingredientinfo_right_code.json b/test/fixtures/nutrition/ingredientinfo_right_code.json new file mode 100644 index 00000000..ee46233a --- /dev/null +++ b/test/fixtures/nutrition/ingredientinfo_right_code.json @@ -0,0 +1,63 @@ +{ + "count": 1, + "next": null, + "previous": null, + "results": [ + { + "id": 19733, + "uuid": "354c6050-5654-41bc-8823-4fd27b54fb59", + "remote_id": "3068320105222", + "source_name": "Open Food Facts", + "source_url": "https://world.openfoodfacts.org/api/v2/product/3068320105222.json", + "code": "3068320105222", + "name": "Badoit zest citron vert sans sucres", + "created": "2020-12-20T01:00:00+01:00", + "last_update": "2024-06-07T06:39:29.032545+02:00", + "last_imported": "2020-12-20T14:45:31.370000+01:00", + "energy": 1, + "protein": "0.000", + "carbohydrates": "0.000", + "carbohydrates_sugar": "0.000", + "fat": "0.000", + "fat_saturated": "0.000", + "fiber": null, + "sodium": "0.020", + "weight_units": [], + "language": { + "id": 12, + "short_name": "fr", + "full_name": "Fran\u00e7ais", + "full_name_en": "French" + }, + "image": { + "id": 26949, + "uuid": "5177e2d1-b03a-42d9-bdf1-2dd3edad8210", + "ingredient_id": 19733, + "ingredient_uuid": "354c6050-5654-41bc-8823-4fd27b54fb59", + "image": "https://wger.de/media/ingredients/19733/5177e2d1-b03a-42d9-bdf1-2dd3edad8210.jpg", + "created": "2023-12-04T10:48:19.019477+01:00", + "last_update": "2023-12-04T10:48:19.062343+01:00", + "size": 13302, + "width": 112, + "height": 400, + "license": 1, + "license_title": "Photo", + "license_object_url": "https://world.openfoodfacts.org/cgi/product_image.pl?code=3068320105222&id=11", + "license_author": "hungergames", + "license_author_url": "https://world.openfoodfacts.org/photographer/hungergames", + "license_derivative_source_url": "" + }, + "license": { + "id": 5, + "full_name": "Open Data Commons Open Database License", + "short_name": "ODbL", + "url": "https://opendatacommons.org/licenses/odbl/" + }, + "license_title": "Badoit zest citron vert sans sucres", + "license_object_url": "", + "license_author": "", + "license_author_url": "", + "license_derivative_source_url": "" + } + ] +} diff --git a/test/fixtures/nutrition/search_ingredient_wrong_code.json b/test/fixtures/nutrition/ingredientinfo_wrong_code.json similarity index 100% rename from test/fixtures/nutrition/search_ingredient_wrong_code.json rename to test/fixtures/nutrition/ingredientinfo_wrong_code.json diff --git a/test/fixtures/nutrition/nutritional_plan_info_detail_response.json b/test/fixtures/nutrition/nutritional_plan_info_detail_response.json index 233d2e1a..ba07b705 100644 --- a/test/fixtures/nutrition/nutritional_plan_info_detail_response.json +++ b/test/fixtures/nutrition/nutritional_plan_info_detail_response.json @@ -50,6 +50,9 @@ "ingredient": 59887, "ingredient_obj": { "id": 59887, + "remote_id": 123456789, + "source_name": "Open Food Facts", + "source_url" : "https://world.openfoodfacts.org/ingredients/123456789", "code": "4311501354155", "name": "Baked Beans", "created": "2020-12-20", @@ -88,6 +91,9 @@ "ingredient": 58300, "ingredient_obj": { "id": 58300, + "remote_id": 123456788, + "source_name": "Open Food Facts", + "source_url" : "https://world.openfoodfacts.org/ingredients/123456788", "code": "4071800000992", "name": "1688 Mehrkorn", "created": "2020-12-20", @@ -141,6 +147,9 @@ "ingredient": 10065, "ingredient_obj": { "id": 10065, + "remote_id": 123456787, + "source_name": "Open Food Facts", + "source_url" : "https://world.openfoodfacts.org/ingredients/123456787", "code": "0043647440020", "name": "'Old Times' Orange Fine Cut Marmalade", "created": "2020-12-20", diff --git a/test/fixtures/nutrition/search_ingredient_right_code.json b/test/fixtures/nutrition/search_ingredient_right_code.json deleted file mode 100644 index 01a5ae39..00000000 --- a/test/fixtures/nutrition/search_ingredient_right_code.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "count": 1, - "next": null, - "previous": null, - "results": [ - { - "id": 9436, - "code": "0013087245950", - "name": " Gâteau double chocolat ", - "creation_date": "2020-12-20", - "update_date": "2020-12-20", - "energy": 360, - "protein": "5.000", - "carbohydrates": "45.000", - "carbohydrates_sugar": "27.000", - "fat": "18.000", - "fat_saturated": "4.500", - "fiber": "2.000", - "sodium": "0.356", - "license": 5, - "license_author": "Open Food Facts", - "language": 12 - } - ] -} \ No newline at end of file diff --git a/test/nutrition/nutrition_provider_test.dart b/test/nutrition/nutrition_provider_test.dart index 8f3f4f95..39ed669a 100644 --- a/test/nutrition/nutrition_provider_test.dart +++ b/test/nutrition/nutrition_provider_test.dart @@ -31,13 +31,13 @@ void main() { fixture('nutrition/nutrition_diary_response.json'), )['results']; final Map ingredient59887Response = jsonDecode( - fixture('nutrition/ingredient_59887_response.json'), + fixture('nutrition/ingredientinfo_59887.json'), ); final Map ingredient10065Response = jsonDecode( - fixture('nutrition/ingredient_10065_response.json'), + fixture('nutrition/ingredientinfo_10065.json'), ); final Map ingredient58300Response = jsonDecode( - fixture('nutrition/ingredient_58300_response.json'), + fixture('nutrition/ingredientinfo_58300.json'), ); final ingredientList = [ diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart index 2ed57b98..9ea69f77 100644 --- a/test/nutrition/nutritional_meal_item_form_test.dart +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -26,6 +26,9 @@ import 'nutritional_plan_form_test.mocks.dart'; void main() { final ingredient = Ingredient( + remoteId: '1', + sourceName: 'Built-in testdata', + sourceUrl: 'https://example.com/ingredient/1', id: 1, code: '123456787', name: 'Water', @@ -52,20 +55,20 @@ void main() { var plan1 = NutritionalPlan.empty(); var meal1 = Meal(); - final Uri tUriRightCode = Uri.parse('https://localhost/api/v2/ingredient/?code=123'); - final Uri tUriEmptyCode = Uri.parse('https://localhost/api/v2/ingredient/?code="%20"'); - final Uri tUriBadCode = Uri.parse('https://localhost/api/v2/ingredient/?code=222'); + final Uri tUriRightCode = Uri.parse('https://localhost/api/v2/ingredientinfo/?code=123'); + final Uri tUriEmptyCode = Uri.parse('https://localhost/api/v2/ingredientinfo/?code="%20"'); + final Uri tUriBadCode = Uri.parse('https://localhost/api/v2/ingredientinfo/?code=222'); when(client.get(tUriRightCode, headers: anyNamed('headers'))).thenAnswer( - (_) => Future.value(http.Response(fixture('nutrition/search_ingredient_right_code.json'), 200)), + (_) => Future.value(http.Response(fixture('nutrition/ingredientinfo_right_code.json'), 200)), ); when(client.get(tUriEmptyCode, headers: anyNamed('headers'))).thenAnswer( - (_) => Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200)), + (_) => Future.value(http.Response(fixture('nutrition/ingredientinfo_wrong_code.json'), 200)), ); when(client.get(tUriBadCode, headers: anyNamed('headers'))).thenAnswer( - (_) => Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200)), + (_) => Future.value(http.Response(fixture('nutrition/ingredientinfo_wrong_code.json'), 200)), ); setUp(() { @@ -307,7 +310,7 @@ void main() { // once ID and weight are set, it'll fetchIngredient and show macros preview when(mockNutrition.fetchIngredient(1)).thenAnswer((_) => Future.value( - Ingredient.fromJson(jsonDecode(fixture('nutrition/ingredient_59887_response.json'))), + Ingredient.fromJson(jsonDecode(fixture('nutrition/ingredientinfo_59887.json'))), )); await tester.enterText(find.byKey(const Key('field-weight')), '2'); diff --git a/test_data/nutritional_plans.dart b/test_data/nutritional_plans.dart index 6cfd2de0..5e77e792 100644 --- a/test_data/nutritional_plans.dart +++ b/test_data/nutritional_plans.dart @@ -26,6 +26,9 @@ import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; final ingredient1 = Ingredient( + remoteId: '1', + sourceName: 'Built-in testdata', + sourceUrl: 'https://example.com/ingredient/1', id: 1, code: '123456787', name: 'Water', @@ -40,6 +43,9 @@ final ingredient1 = Ingredient( sodium: 0.5, ); final ingredient2 = Ingredient( + remoteId: '2', + sourceName: 'Built-in testdata', + sourceUrl: 'https://example.com/ingredient/2', id: 2, code: '123456788', name: 'Burger soup', @@ -54,6 +60,9 @@ final ingredient2 = Ingredient( sodium: 0, ); final ingredient3 = Ingredient( + remoteId: '3', + sourceName: 'Built-in testdata', + sourceUrl: 'https://example.com/ingredient/3', id: 3, code: '123456789', name: 'Broccoli cake', @@ -68,6 +77,9 @@ final ingredient3 = Ingredient( sodium: 10, ); final muesli = Ingredient( + remoteId: '1', + sourceName: 'Built-in testdata', + sourceUrl: 'https://example.com/ingredient/1', id: 1, code: '123456787', name: 'Müsli', @@ -82,6 +94,9 @@ final muesli = Ingredient( sodium: 0.5, ); final milk = Ingredient( + remoteId: '1', + sourceName: 'Built-in testdata', + sourceUrl: 'https://example.com/ingredient/1', id: 1, code: '123456787', name: 'Milk', @@ -96,6 +111,9 @@ final milk = Ingredient( sodium: 0.5, ); final apple = Ingredient( + remoteId: '1', + sourceName: 'Built-in testdata', + sourceUrl: 'https://example.com/ingredient/1', id: 1, code: '123456787', name: 'Apple', @@ -110,6 +128,9 @@ final apple = Ingredient( sodium: 0.5, ); final cake = Ingredient( + remoteId: '1', + sourceName: 'Built-in testdata', + sourceUrl: 'https://example.com/ingredient/1', id: 1, code: '111111111', name: 'Lemon CAke',