Consolidate ingredient search methods into the ingredient repo

This commit is contained in:
Roland Geider
2026-05-01 12:27:49 +02:00
parent 5fea670ba3
commit 9f365f8069
18 changed files with 499 additions and 484 deletions

View File

@@ -1,7 +1,7 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shared_preferences/util/legacy_to_async_migration_util.dart';
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/providers/nutrition_repository.dart';
import 'package:wger/providers/ingredient_repository.dart';
/// A helper class that manages preferences using SharedPreferencesAsync
/// and handles migration from the legacy SharedPreferences to

View File

@@ -1,6 +1,6 @@
//model is used to store ingredient filters values
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/providers/nutrition_repository.dart';
import 'package:wger/providers/ingredient_repository.dart';
class IngredientFilters {
final bool isVegan;

View File

@@ -19,21 +19,36 @@
import 'package:drift/drift.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/models/nutrition/ingredient_weight_unit.dart';
import 'package:wger/providers/base_provider.dart';
import 'package:wger/providers/wger_base.dart';
import '../database/powersync/database.dart';
/// Which language(s) the server-side ingredient search should consider.
enum IngredientSearchLanguage {
current,
currentAndEnglish,
all,
}
final ingredientRepositoryProvider = Provider<IngredientRepository>((ref) {
final base = ref.read(wgerBaseProvider);
final db = ref.read(driftPowerSyncDatabase);
return IngredientRepository(db);
return IngredientRepository(base, db);
});
/// Data access for ingredient lookups and searches
class IngredientRepository {
final _logger = Logger('IngredientRepository');
final WgerBaseProvider _base;
final DriftPowersyncDatabase _db;
IngredientRepository(this._db);
static const ingredientInfoPath = 'ingredientinfo';
IngredientRepository(this._base, this._db);
/// Watches a single ingredient by [id] with its `image` and `weightUnits`
/// fields fully hydrated. Emits `null` if no ingredient with that id exists,
@@ -60,7 +75,7 @@ class IngredientRepository {
///
/// Hydrates `image` and `weightUnits` on the returned rows so the
/// result is shape-compatible with the REST search.
Future<List<Ingredient>> searchByName(
Future<List<Ingredient>> searchIngredientLocal(
String term, {
bool isVegan = false,
bool isVegetarian = false,
@@ -87,6 +102,76 @@ class IngredientRepository {
return _hydrate(await query.get());
}
/// Searches for ingredients via the wger REST API.
Future<List<Ingredient>> searchIngredientServer(
String name, {
String languageCode = 'en',
IngredientSearchLanguage searchLanguage = IngredientSearchLanguage.current,
bool isVegan = false,
bool isVegetarian = false,
NutriScore? nutriscoreMax,
}) async {
if (name.length <= 1) {
return [];
}
final List<String> languages = [];
switch (searchLanguage) {
case IngredientSearchLanguage.current:
languages.add(languageCode);
case IngredientSearchLanguage.currentAndEnglish:
languages.add(languageCode);
if (languageCode != LANGUAGE_SHORT_ENGLISH) {
languages.add(LANGUAGE_SHORT_ENGLISH);
}
case IngredientSearchLanguage.all:
// Don't add any language code to search in all languages
break;
}
final query = {
'name__search': name,
'limit': API_RESULTS_PAGE_SIZE,
};
if (languages.isNotEmpty) {
query['language__code'] = languages.join(',');
}
if (isVegan) {
query['is_vegan'] = 'true';
}
if (isVegetarian) {
query['is_vegetarian'] = 'true';
}
if (nutriscoreMax != null) {
query['nutriscore__lte'] = nutriscoreMax.name;
}
_logger.info('Searching ingredients from server');
final response = await _base.fetch(
_base.makeUrl(ingredientInfoPath, query: query),
timeout: const Duration(seconds: 20),
);
return (response['results'] as List)
.map((data) => Ingredient.fromJson(data as Map<String, dynamic>))
.toList();
}
/// Looks up an ingredient by its product barcode via the REST API.
/// Returns `null` if no matching product is found.
Future<Ingredient?> searchIngredientByBarcode(String barcode) async {
if (barcode.isEmpty) {
return null;
}
final data = await _base.fetch(
_base.makeUrl(ingredientInfoPath, query: {'code': barcode}),
);
if (data['count'] == 0) {
return null;
}
return Ingredient.fromJson(data['results'][0]);
}
/// Builds the standard joined query used by every ingredient lookup
JoinedSelectStatement<HasResultSet, dynamic> _baseJoinedQuery() {
return _db.select(_db.ingredientTable).join([

View File

@@ -21,7 +21,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:wger/helpers/shared_preferences.dart';
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/models/nutrition/ingredient_filters.dart';
import 'package:wger/providers/nutrition_repository.dart';
import 'package:wger/providers/ingredient_repository.dart';
part 'nutrition_ingredient_filters_riverpod.g.dart';

View File

@@ -22,7 +22,6 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:stream_transform/stream_transform.dart';
import 'package:wger/core/exceptions/http_exception.dart';
import 'package:wger/core/exceptions/no_such_entry_exception.dart';
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/models/nutrition/log.dart';
import 'package:wger/models/nutrition/meal.dart';
import 'package:wger/models/nutrition/meal_item.dart';
@@ -305,32 +304,6 @@ class NutritionNotifier extends _$NutritionNotifier {
}
}
// --- Ingredients ---
Future<List<Ingredient>> searchIngredient(
String name, {
String languageCode = 'en',
IngredientSearchLanguage searchLanguage = IngredientSearchLanguage.current,
bool isVegan = false,
bool isVegetarian = false,
NutriScore? nutriscoreMax,
}) {
final repo = ref.read(nutritionRepositoryProvider);
return repo.searchIngredient(
name,
languageCode: languageCode,
searchLanguage: searchLanguage,
isVegan: isVegan,
isVegetarian: isVegetarian,
nutriscoreMax: nutriscoreMax,
);
}
Future<Ingredient?> searchIngredientWithBarcode(String barcode) {
final repo = ref.read(nutritionRepositoryProvider);
return repo.searchIngredientWithBarcode(barcode);
}
// --- Logs (nutrition diary) ---
Future<void> logMealToDiary(Meal meal, DateTime mealDateTime) async {

View File

@@ -33,7 +33,7 @@ final class NutritionNotifierProvider
NutritionNotifier create() => NutritionNotifier();
}
String _$nutritionNotifierHash() => r'afac5137c8f510197cbefb08fe595f8a59d4024b';
String _$nutritionNotifierHash() => r'ac4b649e3622f55c01486efa4538038f68dba113';
abstract class _$NutritionNotifier extends $StreamNotifier<NutritionState> {
Stream<NutritionState> build();

View File

@@ -30,12 +30,6 @@ import 'package:wger/models/nutrition/nutritional_plan.dart';
import 'package:wger/providers/base_provider.dart';
import 'package:wger/providers/wger_base.dart';
enum IngredientSearchLanguage {
current,
currentAndEnglish,
all,
}
final nutritionRepositoryProvider = Provider<NutritionRepository>((ref) {
final base = ref.read(wgerBaseProvider);
final db = ref.read(driftPowerSyncDatabase);
@@ -50,7 +44,7 @@ final nutritionRepositoryProvider = Provider<NutritionRepository>((ref) {
/// database — see [watchAllDrift], [editLocalDrift], [deleteLocalDrift],
/// [watchAllLogsHydrated], [addLogLocalDrift], [deleteLogLocalDrift].
///
/// Local ingredient lookups are handled by [IngredientRepository] (PowerSync).
/// Ingredient searches (local + REST) live on [IngredientRepository].
class NutritionRepository {
final _logger = Logger('NutritionRepository');
final WgerBaseProvider _base;
@@ -60,7 +54,6 @@ class NutritionRepository {
static const plansInfoPath = 'nutritionplaninfo';
static const mealPath = 'meal';
static const mealItemPath = 'mealitem';
static const ingredientInfoPath = 'ingredientinfo';
NutritionRepository(this._base, this._db);
@@ -153,81 +146,6 @@ class NutritionRepository {
return _base.deleteRequest(mealItemPath, id);
}
// --- Ingredients ---
/// Searches for an ingredient via the REST API.
///
/// [nutriscoreMax] — if non-null, the worst acceptable Nutri-Score grade,
/// sent to the backend as `nutriscore__lte`. The Django filterset
/// compares lexicographically on the `a`..`e` choices, so passing
/// [NutriScore.b] yields "only A or B".
Future<List<Ingredient>> searchIngredient(
String name, {
String languageCode = 'en',
IngredientSearchLanguage searchLanguage = IngredientSearchLanguage.current,
bool isVegan = false,
bool isVegetarian = false,
NutriScore? nutriscoreMax,
}) async {
if (name.length <= 1) {
return [];
}
final List<String> languages = [];
switch (searchLanguage) {
case IngredientSearchLanguage.current:
languages.add(languageCode);
case IngredientSearchLanguage.currentAndEnglish:
languages.add(languageCode);
if (languageCode != LANGUAGE_SHORT_ENGLISH) {
languages.add(LANGUAGE_SHORT_ENGLISH);
}
case IngredientSearchLanguage.all:
// Don't add any language code to search in all languages
break;
}
final query = {
'name__search': name,
'limit': API_RESULTS_PAGE_SIZE,
};
if (languages.isNotEmpty) {
query['language__code'] = languages.join(',');
}
if (isVegan) {
query['is_vegan'] = 'true';
}
if (isVegetarian) {
query['is_vegetarian'] = 'true';
}
if (nutriscoreMax != null) {
query['nutriscore__lte'] = nutriscoreMax.name;
}
_logger.info('Searching ingredients from server');
final response = await _base.fetch(
_base.makeUrl(ingredientInfoPath, query: query),
timeout: const Duration(seconds: 20),
);
return (response['results'] as List)
.map((data) => Ingredient.fromJson(data as Map<String, dynamic>))
.toList();
}
Future<Ingredient?> searchIngredientWithBarcode(String barcode) async {
if (barcode.isEmpty) {
return null;
}
final data = await _base.fetch(
_base.makeUrl(ingredientInfoPath, query: {'code': barcode}),
);
if (data['count'] == 0) {
return null;
}
return Ingredient.fromJson(data['results'][0]);
}
// --- Nutrition diary (logs) ---
/// Streams all of the user's diary entries with their related [Ingredient]

View File

@@ -30,8 +30,6 @@ import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/providers/ingredient_repository.dart';
import 'package:wger/providers/network_provider.dart';
import 'package:wger/providers/nutrition_ingredient_filters_riverpod.dart';
import 'package:wger/providers/nutrition_notifier.dart';
import 'package:wger/providers/nutrition_repository.dart';
import 'package:wger/widgets/core/core.dart';
import 'package:wger/widgets/core/wger_image.dart';
import 'package:wger/widgets/nutrition/helpers.dart';
@@ -159,26 +157,23 @@ class _IngredientTypeaheadState extends ConsumerState<IngredientTypeahead> {
// Online: REST search across all ingredients in the wger DB.
// Offline: SQL substring search against the local snapshot.
// Both honour the diet flags and the Nutri-Score filter.
final ingredientRepo = ref.read(ingredientRepositoryProvider);
if (ref.read(networkStatusProvider)) {
return ref
.read(nutritionProvider.notifier)
.searchIngredient(
pattern,
languageCode: Localizations.localeOf(context).languageCode,
searchLanguage: filters.searchLanguage,
isVegan: filters.isVegan,
isVegetarian: filters.isVegetarian,
nutriscoreMax: filters.nutriscoreMax,
);
return ingredientRepo.searchIngredientServer(
pattern,
languageCode: Localizations.localeOf(context).languageCode,
searchLanguage: filters.searchLanguage,
isVegan: filters.isVegan,
isVegetarian: filters.isVegetarian,
nutriscoreMax: filters.nutriscoreMax,
);
}
return ref
.read(ingredientRepositoryProvider)
.searchByName(
pattern,
isVegan: filters.isVegan,
isVegetarian: filters.isVegetarian,
nutriscoreMax: filters.nutriscoreMax,
);
return ingredientRepo.searchIngredientLocal(
pattern,
isVegan: filters.isVegan,
isVegetarian: filters.isVegetarian,
nutriscoreMax: filters.nutriscoreMax,
);
},
itemBuilder: (context, ingredient) {
final i18n = AppLocalizations.of(context);
@@ -275,7 +270,7 @@ class _IngredientTypeaheadState extends ConsumerState<IngredientTypeahead> {
showDialog(
context: context,
builder: (context) => FutureBuilder<Ingredient?>(
future: ref.read(nutritionProvider.notifier).searchIngredientWithBarcode(barcode),
future: ref.read(ingredientRepositoryProvider).searchIngredientByBarcode(barcode),
builder: (BuildContext context, AsyncSnapshot<Ingredient?> snapshot) {
return IngredientScanResultDialog(snapshot, barcode, widget.selectIngredient);
},

View File

@@ -4195,6 +4195,39 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
)
as String);
@override
String get filterNutriscore =>
(super.noSuchMethod(
Invocation.getter(#filterNutriscore),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#filterNutriscore),
),
)
as String);
@override
String get filterNutriscoreOff =>
(super.noSuchMethod(
Invocation.getter(#filterNutriscoreOff),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#filterNutriscoreOff),
),
)
as String);
@override
String get filterNutriscoreNoFilter =>
(super.noSuchMethod(
Invocation.getter(#filterNutriscoreNoFilter),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#filterNutriscoreNoFilter),
),
)
as String);
@override
String exerciseNr(String? nr) =>
(super.noSuchMethod(
@@ -4480,4 +4513,15 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
),
)
as String);
@override
String filterNutriscoreOrBetter(String? grade) =>
(super.noSuchMethod(
Invocation.method(#filterNutriscoreOrBetter, [grade]),
returnValue: _i3.dummyValue<String>(
this,
Invocation.method(#filterNutriscoreOrBetter, [grade]),
),
)
as String);
}

View File

@@ -9,10 +9,10 @@ import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/measurements/measurement_category.dart' as _i5;
import 'package:wger/models/measurements/measurement_entry.dart' as _i6;
import 'package:wger/models/nutrition/ingredient.dart' as _i9;
import 'package:wger/models/nutrition/log.dart' as _i10;
import 'package:wger/models/nutrition/ingredient.dart' as _i11;
import 'package:wger/models/nutrition/log.dart' as _i9;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i8;
import 'package:wger/providers/ingredient_repository.dart' as _i11;
import 'package:wger/providers/ingredient_repository.dart' as _i10;
import 'package:wger/providers/measurement_repository.dart' as _i3;
import 'package:wger/providers/nutrition_repository.dart' as _i7;
@@ -263,50 +263,15 @@ class MockNutritionRepository extends _i1.Mock implements _i7.NutritionRepositor
as _i4.Future<_i2.Response>);
@override
_i4.Future<List<_i9.Ingredient>> searchIngredient(
String? name, {
String? languageCode = 'en',
_i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i9.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredient,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i4.Future<List<_i9.Ingredient>>.value(
<_i9.Ingredient>[],
),
)
as _i4.Future<List<_i9.Ingredient>>);
@override
_i4.Future<_i9.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientWithBarcode, [barcode]),
returnValue: _i4.Future<_i9.Ingredient?>.value(),
)
as _i4.Future<_i9.Ingredient?>);
@override
_i4.Stream<List<_i10.LogItem>> watchAllLogsHydrated() =>
_i4.Stream<List<_i9.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i4.Stream<List<_i10.LogItem>>.empty(),
returnValue: _i4.Stream<List<_i9.LogItem>>.empty(),
)
as _i4.Stream<List<_i10.LogItem>>);
as _i4.Stream<List<_i9.LogItem>>);
@override
_i4.Future<void> addLogLocalDrift(_i10.LogItem? log) =>
_i4.Future<void> addLogLocalDrift(_i9.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i4.Future<void>.value(),
@@ -327,38 +292,38 @@ class MockNutritionRepository extends _i1.Mock implements _i7.NutritionRepositor
/// A class which mocks [IngredientRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockIngredientRepository extends _i1.Mock implements _i11.IngredientRepository {
class MockIngredientRepository extends _i1.Mock implements _i10.IngredientRepository {
MockIngredientRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i4.Stream<_i9.Ingredient?> watchById(int? id) =>
_i4.Stream<_i11.Ingredient?> watchById(int? id) =>
(super.noSuchMethod(
Invocation.method(#watchById, [id]),
returnValue: _i4.Stream<_i9.Ingredient?>.empty(),
returnValue: _i4.Stream<_i11.Ingredient?>.empty(),
)
as _i4.Stream<_i9.Ingredient?>);
as _i4.Stream<_i11.Ingredient?>);
@override
_i4.Future<_i9.Ingredient?> getById(int? id) =>
_i4.Future<_i11.Ingredient?> getById(int? id) =>
(super.noSuchMethod(
Invocation.method(#getById, [id]),
returnValue: _i4.Future<_i9.Ingredient?>.value(),
returnValue: _i4.Future<_i11.Ingredient?>.value(),
)
as _i4.Future<_i9.Ingredient?>);
as _i4.Future<_i11.Ingredient?>);
@override
_i4.Future<List<_i9.Ingredient>> searchByName(
_i4.Future<List<_i11.Ingredient>> searchIngredientLocal(
String? term, {
bool? isVegan = false,
bool? isVegetarian = false,
_i9.NutriScore? nutriscoreMax,
_i11.NutriScore? nutriscoreMax,
int? limit = 100,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchByName,
#searchIngredientLocal,
[term],
{
#isVegan: isVegan,
@@ -367,9 +332,44 @@ class MockIngredientRepository extends _i1.Mock implements _i11.IngredientReposi
#limit: limit,
},
),
returnValue: _i4.Future<List<_i9.Ingredient>>.value(
<_i9.Ingredient>[],
returnValue: _i4.Future<List<_i11.Ingredient>>.value(
<_i11.Ingredient>[],
),
)
as _i4.Future<List<_i9.Ingredient>>);
as _i4.Future<List<_i11.Ingredient>>);
@override
_i4.Future<List<_i11.Ingredient>> searchIngredientServer(
String? name, {
String? languageCode = 'en',
_i10.IngredientSearchLanguage? searchLanguage = _i10.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i11.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredientServer,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i4.Future<List<_i11.Ingredient>>.value(
<_i11.Ingredient>[],
),
)
as _i4.Future<List<_i11.Ingredient>>);
@override
_i4.Future<_i11.Ingredient?> searchIngredientByBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientByBarcode, [barcode]),
returnValue: _i4.Future<_i11.Ingredient?>.value(),
)
as _i4.Future<_i11.Ingredient?>);
}

View File

@@ -21,8 +21,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
import 'package:wger/helpers/shared_preferences.dart';
import 'package:wger/providers/ingredient_repository.dart';
import 'package:wger/providers/nutrition_ingredient_filters_riverpod.dart';
import 'package:wger/providers/nutrition_repository.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

View File

@@ -28,26 +28,23 @@ import 'package:wger/helpers/shared_preferences.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/providers/ingredient_repository.dart';
import 'package:wger/providers/nutrition_repository.dart';
import 'package:wger/widgets/nutrition/widgets.dart';
import '../../test_data/nutritional_plans.dart';
import 'nutritional_plan_form_test.mocks.dart';
void main() {
late MockNutritionRepository mockRepo;
late MockIngredientRepository mockIngredientRepo;
setUp(() async {
SharedPreferences.setMockInitialValues(<String, Object>{});
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
await PreferenceHelper.instance.migrationSupportFunctionForSharedPreferences();
mockRepo = MockNutritionRepository();
mockIngredientRepo = MockIngredientRepository();
when(mockIngredientRepo.getById(any)).thenAnswer((_) async => null);
when(
mockRepo.searchIngredient(
mockIngredientRepo.searchIngredientServer(
any,
languageCode: anyNamed('languageCode'),
searchLanguage: anyNamed('searchLanguage'),
@@ -81,7 +78,6 @@ void main() {
Widget createWidgetUnderTest() {
return ProviderScope(
overrides: [
nutritionRepositoryProvider.overrideWithValue(mockRepo),
ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo),
],
child: MaterialApp(
@@ -132,7 +128,7 @@ void main() {
testWidgets('Shows only Vegan chip when ingredient is vegan', (WidgetTester tester) async {
// ingredient1 (Water) is vegan + vegetarian
when(
mockRepo.searchIngredient(
mockIngredientRepo.searchIngredientServer(
any,
languageCode: anyNamed('languageCode'),
searchLanguage: anyNamed('searchLanguage'),
@@ -156,7 +152,7 @@ void main() {
) async {
// milk is vegetarian but not vegan
when(
mockRepo.searchIngredient(
mockIngredientRepo.searchIngredientServer(
any,
languageCode: anyNamed('languageCode'),
searchLanguage: anyNamed('searchLanguage'),
@@ -178,7 +174,7 @@ void main() {
testWidgets('Shows no dietary chips when ingredient has no info', (WidgetTester tester) async {
// ingredient2 (Burger soup) has no dietary info
when(
mockRepo.searchIngredient(
mockIngredientRepo.searchIngredientServer(
any,
languageCode: anyNamed('languageCode'),
searchLanguage: anyNamed('searchLanguage'),
@@ -222,7 +218,7 @@ void main() {
// Assert
verify(
mockRepo.searchIngredient(
mockIngredientRepo.searchIngredientServer(
'Apple',
languageCode: 'en',
searchLanguage: IngredientSearchLanguage.current,
@@ -273,7 +269,7 @@ void main() {
// Assert — index 1 maps to NutriScore.a
verify(
mockRepo.searchIngredient(
mockIngredientRepo.searchIngredientServer(
'Apple',
languageCode: 'en',
searchLanguage: IngredientSearchLanguage.current,
@@ -293,7 +289,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 600));
verify(
mockRepo.searchIngredient(
mockIngredientRepo.searchIngredientServer(
'Apple',
languageCode: 'en',
searchLanguage: IngredientSearchLanguage.current,

View File

@@ -7,10 +7,10 @@ import 'dart:async' as _i4;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/nutrition/ingredient.dart' as _i6;
import 'package:wger/models/nutrition/log.dart' as _i7;
import 'package:wger/models/nutrition/ingredient.dart' as _i8;
import 'package:wger/models/nutrition/log.dart' as _i6;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/ingredient_repository.dart' as _i7;
import 'package:wger/providers/nutrition_repository.dart' as _i3;
// ignore_for_file: type=lint
@@ -177,50 +177,15 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
as _i4.Future<_i2.Response>);
@override
_i4.Future<List<_i6.Ingredient>> searchIngredient(
String? name, {
String? languageCode = 'en',
_i3.IngredientSearchLanguage? searchLanguage = _i3.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i6.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredient,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i4.Future<List<_i6.Ingredient>>.value(
<_i6.Ingredient>[],
),
)
as _i4.Future<List<_i6.Ingredient>>);
@override
_i4.Future<_i6.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientWithBarcode, [barcode]),
returnValue: _i4.Future<_i6.Ingredient?>.value(),
)
as _i4.Future<_i6.Ingredient?>);
@override
_i4.Stream<List<_i7.LogItem>> watchAllLogsHydrated() =>
_i4.Stream<List<_i6.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i4.Stream<List<_i7.LogItem>>.empty(),
returnValue: _i4.Stream<List<_i6.LogItem>>.empty(),
)
as _i4.Stream<List<_i7.LogItem>>);
as _i4.Stream<List<_i6.LogItem>>);
@override
_i4.Future<void> addLogLocalDrift(_i7.LogItem? log) =>
_i4.Future<void> addLogLocalDrift(_i6.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i4.Future<void>.value(),
@@ -241,38 +206,38 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
/// A class which mocks [IngredientRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository {
class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository {
MockIngredientRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i4.Stream<_i6.Ingredient?> watchById(int? id) =>
_i4.Stream<_i8.Ingredient?> watchById(int? id) =>
(super.noSuchMethod(
Invocation.method(#watchById, [id]),
returnValue: _i4.Stream<_i6.Ingredient?>.empty(),
returnValue: _i4.Stream<_i8.Ingredient?>.empty(),
)
as _i4.Stream<_i6.Ingredient?>);
as _i4.Stream<_i8.Ingredient?>);
@override
_i4.Future<_i6.Ingredient?> getById(int? id) =>
_i4.Future<_i8.Ingredient?> getById(int? id) =>
(super.noSuchMethod(
Invocation.method(#getById, [id]),
returnValue: _i4.Future<_i6.Ingredient?>.value(),
returnValue: _i4.Future<_i8.Ingredient?>.value(),
)
as _i4.Future<_i6.Ingredient?>);
as _i4.Future<_i8.Ingredient?>);
@override
_i4.Future<List<_i6.Ingredient>> searchByName(
_i4.Future<List<_i8.Ingredient>> searchIngredientLocal(
String? term, {
bool? isVegan = false,
bool? isVegetarian = false,
_i6.NutriScore? nutriscoreMax,
_i8.NutriScore? nutriscoreMax,
int? limit = 100,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchByName,
#searchIngredientLocal,
[term],
{
#isVegan: isVegan,
@@ -281,9 +246,44 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit
#limit: limit,
},
),
returnValue: _i4.Future<List<_i6.Ingredient>>.value(
<_i6.Ingredient>[],
returnValue: _i4.Future<List<_i8.Ingredient>>.value(
<_i8.Ingredient>[],
),
)
as _i4.Future<List<_i6.Ingredient>>);
as _i4.Future<List<_i8.Ingredient>>);
@override
_i4.Future<List<_i8.Ingredient>> searchIngredientServer(
String? name, {
String? languageCode = 'en',
_i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i8.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredientServer,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i4.Future<List<_i8.Ingredient>>.value(
<_i8.Ingredient>[],
),
)
as _i4.Future<List<_i8.Ingredient>>);
@override
_i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientByBarcode, [barcode]),
returnValue: _i4.Future<_i8.Ingredient?>.value(),
)
as _i4.Future<_i8.Ingredient?>);
}

View File

@@ -107,12 +107,16 @@ void main() {
mockIngredientRepo = MockIngredientRepository();
when(
mockRepo.searchIngredientWithBarcode('123'),
mockIngredientRepo.searchIngredientByBarcode('123'),
).thenAnswer((_) => Future.value(ingredient));
when(mockRepo.searchIngredientWithBarcode('')).thenAnswer((_) => Future.value(null));
when(mockRepo.searchIngredientWithBarcode('222')).thenAnswer((_) => Future.value(null));
when(
mockRepo.searchIngredient(
mockIngredientRepo.searchIngredientByBarcode(''),
).thenAnswer((_) => Future.value(null));
when(
mockIngredientRepo.searchIngredientByBarcode('222'),
).thenAnswer((_) => Future.value(null));
when(
mockIngredientRepo.searchIngredientServer(
any,
languageCode: anyNamed('languageCode'),
searchLanguage: anyNamed('searchLanguage'),

View File

@@ -7,10 +7,10 @@ import 'dart:async' as _i4;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/nutrition/ingredient.dart' as _i6;
import 'package:wger/models/nutrition/log.dart' as _i7;
import 'package:wger/models/nutrition/ingredient.dart' as _i8;
import 'package:wger/models/nutrition/log.dart' as _i6;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/ingredient_repository.dart' as _i7;
import 'package:wger/providers/nutrition_repository.dart' as _i3;
// ignore_for_file: type=lint
@@ -177,50 +177,15 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
as _i4.Future<_i2.Response>);
@override
_i4.Future<List<_i6.Ingredient>> searchIngredient(
String? name, {
String? languageCode = 'en',
_i3.IngredientSearchLanguage? searchLanguage = _i3.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i6.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredient,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i4.Future<List<_i6.Ingredient>>.value(
<_i6.Ingredient>[],
),
)
as _i4.Future<List<_i6.Ingredient>>);
@override
_i4.Future<_i6.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientWithBarcode, [barcode]),
returnValue: _i4.Future<_i6.Ingredient?>.value(),
)
as _i4.Future<_i6.Ingredient?>);
@override
_i4.Stream<List<_i7.LogItem>> watchAllLogsHydrated() =>
_i4.Stream<List<_i6.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i4.Stream<List<_i7.LogItem>>.empty(),
returnValue: _i4.Stream<List<_i6.LogItem>>.empty(),
)
as _i4.Stream<List<_i7.LogItem>>);
as _i4.Stream<List<_i6.LogItem>>);
@override
_i4.Future<void> addLogLocalDrift(_i7.LogItem? log) =>
_i4.Future<void> addLogLocalDrift(_i6.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i4.Future<void>.value(),
@@ -241,38 +206,38 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
/// A class which mocks [IngredientRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository {
class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository {
MockIngredientRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i4.Stream<_i6.Ingredient?> watchById(int? id) =>
_i4.Stream<_i8.Ingredient?> watchById(int? id) =>
(super.noSuchMethod(
Invocation.method(#watchById, [id]),
returnValue: _i4.Stream<_i6.Ingredient?>.empty(),
returnValue: _i4.Stream<_i8.Ingredient?>.empty(),
)
as _i4.Stream<_i6.Ingredient?>);
as _i4.Stream<_i8.Ingredient?>);
@override
_i4.Future<_i6.Ingredient?> getById(int? id) =>
_i4.Future<_i8.Ingredient?> getById(int? id) =>
(super.noSuchMethod(
Invocation.method(#getById, [id]),
returnValue: _i4.Future<_i6.Ingredient?>.value(),
returnValue: _i4.Future<_i8.Ingredient?>.value(),
)
as _i4.Future<_i6.Ingredient?>);
as _i4.Future<_i8.Ingredient?>);
@override
_i4.Future<List<_i6.Ingredient>> searchByName(
_i4.Future<List<_i8.Ingredient>> searchIngredientLocal(
String? term, {
bool? isVegan = false,
bool? isVegetarian = false,
_i6.NutriScore? nutriscoreMax,
_i8.NutriScore? nutriscoreMax,
int? limit = 100,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchByName,
#searchIngredientLocal,
[term],
{
#isVegan: isVegan,
@@ -281,9 +246,44 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit
#limit: limit,
},
),
returnValue: _i4.Future<List<_i6.Ingredient>>.value(
<_i6.Ingredient>[],
returnValue: _i4.Future<List<_i8.Ingredient>>.value(
<_i8.Ingredient>[],
),
)
as _i4.Future<List<_i6.Ingredient>>);
as _i4.Future<List<_i8.Ingredient>>);
@override
_i4.Future<List<_i8.Ingredient>> searchIngredientServer(
String? name, {
String? languageCode = 'en',
_i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i8.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredientServer,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i4.Future<List<_i8.Ingredient>>.value(
<_i8.Ingredient>[],
),
)
as _i4.Future<List<_i8.Ingredient>>);
@override
_i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientByBarcode, [barcode]),
returnValue: _i4.Future<_i8.Ingredient?>.value(),
)
as _i4.Future<_i8.Ingredient?>);
}

View File

@@ -11,11 +11,11 @@ import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:mockito/src/dummies.dart' as _i10;
import 'package:wger/models/body_weight/weight_entry.dart' as _i13;
import 'package:wger/models/nutrition/ingredient.dart' as _i6;
import 'package:wger/models/nutrition/log.dart' as _i7;
import 'package:wger/models/nutrition/ingredient.dart' as _i8;
import 'package:wger/models/nutrition/log.dart' as _i6;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5;
import 'package:wger/providers/body_weight_repository.dart' as _i12;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/ingredient_repository.dart' as _i7;
import 'package:wger/providers/nutrition_repository.dart' as _i3;
// ignore_for_file: type=lint
@@ -187,50 +187,15 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
as _i4.Future<_i2.Response>);
@override
_i4.Future<List<_i6.Ingredient>> searchIngredient(
String? name, {
String? languageCode = 'en',
_i3.IngredientSearchLanguage? searchLanguage = _i3.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i6.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredient,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i4.Future<List<_i6.Ingredient>>.value(
<_i6.Ingredient>[],
),
)
as _i4.Future<List<_i6.Ingredient>>);
@override
_i4.Future<_i6.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientWithBarcode, [barcode]),
returnValue: _i4.Future<_i6.Ingredient?>.value(),
)
as _i4.Future<_i6.Ingredient?>);
@override
_i4.Stream<List<_i7.LogItem>> watchAllLogsHydrated() =>
_i4.Stream<List<_i6.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i4.Stream<List<_i7.LogItem>>.empty(),
returnValue: _i4.Stream<List<_i6.LogItem>>.empty(),
)
as _i4.Stream<List<_i7.LogItem>>);
as _i4.Stream<List<_i6.LogItem>>);
@override
_i4.Future<void> addLogLocalDrift(_i7.LogItem? log) =>
_i4.Future<void> addLogLocalDrift(_i6.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i4.Future<void>.value(),
@@ -251,38 +216,38 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
/// A class which mocks [IngredientRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository {
class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository {
MockIngredientRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i4.Stream<_i6.Ingredient?> watchById(int? id) =>
_i4.Stream<_i8.Ingredient?> watchById(int? id) =>
(super.noSuchMethod(
Invocation.method(#watchById, [id]),
returnValue: _i4.Stream<_i6.Ingredient?>.empty(),
returnValue: _i4.Stream<_i8.Ingredient?>.empty(),
)
as _i4.Stream<_i6.Ingredient?>);
as _i4.Stream<_i8.Ingredient?>);
@override
_i4.Future<_i6.Ingredient?> getById(int? id) =>
_i4.Future<_i8.Ingredient?> getById(int? id) =>
(super.noSuchMethod(
Invocation.method(#getById, [id]),
returnValue: _i4.Future<_i6.Ingredient?>.value(),
returnValue: _i4.Future<_i8.Ingredient?>.value(),
)
as _i4.Future<_i6.Ingredient?>);
as _i4.Future<_i8.Ingredient?>);
@override
_i4.Future<List<_i6.Ingredient>> searchByName(
_i4.Future<List<_i8.Ingredient>> searchIngredientLocal(
String? term, {
bool? isVegan = false,
bool? isVegetarian = false,
_i6.NutriScore? nutriscoreMax,
_i8.NutriScore? nutriscoreMax,
int? limit = 100,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchByName,
#searchIngredientLocal,
[term],
{
#isVegan: isVegan,
@@ -291,11 +256,46 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit
#limit: limit,
},
),
returnValue: _i4.Future<List<_i6.Ingredient>>.value(
<_i6.Ingredient>[],
returnValue: _i4.Future<List<_i8.Ingredient>>.value(
<_i8.Ingredient>[],
),
)
as _i4.Future<List<_i6.Ingredient>>);
as _i4.Future<List<_i8.Ingredient>>);
@override
_i4.Future<List<_i8.Ingredient>> searchIngredientServer(
String? name, {
String? languageCode = 'en',
_i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i8.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredientServer,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i4.Future<List<_i8.Ingredient>>.value(
<_i8.Ingredient>[],
),
)
as _i4.Future<List<_i8.Ingredient>>);
@override
_i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientByBarcode, [barcode]),
returnValue: _i4.Future<_i8.Ingredient?>.value(),
)
as _i4.Future<_i8.Ingredient?>);
}
/// A class which mocks [Client].

View File

@@ -11,12 +11,12 @@ import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:mockito/src/dummies.dart' as _i11;
import 'package:wger/models/body_weight/weight_entry.dart' as _i14;
import 'package:wger/models/nutrition/ingredient.dart' as _i7;
import 'package:wger/models/nutrition/log.dart' as _i8;
import 'package:wger/models/nutrition/ingredient.dart' as _i9;
import 'package:wger/models/nutrition/log.dart' as _i7;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i6;
import 'package:wger/models/user/profile.dart' as _i3;
import 'package:wger/providers/body_weight_repository.dart' as _i13;
import 'package:wger/providers/ingredient_repository.dart' as _i9;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/nutrition_repository.dart' as _i4;
import 'package:wger/providers/user_profile_repository.dart' as _i15;
@@ -193,50 +193,15 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor
as _i5.Future<_i2.Response>);
@override
_i5.Future<List<_i7.Ingredient>> searchIngredient(
String? name, {
String? languageCode = 'en',
_i4.IngredientSearchLanguage? searchLanguage = _i4.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i7.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredient,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i5.Future<List<_i7.Ingredient>>.value(
<_i7.Ingredient>[],
),
)
as _i5.Future<List<_i7.Ingredient>>);
@override
_i5.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientWithBarcode, [barcode]),
returnValue: _i5.Future<_i7.Ingredient?>.value(),
)
as _i5.Future<_i7.Ingredient?>);
@override
_i5.Stream<List<_i8.LogItem>> watchAllLogsHydrated() =>
_i5.Stream<List<_i7.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i5.Stream<List<_i8.LogItem>>.empty(),
returnValue: _i5.Stream<List<_i7.LogItem>>.empty(),
)
as _i5.Stream<List<_i8.LogItem>>);
as _i5.Stream<List<_i7.LogItem>>);
@override
_i5.Future<void> addLogLocalDrift(_i8.LogItem? log) =>
_i5.Future<void> addLogLocalDrift(_i7.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i5.Future<void>.value(),
@@ -257,38 +222,38 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor
/// A class which mocks [IngredientRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockIngredientRepository extends _i1.Mock implements _i9.IngredientRepository {
class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository {
MockIngredientRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i5.Stream<_i7.Ingredient?> watchById(int? id) =>
_i5.Stream<_i9.Ingredient?> watchById(int? id) =>
(super.noSuchMethod(
Invocation.method(#watchById, [id]),
returnValue: _i5.Stream<_i7.Ingredient?>.empty(),
returnValue: _i5.Stream<_i9.Ingredient?>.empty(),
)
as _i5.Stream<_i7.Ingredient?>);
as _i5.Stream<_i9.Ingredient?>);
@override
_i5.Future<_i7.Ingredient?> getById(int? id) =>
_i5.Future<_i9.Ingredient?> getById(int? id) =>
(super.noSuchMethod(
Invocation.method(#getById, [id]),
returnValue: _i5.Future<_i7.Ingredient?>.value(),
returnValue: _i5.Future<_i9.Ingredient?>.value(),
)
as _i5.Future<_i7.Ingredient?>);
as _i5.Future<_i9.Ingredient?>);
@override
_i5.Future<List<_i7.Ingredient>> searchByName(
_i5.Future<List<_i9.Ingredient>> searchIngredientLocal(
String? term, {
bool? isVegan = false,
bool? isVegetarian = false,
_i7.NutriScore? nutriscoreMax,
_i9.NutriScore? nutriscoreMax,
int? limit = 100,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchByName,
#searchIngredientLocal,
[term],
{
#isVegan: isVegan,
@@ -297,11 +262,46 @@ class MockIngredientRepository extends _i1.Mock implements _i9.IngredientReposit
#limit: limit,
},
),
returnValue: _i5.Future<List<_i7.Ingredient>>.value(
<_i7.Ingredient>[],
returnValue: _i5.Future<List<_i9.Ingredient>>.value(
<_i9.Ingredient>[],
),
)
as _i5.Future<List<_i7.Ingredient>>);
as _i5.Future<List<_i9.Ingredient>>);
@override
_i5.Future<List<_i9.Ingredient>> searchIngredientServer(
String? name, {
String? languageCode = 'en',
_i8.IngredientSearchLanguage? searchLanguage = _i8.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i9.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredientServer,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i5.Future<List<_i9.Ingredient>>.value(
<_i9.Ingredient>[],
),
)
as _i5.Future<List<_i9.Ingredient>>);
@override
_i5.Future<_i9.Ingredient?> searchIngredientByBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientByBarcode, [barcode]),
returnValue: _i5.Future<_i9.Ingredient?>.value(),
)
as _i5.Future<_i9.Ingredient?>);
}
/// A class which mocks [Client].

View File

@@ -8,12 +8,12 @@ import 'dart:async' as _i5;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/body_weight/weight_entry.dart' as _i11;
import 'package:wger/models/nutrition/ingredient.dart' as _i7;
import 'package:wger/models/nutrition/log.dart' as _i8;
import 'package:wger/models/nutrition/ingredient.dart' as _i9;
import 'package:wger/models/nutrition/log.dart' as _i7;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i6;
import 'package:wger/models/user/profile.dart' as _i3;
import 'package:wger/providers/body_weight_repository.dart' as _i10;
import 'package:wger/providers/ingredient_repository.dart' as _i9;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/nutrition_repository.dart' as _i4;
import 'package:wger/providers/user_profile_repository.dart' as _i12;
@@ -185,50 +185,15 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor
as _i5.Future<_i2.Response>);
@override
_i5.Future<List<_i7.Ingredient>> searchIngredient(
String? name, {
String? languageCode = 'en',
_i4.IngredientSearchLanguage? searchLanguage = _i4.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i7.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredient,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i5.Future<List<_i7.Ingredient>>.value(
<_i7.Ingredient>[],
),
)
as _i5.Future<List<_i7.Ingredient>>);
@override
_i5.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientWithBarcode, [barcode]),
returnValue: _i5.Future<_i7.Ingredient?>.value(),
)
as _i5.Future<_i7.Ingredient?>);
@override
_i5.Stream<List<_i8.LogItem>> watchAllLogsHydrated() =>
_i5.Stream<List<_i7.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i5.Stream<List<_i8.LogItem>>.empty(),
returnValue: _i5.Stream<List<_i7.LogItem>>.empty(),
)
as _i5.Stream<List<_i8.LogItem>>);
as _i5.Stream<List<_i7.LogItem>>);
@override
_i5.Future<void> addLogLocalDrift(_i8.LogItem? log) =>
_i5.Future<void> addLogLocalDrift(_i7.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i5.Future<void>.value(),
@@ -249,38 +214,38 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor
/// A class which mocks [IngredientRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockIngredientRepository extends _i1.Mock implements _i9.IngredientRepository {
class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository {
MockIngredientRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i5.Stream<_i7.Ingredient?> watchById(int? id) =>
_i5.Stream<_i9.Ingredient?> watchById(int? id) =>
(super.noSuchMethod(
Invocation.method(#watchById, [id]),
returnValue: _i5.Stream<_i7.Ingredient?>.empty(),
returnValue: _i5.Stream<_i9.Ingredient?>.empty(),
)
as _i5.Stream<_i7.Ingredient?>);
as _i5.Stream<_i9.Ingredient?>);
@override
_i5.Future<_i7.Ingredient?> getById(int? id) =>
_i5.Future<_i9.Ingredient?> getById(int? id) =>
(super.noSuchMethod(
Invocation.method(#getById, [id]),
returnValue: _i5.Future<_i7.Ingredient?>.value(),
returnValue: _i5.Future<_i9.Ingredient?>.value(),
)
as _i5.Future<_i7.Ingredient?>);
as _i5.Future<_i9.Ingredient?>);
@override
_i5.Future<List<_i7.Ingredient>> searchByName(
_i5.Future<List<_i9.Ingredient>> searchIngredientLocal(
String? term, {
bool? isVegan = false,
bool? isVegetarian = false,
_i7.NutriScore? nutriscoreMax,
_i9.NutriScore? nutriscoreMax,
int? limit = 100,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchByName,
#searchIngredientLocal,
[term],
{
#isVegan: isVegan,
@@ -289,11 +254,46 @@ class MockIngredientRepository extends _i1.Mock implements _i9.IngredientReposit
#limit: limit,
},
),
returnValue: _i5.Future<List<_i7.Ingredient>>.value(
<_i7.Ingredient>[],
returnValue: _i5.Future<List<_i9.Ingredient>>.value(
<_i9.Ingredient>[],
),
)
as _i5.Future<List<_i7.Ingredient>>);
as _i5.Future<List<_i9.Ingredient>>);
@override
_i5.Future<List<_i9.Ingredient>> searchIngredientServer(
String? name, {
String? languageCode = 'en',
_i8.IngredientSearchLanguage? searchLanguage = _i8.IngredientSearchLanguage.current,
bool? isVegan = false,
bool? isVegetarian = false,
_i9.NutriScore? nutriscoreMax,
}) =>
(super.noSuchMethod(
Invocation.method(
#searchIngredientServer,
[name],
{
#languageCode: languageCode,
#searchLanguage: searchLanguage,
#isVegan: isVegan,
#isVegetarian: isVegetarian,
#nutriscoreMax: nutriscoreMax,
},
),
returnValue: _i5.Future<List<_i9.Ingredient>>.value(
<_i9.Ingredient>[],
),
)
as _i5.Future<List<_i9.Ingredient>>);
@override
_i5.Future<_i9.Ingredient?> searchIngredientByBarcode(String? barcode) =>
(super.noSuchMethod(
Invocation.method(#searchIngredientByBarcode, [barcode]),
returnValue: _i5.Future<_i9.Ingredient?>.value(),
)
as _i5.Future<_i9.Ingredient?>);
}
/// A class which mocks [BodyWeightRepository].