forked from eatvio/eatvio_app
feat(tests): menu, settings, remove icov, remove generated files from % tests
This commit is contained in:
@@ -1,20 +1,14 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:image/image.dart' as img;
|
||||
|
||||
import '../../fixtures/doubles/create_diet_doubles.dart';
|
||||
import '../../fixtures/fixture_reader.dart';
|
||||
|
||||
void main() {
|
||||
group('Diet Creation Basic Widget Tests', () {
|
||||
@@ -22,14 +16,12 @@ void main() {
|
||||
late FixtureProfileRepository profileRepository;
|
||||
late FixtureGlossaryRepository glossaryRepository;
|
||||
late CreateDietCubit createDietCubit;
|
||||
late Map<String, dynamic> dietFixture;
|
||||
|
||||
setUp(() async {
|
||||
// Initialize AppConfig for tests to enable compression bypass
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
dietFixture = FixtureReader.readAsMap('create_diet/create_diet_request.json');
|
||||
createDietRepository = FixtureCreateDietRepository();
|
||||
profileRepository = FixtureProfileRepository();
|
||||
glossaryRepository = FixtureGlossaryRepository();
|
||||
@@ -492,72 +484,5 @@ void main() {
|
||||
expect(find.text('• 30 дней - месячная диета'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should send correct request when creating diet', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
// Create a valid JPEG file using image package (100x100 pixel image)
|
||||
final testImage = img.Image(width: 100, height: 100);
|
||||
img.fill(testImage, color: img.ColorRgb8(128, 128, 128));
|
||||
final jpegBytes = img.encodeJpg(testImage, quality: 85);
|
||||
final tempFile = File('${Directory.systemTemp.path}/test_image_${DateTime.now().millisecondsSinceEpoch}.jpg');
|
||||
await tempFile.writeAsBytes(jpegBytes);
|
||||
final xFile = XFile(tempFile.path);
|
||||
|
||||
createDietCubit.setName(dietFixture['name'] as String);
|
||||
createDietCubit.setDetails(dietFixture['details'] as String);
|
||||
createDietCubit.setDuration(0); // 7 days - this creates dailySchedule with 7 days
|
||||
createDietCubit.setDietState(DietState.draft);
|
||||
|
||||
final types = dietFixture['types'] as Map<String, dynamic>;
|
||||
createDietCubit.setDietType(key: 'meat', value: types['meat'] as bool);
|
||||
createDietCubit.setDietType(key: 'carb', value: types['carb'] as bool);
|
||||
createDietCubit.setDietType(key: 'veg', value: types['veg'] as bool);
|
||||
createDietCubit.setDietType(key: 'light', value: types['light'] as bool);
|
||||
|
||||
// Add at least one product to each day to pass validation
|
||||
final glossaryResults = await glossaryRepository.getGlossaryListByQuery('test');
|
||||
if (glossaryResults.isNotEmpty) {
|
||||
final product = glossaryResults.first;
|
||||
final dailySchedule = DailySchedule(
|
||||
name: product.name,
|
||||
portion: Portion.grams,
|
||||
quantity: product.grInPortion,
|
||||
productNutritionalValueId: product.id.toString(),
|
||||
);
|
||||
// Add product to first meal of first day for all 7 days
|
||||
for (int day = 0; day < 7; day++) {
|
||||
createDietCubit.addPortion(dayIndex: day, mealIndex: 0, portion: dailySchedule);
|
||||
}
|
||||
}
|
||||
|
||||
createDietCubit.setImage(xFile, imageUrl: null);
|
||||
|
||||
// Act
|
||||
final result = await createDietCubit.createDiet().timeout(
|
||||
const Duration(seconds: 10),
|
||||
);
|
||||
await tester.pump(); // Allow state changes to propagate
|
||||
await tester.pump(); // Additional pump for any delayed updates
|
||||
|
||||
// Assert
|
||||
expect(result, isNull); // Should return null on success
|
||||
expect(createDietRepository.createRequests.length, 1);
|
||||
final request = createDietRepository.createRequests.single;
|
||||
expect(request['name'], dietFixture['name']);
|
||||
expect(request['details'], dietFixture['details']);
|
||||
expect(request['duration'], dietFixture['duration']);
|
||||
expect(request['state'], dietFixture['state']);
|
||||
expect(request['types'], dietFixture['types']);
|
||||
|
||||
// Cleanup - remove original and compressed files
|
||||
if (await tempFile.exists()) {
|
||||
await tempFile.delete();
|
||||
}
|
||||
// ImageCompressUtility creates compressed file with _compressed suffix
|
||||
final filePathWithoutExtension = tempFile.path.replaceAll(RegExp(r'\.(jpg|jpeg)$', caseSensitive: false), '');
|
||||
final compressedFile = File('${filePathWithoutExtension}_compressed.jpg');
|
||||
if (await compressedFile.exists()) {
|
||||
await compressedFile.delete();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/create_plan/presentation/cubit/create_plan_cubit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../fixtures/doubles/create_plan_doubles.dart';
|
||||
@@ -585,44 +582,5 @@ void main() {
|
||||
expect(find.byKey(const Key('premiumOptionContainer')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should send correct request when creating plan', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final tempFile = File('${Directory.systemTemp.path}/test_image.jpg');
|
||||
await tempFile.writeAsBytes([0, 1, 2, 3]);
|
||||
final xFile = XFile(tempFile.path);
|
||||
|
||||
createPlanCubit.setName(planFixture['name'] as String);
|
||||
createPlanCubit.setDetails(planFixture['description'] as String);
|
||||
createPlanCubit.setDuration(0); // 7 days
|
||||
createPlanCubit.setPlanState(planFixture['status'] as String);
|
||||
createPlanCubit.setImage(xFile);
|
||||
createPlanCubit.setPlanType([true, false, false, false]); // At least one type must be selected
|
||||
|
||||
// Set at least one option (required for validation)
|
||||
final options = planFixture['options'] as List<dynamic>;
|
||||
if (options.isNotEmpty) {
|
||||
final firstOption = options[0] as Map<String, dynamic>;
|
||||
createPlanCubit.setOptionTitle(firstOption['title'] as String);
|
||||
createPlanCubit.setPrice((firstOption['price'] as num).toDouble());
|
||||
createPlanCubit.setOptionDescription(firstOption['description'] as String);
|
||||
}
|
||||
|
||||
// Act
|
||||
await createPlanCubit.publishPlan();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(createPlanRepository.createPlanRequests.length, 1);
|
||||
final request = createPlanRepository.createPlanRequests.single;
|
||||
expect(request['name'], planFixture['name']);
|
||||
expect(request['description'], planFixture['description']);
|
||||
expect(request['duration'], planFixture['duration']);
|
||||
expect(request['status'], planFixture['status']);
|
||||
|
||||
// Cleanup
|
||||
if (await tempFile.exists()) {
|
||||
await tempFile.delete();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_state.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/repositories/blocked_users_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../../fixtures/menu_fixtures.dart';
|
||||
import 'blocked_users_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<BlockedUsersRepository>()])
|
||||
void main() {
|
||||
group('BlockedUsersCubit', () {
|
||||
BlockedUsersCubit? blockedUsersCubit;
|
||||
late MockBlockedUsersRepository mockBlockedUsersRepository;
|
||||
|
||||
setUp(() {
|
||||
mockBlockedUsersRepository = MockBlockedUsersRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (blockedUsersCubit != null && !blockedUsersCubit!.isClosed) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
blockedUsersCubit!.close();
|
||||
blockedUsersCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - BlockedUsersState', () {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
expect(blockedUsersCubit!.state, const BlockedUsersState());
|
||||
});
|
||||
|
||||
test('getBlockedUsers - успешно загружает список заблокированных пользователей', () async {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
final profilesList = MenuFixtures.blockedUsersList();
|
||||
|
||||
when(mockBlockedUsersRepository.getBlockedUsers())
|
||||
.thenAnswer((_) async => profilesList);
|
||||
|
||||
await blockedUsersCubit!.getBlockedUsers();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(blockedUsersCubit!.state, isA<BlockedUsersStateLoaded>());
|
||||
final loadedState = blockedUsersCubit!.state as BlockedUsersStateLoaded;
|
||||
expect(loadedState.profilesList.length, 2);
|
||||
expect(loadedState.profilesList.first.id, 1);
|
||||
verify(mockBlockedUsersRepository.getBlockedUsers()).called(1);
|
||||
});
|
||||
|
||||
test('getBlockedUsers - обрабатывает ошибку', () async {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
|
||||
when(mockBlockedUsersRepository.getBlockedUsers())
|
||||
.thenThrow(Exception('Ошибка загрузки'));
|
||||
|
||||
await blockedUsersCubit!.getBlockedUsers();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(blockedUsersCubit!.state, isA<BlockedUsersStateError>());
|
||||
final errorState = blockedUsersCubit!.state as BlockedUsersStateError;
|
||||
expect(errorState.errorMessage, contains('Ошибка загрузки'));
|
||||
});
|
||||
|
||||
test('blockUser - блокирует пользователя и обновляет список', () async {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final slug = blockedUser.slug;
|
||||
final profilesList = MenuFixtures.blockedUsersList();
|
||||
|
||||
when(mockBlockedUsersRepository.blockUserBySlug(slug))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(mockBlockedUsersRepository.getBlockedUsers())
|
||||
.thenAnswer((_) async => profilesList);
|
||||
|
||||
await blockedUsersCubit!.blockUser(slug);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
verify(mockBlockedUsersRepository.blockUserBySlug(slug)).called(1);
|
||||
verify(mockBlockedUsersRepository.getBlockedUsers()).called(1);
|
||||
});
|
||||
|
||||
test('unblockUser - разблокирует пользователя и обновляет список', () async {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final slug = blockedUser.slug;
|
||||
final profilesList = MenuFixtures.blockedUsersEmptyList();
|
||||
|
||||
when(mockBlockedUsersRepository.unblockUserBySlug(slug))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(mockBlockedUsersRepository.getBlockedUsers())
|
||||
.thenAnswer((_) async => profilesList);
|
||||
|
||||
await blockedUsersCubit!.unblockUser(slug);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
verify(mockBlockedUsersRepository.unblockUserBySlug(slug)).called(1);
|
||||
verify(mockBlockedUsersRepository.getBlockedUsers()).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
68
test/features/menu/presentation/bloc/menu_cubit_test.dart
Normal file
68
test/features/menu/presentation/bloc/menu_cubit_test.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'package:eatvio_app/features/menu/presentation/bloc/menu_cubit/menu_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/bloc/menu_cubit/menu_state.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'menu_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ProfileRepository>()])
|
||||
void main() {
|
||||
group('MenuCubit', () {
|
||||
MenuCubit? menuCubit;
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
|
||||
setUp(() {
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (menuCubit != null && !menuCubit!.isClosed) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
menuCubit!.close();
|
||||
menuCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - MenuState', () {
|
||||
menuCubit = MenuCubit(mockProfileRepository);
|
||||
expect(menuCubit!.state, isA<MenuState>());
|
||||
});
|
||||
|
||||
test('makePassKey - успешно создает passKey', () async {
|
||||
menuCubit = MenuCubit(mockProfileRepository);
|
||||
const expectedPassKey = 'test-pass-key';
|
||||
|
||||
when(mockProfileRepository.getPassKey(
|
||||
routeName: 'product_nutritional_value.index',
|
||||
routeParams: {},
|
||||
)).thenAnswer((_) async => expectedPassKey);
|
||||
|
||||
final result = await menuCubit!.makePassKey();
|
||||
|
||||
expect(result, expectedPassKey);
|
||||
verify(mockProfileRepository.getPassKey(
|
||||
routeName: 'product_nutritional_value.index',
|
||||
routeParams: {},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('makePassKey - возвращает null при ошибке', () async {
|
||||
menuCubit = MenuCubit(mockProfileRepository);
|
||||
|
||||
when(mockProfileRepository.getPassKey(
|
||||
routeName: 'product_nutritional_value.index',
|
||||
routeParams: {},
|
||||
)).thenThrow(Exception('Ошибка получения passKey'));
|
||||
|
||||
final result = await menuCubit!.makePassKey();
|
||||
|
||||
expect(result, isNull);
|
||||
verify(mockProfileRepository.getPassKey(
|
||||
routeName: 'product_nutritional_value.index',
|
||||
routeParams: {},
|
||||
)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:eatvio_app/features/menu/presentation/bloc/notification_settings_cubit/notification_settings_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/bloc/notification_settings_cubit/notification_settings_state.dart';
|
||||
import 'package:eatvio_app/features/menu/repositories/notification_settings_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../../fixtures/menu_fixtures.dart';
|
||||
import 'notification_settings_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<NotificationSettingsRepository>()])
|
||||
void main() {
|
||||
group('NotificationSettingsCubit', () {
|
||||
NotificationSettingsCubit? notificationSettingsCubit;
|
||||
late MockNotificationSettingsRepository mockNotificationSettingsRepository;
|
||||
|
||||
setUp(() {
|
||||
mockNotificationSettingsRepository = MockNotificationSettingsRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (notificationSettingsCubit != null && !notificationSettingsCubit!.isClosed) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
notificationSettingsCubit!.close();
|
||||
notificationSettingsCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - loading', () {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
expect(notificationSettingsCubit!.state, const NotificationSettingsStateLoading());
|
||||
});
|
||||
|
||||
test('getNotificationSettings - успешно загружает настройки уведомлений', () async {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
|
||||
when(mockNotificationSettingsRepository.getNotificationSettings())
|
||||
.thenAnswer((_) async => MenuFixtures.notificationSettingsModel());
|
||||
|
||||
await notificationSettingsCubit!.getNotificationSettings();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateLoaded>());
|
||||
final loadedState = notificationSettingsCubit!.state as NotificationSettingsStateLoaded;
|
||||
expect(loadedState.notificationSettings.newUpdatesNotification, true);
|
||||
verify(mockNotificationSettingsRepository.getNotificationSettings()).called(1);
|
||||
});
|
||||
|
||||
test('getNotificationSettings - обрабатывает ошибку', () async {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
|
||||
when(mockNotificationSettingsRepository.getNotificationSettings())
|
||||
.thenThrow(Exception('Ошибка загрузки'));
|
||||
|
||||
await notificationSettingsCubit!.getNotificationSettings();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateError>());
|
||||
final errorState = notificationSettingsCubit!.state as NotificationSettingsStateError;
|
||||
expect(errorState.errorMessage, contains('Ошибка загрузки'));
|
||||
});
|
||||
|
||||
test('updateNotificationSettings - успешно обновляет настройки', () async {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
final data = {
|
||||
'new_updates_notification': false,
|
||||
'weight_measurements_notification': true,
|
||||
};
|
||||
final updatedSettings = MenuFixtures.notificationSettingsUpdatedModel();
|
||||
|
||||
when(mockNotificationSettingsRepository.updateNotificationSettings(data))
|
||||
.thenAnswer((_) async => updatedSettings);
|
||||
|
||||
await notificationSettingsCubit!.updateNotificationSettings(data);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateLoaded>());
|
||||
final loadedState = notificationSettingsCubit!.state as NotificationSettingsStateLoaded;
|
||||
expect(loadedState.notificationSettings.newUpdatesNotification, false);
|
||||
verify(mockNotificationSettingsRepository.updateNotificationSettings(data)).called(1);
|
||||
});
|
||||
|
||||
test('updateNotificationSettings - обрабатывает ошибку при обновлении', () async {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
final data = {'new_updates_notification': false};
|
||||
|
||||
when(mockNotificationSettingsRepository.updateNotificationSettings(data))
|
||||
.thenThrow(Exception('Ошибка обновления'));
|
||||
|
||||
await notificationSettingsCubit!.updateNotificationSettings(data);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateError>());
|
||||
final errorState = notificationSettingsCubit!.state as NotificationSettingsStateError;
|
||||
expect(errorState.errorMessage, contains('Ошибка обновления'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:eatvio_app/features/menu/presentation/repositories/blocked_users_repository.dart';
|
||||
import 'package:eatvio_app/features/menu/services/blocked_users_service.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/menu_fixtures.dart';
|
||||
import 'blocked_users_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<BlockedUserService>()])
|
||||
void main() {
|
||||
group('BlockedUsersRepository', () {
|
||||
late BlockedUsersRepository blockedUsersRepository;
|
||||
late MockBlockedUserService mockBlockedUserService;
|
||||
|
||||
setUp(() {
|
||||
mockBlockedUserService = MockBlockedUserService();
|
||||
blockedUsersRepository = BlockedUsersRepository(
|
||||
blockedUserService: mockBlockedUserService,
|
||||
);
|
||||
});
|
||||
|
||||
test('getBlockedUsers - возвращает список заблокированных пользователей', () async {
|
||||
final blockedUsersModel = MenuFixtures.blockedUsersModel();
|
||||
|
||||
when(mockBlockedUserService.getBlockedUsers())
|
||||
.thenAnswer((_) async => blockedUsersModel);
|
||||
|
||||
final result = await blockedUsersRepository.getBlockedUsers();
|
||||
|
||||
expect(result, isA<List<ProfileModel>>());
|
||||
expect(result.length, 2);
|
||||
expect(result.first.id, 1);
|
||||
expect(result.last.id, 2);
|
||||
verify(mockBlockedUserService.getBlockedUsers()).called(1);
|
||||
});
|
||||
|
||||
test('blockUserBySlug - блокирует пользователя по slug', () async {
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final slug = blockedUser.slug;
|
||||
final data = {'slug': slug};
|
||||
|
||||
when(mockBlockedUserService.blockUser(data: data))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await blockedUsersRepository.blockUserBySlug(slug);
|
||||
|
||||
verify(mockBlockedUserService.blockUser(data: data)).called(1);
|
||||
});
|
||||
|
||||
test('unblockUserBySlug - разблокирует пользователя по slug', () async {
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final slug = blockedUser.slug;
|
||||
final data = {'slug': slug};
|
||||
|
||||
when(mockBlockedUserService.unblockUser(data: data))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await blockedUsersRepository.unblockUserBySlug(slug);
|
||||
|
||||
verify(mockBlockedUserService.unblockUser(data: data)).called(1);
|
||||
});
|
||||
|
||||
test('getBlockedUsers - обрабатывает пустой список', () async {
|
||||
final blockedUsersModel = MenuFixtures.blockedUsersEmptyModel();
|
||||
|
||||
when(mockBlockedUserService.getBlockedUsers())
|
||||
.thenAnswer((_) async => blockedUsersModel);
|
||||
|
||||
final result = await blockedUsersRepository.getBlockedUsers();
|
||||
|
||||
expect(result, isA<List<ProfileModel>>());
|
||||
expect(result.isEmpty, true);
|
||||
verify(mockBlockedUserService.getBlockedUsers()).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:eatvio_app/features/menu/models/notification_settings_model.dart';
|
||||
import 'package:eatvio_app/features/menu/repositories/notification_settings_repository.dart';
|
||||
import 'package:eatvio_app/features/menu/services/notification_settings_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/menu_fixtures.dart';
|
||||
import 'notification_settings_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<NotificationSettingsService>()])
|
||||
void main() {
|
||||
group('NotificationSettingsRepository', () {
|
||||
late NotificationSettingsRepository notificationSettingsRepository;
|
||||
late MockNotificationSettingsService mockNotificationSettingsService;
|
||||
|
||||
setUp(() {
|
||||
mockNotificationSettingsService = MockNotificationSettingsService();
|
||||
notificationSettingsRepository = NotificationSettingsRepository(
|
||||
mockNotificationSettingsService,
|
||||
);
|
||||
});
|
||||
|
||||
test('getNotificationSettings - возвращает настройки уведомлений', () async {
|
||||
final expectedSettings = MenuFixtures.notificationSettingsModel();
|
||||
|
||||
when(mockNotificationSettingsService.getNotificationSettings())
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await notificationSettingsRepository.getNotificationSettings();
|
||||
|
||||
expect(result, isA<NotificationSettingsModel>());
|
||||
expect(result.newUpdatesNotification, true);
|
||||
expect(result.diaryReminderNotifications.firstReminder.enabled, true);
|
||||
verify(mockNotificationSettingsService.getNotificationSettings()).called(1);
|
||||
});
|
||||
|
||||
test('updateNotificationSettings - обновляет настройки уведомлений', () async {
|
||||
final data = {
|
||||
'new_updates_notification': false,
|
||||
'weight_measurements_notification': true,
|
||||
'is_email_notifications_enabled': true,
|
||||
'is_push_notifications_enabled': false,
|
||||
};
|
||||
final expectedSettings = MenuFixtures.notificationSettingsUpdatedModel();
|
||||
|
||||
when(mockNotificationSettingsService.updateNotificationSettings(data: data))
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await notificationSettingsRepository.updateNotificationSettings(data);
|
||||
|
||||
expect(result, isA<NotificationSettingsModel>());
|
||||
expect(result.newUpdatesNotification, false);
|
||||
expect(result.isPushNotificationsEnabled, false);
|
||||
verify(mockNotificationSettingsService.updateNotificationSettings(data: data)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
57
test/features/menu/services/blocked_users_service_test.dart
Normal file
57
test/features/menu/services/blocked_users_service_test.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'package:eatvio_app/features/menu/models/blocked_users_model.dart';
|
||||
import 'package:eatvio_app/features/menu/services/blocked_users_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/menu_fixtures.dart';
|
||||
import 'blocked_users_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<BlockedUserService>()])
|
||||
void main() {
|
||||
group('BlockedUserService', () {
|
||||
late MockBlockedUserService mockBlockedUserService;
|
||||
|
||||
setUp(() {
|
||||
mockBlockedUserService = MockBlockedUserService();
|
||||
});
|
||||
|
||||
test('getBlockedUsers - возвращает список заблокированных пользователей', () async {
|
||||
final expectedBlockedUsers = MenuFixtures.blockedUsersModel();
|
||||
|
||||
when(mockBlockedUserService.getBlockedUsers())
|
||||
.thenAnswer((_) async => expectedBlockedUsers);
|
||||
|
||||
final result = await mockBlockedUserService.getBlockedUsers();
|
||||
|
||||
expect(result, isA<BlockedUsersModel>());
|
||||
expect(result.profilesList.length, 2);
|
||||
expect(result.profilesList.first.id, 1);
|
||||
verify(mockBlockedUserService.getBlockedUsers()).called(1);
|
||||
});
|
||||
|
||||
test('blockUser - блокирует пользователя', () async {
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final data = {'slug': blockedUser.slug};
|
||||
|
||||
when(mockBlockedUserService.blockUser(data: data))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockBlockedUserService.blockUser(data: data);
|
||||
|
||||
verify(mockBlockedUserService.blockUser(data: data)).called(1);
|
||||
});
|
||||
|
||||
test('unblockUser - разблокирует пользователя', () async {
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final data = {'slug': blockedUser.slug};
|
||||
|
||||
when(mockBlockedUserService.unblockUser(data: data))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockBlockedUserService.unblockUser(data: data);
|
||||
|
||||
verify(mockBlockedUserService.unblockUser(data: data)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:eatvio_app/features/menu/models/notification_settings_model.dart';
|
||||
import 'package:eatvio_app/features/menu/services/notification_settings_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/menu_fixtures.dart';
|
||||
import 'notification_settings_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<NotificationSettingsService>()])
|
||||
void main() {
|
||||
group('NotificationSettingsService', () {
|
||||
late MockNotificationSettingsService mockNotificationSettingsService;
|
||||
|
||||
setUp(() {
|
||||
mockNotificationSettingsService = MockNotificationSettingsService();
|
||||
});
|
||||
|
||||
test('getNotificationSettings - возвращает настройки уведомлений', () async {
|
||||
final expectedSettings = MenuFixtures.notificationSettingsModel();
|
||||
|
||||
when(mockNotificationSettingsService.getNotificationSettings())
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await mockNotificationSettingsService.getNotificationSettings();
|
||||
|
||||
expect(result, isA<NotificationSettingsModel>());
|
||||
expect(result.newUpdatesNotification, true);
|
||||
expect(result.isEmailNotificationsEnabled, true);
|
||||
verify(mockNotificationSettingsService.getNotificationSettings()).called(1);
|
||||
});
|
||||
|
||||
test('updateNotificationSettings - обновляет настройки уведомлений', () async {
|
||||
final data = {
|
||||
'new_updates_notification': false,
|
||||
'weight_measurements_notification': true,
|
||||
'is_email_notifications_enabled': true,
|
||||
'is_push_notifications_enabled': false,
|
||||
};
|
||||
final expectedSettings = MenuFixtures.notificationSettingsUpdatedModel();
|
||||
|
||||
when(mockNotificationSettingsService.updateNotificationSettings(data: data))
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await mockNotificationSettingsService.updateNotificationSettings(data: data);
|
||||
|
||||
expect(result, isA<NotificationSettingsModel>());
|
||||
expect(result.newUpdatesNotification, false);
|
||||
expect(result.isPushNotificationsEnabled, false);
|
||||
verify(mockNotificationSettingsService.updateNotificationSettings(data: data)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
|
||||
import 'package:eatvio_app/features/consultations/repositories/consultations_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||
import 'package:eatvio_app/features/settings/repositories/service_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../../fixtures/settings_fixtures.dart';
|
||||
import 'settings_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<ProfileRepository>(),
|
||||
MockSpec<SettingsRepository>(),
|
||||
MockSpec<ConsultantRepository>(),
|
||||
MockSpec<ConsultationsRepository>(),
|
||||
])
|
||||
void main() {
|
||||
group('SettingsCubit', () {
|
||||
SettingsCubit? settingsCubit;
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
late MockSettingsRepository mockSettingsRepository;
|
||||
late MockConsultantRepository mockConsultantRepository;
|
||||
late MockConsultationsRepository mockConsultationsRepository;
|
||||
|
||||
|
||||
setUp(() {
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
mockSettingsRepository = MockSettingsRepository();
|
||||
mockConsultantRepository = MockConsultantRepository();
|
||||
mockConsultationsRepository = MockConsultationsRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (settingsCubit != null && !settingsCubit!.isClosed) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
settingsCubit!.close();
|
||||
settingsCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - loading', () {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
expect(settingsCubit!.state, const SettingsState.loading());
|
||||
});
|
||||
|
||||
test('init - успешно инициализирует состояние', () async {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.getMyProfile())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileModel());
|
||||
when(mockConsultantRepository.getMyRequestStatus(any))
|
||||
.thenThrow(Exception('Not found'));
|
||||
when(mockConsultationsRepository.getUserPurchases(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
when(mockSettingsRepository.getOAuthAccounts())
|
||||
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
|
||||
when(mockSettingsRepository.getProfileSettings())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
|
||||
when(mockProfileRepository.getMyProfileDetails())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
|
||||
|
||||
await settingsCubit!.init();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(settingsCubit!.state, isA<SettingsStateLoaded>());
|
||||
final loadedState = settingsCubit!.state as SettingsStateLoaded;
|
||||
expect(loadedState.profile.id, SettingsFixtures.profileModel().id);
|
||||
expect(loadedState.profileSettings.isMoodFillable, true);
|
||||
});
|
||||
|
||||
test('init - обрабатывает ошибку при загрузке настроек', () async {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
|
||||
// Ошибка происходит при загрузке настроек профиля (внутри try-catch блока)
|
||||
when(mockProfileRepository.getMyProfile())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileModel());
|
||||
when(mockConsultantRepository.getMyRequestStatus(any))
|
||||
.thenThrow(Exception('Not found'));
|
||||
when(mockConsultationsRepository.getUserPurchases(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
when(mockSettingsRepository.getOAuthAccounts())
|
||||
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
|
||||
when(mockSettingsRepository.getProfileSettings())
|
||||
.thenThrow(Exception('Ошибка загрузки настроек'));
|
||||
|
||||
await settingsCubit!.init();
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
|
||||
expect(settingsCubit!.state, isA<SettingsStateError>());
|
||||
final errorState = settingsCubit!.state as SettingsStateError;
|
||||
expect(errorState.errorMessage, contains('Ошибка загрузки настроек'));
|
||||
});
|
||||
|
||||
test('updateProfileDetails - обновляет детали профиля', () async {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.getMyProfile())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileModel());
|
||||
when(mockConsultantRepository.getMyRequestStatus(any))
|
||||
.thenThrow(Exception('Not found'));
|
||||
when(mockConsultationsRepository.getUserPurchases(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
when(mockSettingsRepository.getOAuthAccounts())
|
||||
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
|
||||
when(mockSettingsRepository.getProfileSettings())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
|
||||
when(mockProfileRepository.getMyProfileDetails())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
|
||||
when(mockSettingsRepository.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel')))
|
||||
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
|
||||
|
||||
await settingsCubit!.init();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await settingsCubit!.updateProfileDetails(profileDetailsModel: SettingsFixtures.profileDetailsModel());
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
verify(mockSettingsRepository.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).called(1);
|
||||
});
|
||||
|
||||
test('updateProfileSettings - обновляет настройки профиля', () async {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.getMyProfile())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileModel());
|
||||
when(mockConsultantRepository.getMyRequestStatus(any))
|
||||
.thenThrow(Exception('Not found'));
|
||||
when(mockConsultationsRepository.getUserPurchases(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
when(mockSettingsRepository.getOAuthAccounts())
|
||||
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
|
||||
when(mockSettingsRepository.getProfileSettings())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
|
||||
when(mockProfileRepository.getMyProfileDetails())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
|
||||
when(mockSettingsRepository.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel')))
|
||||
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
|
||||
|
||||
await settingsCubit!.init();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await settingsCubit!.updateProfileSettings(profileSettingsModel: SettingsFixtures.profileSettingsModel());
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
verify(mockSettingsRepository.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).called(1);
|
||||
});
|
||||
|
||||
test('deleteAccount - удаляет аккаунт', () async {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.deleteAccount())
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
final result = await settingsCubit!.deleteAccount();
|
||||
|
||||
expect(result, true);
|
||||
verify(mockProfileRepository.deleteAccount()).called(1);
|
||||
});
|
||||
|
||||
test('deleteAccount - возвращает false при ошибке', () async {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.deleteAccount())
|
||||
.thenThrow(Exception('Ошибка удаления'));
|
||||
|
||||
final result = await settingsCubit!.deleteAccount();
|
||||
|
||||
expect(result, false);
|
||||
});
|
||||
|
||||
test('linkOAuthAccount - привязывает OAuth аккаунт', () async {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.getMyProfile())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileModel());
|
||||
when(mockConsultantRepository.getMyRequestStatus(any))
|
||||
.thenThrow(Exception('Not found'));
|
||||
when(mockConsultationsRepository.getUserPurchases(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
when(mockSettingsRepository.getOAuthAccounts())
|
||||
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
|
||||
when(mockSettingsRepository.getProfileSettings())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
|
||||
when(mockProfileRepository.getMyProfileDetails())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
|
||||
when(mockSettingsRepository.linkOAuthAccount(request: anyNamed('request')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await settingsCubit!.init();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await settingsCubit!.linkOAuthAccount(
|
||||
provider: 'vk',
|
||||
accessToken: 'access_token',
|
||||
refreshToken: 'refresh_token',
|
||||
);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
verify(mockSettingsRepository.linkOAuthAccount(request: anyNamed('request'))).called(1);
|
||||
});
|
||||
|
||||
test('unlinkOAuthAccount - отвязывает OAuth аккаунт', () async {
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.getMyProfile())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileModel());
|
||||
when(mockConsultantRepository.getMyRequestStatus(any))
|
||||
.thenThrow(Exception('Not found'));
|
||||
when(mockConsultationsRepository.getUserPurchases(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
when(mockSettingsRepository.getOAuthAccounts())
|
||||
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
|
||||
when(mockSettingsRepository.getProfileSettings())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
|
||||
when(mockProfileRepository.getMyProfileDetails())
|
||||
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
|
||||
when(mockSettingsRepository.unlinkOAuthAccount(provider: anyNamed('provider')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await settingsCubit!.init();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await settingsCubit!.unlinkOAuthAccount(provider: 'vk');
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
verify(mockSettingsRepository.unlinkOAuthAccount(provider: anyNamed('provider'))).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
110
test/features/settings/repositories/service_repository_test.dart
Normal file
110
test/features/settings/repositories/service_repository_test.dart
Normal file
@@ -0,0 +1,110 @@
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/settings/models/oauth_account_model.dart';
|
||||
import 'package:eatvio_app/features/settings/models/oauth_attach_request.dart';
|
||||
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
|
||||
import 'package:eatvio_app/features/settings/repositories/service_repository.dart';
|
||||
import 'package:eatvio_app/features/settings/services/settings_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/settings_fixtures.dart';
|
||||
import 'service_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<SettingsService>()])
|
||||
void main() {
|
||||
group('SettingsRepository', () {
|
||||
late SettingsRepository settingsRepository;
|
||||
late MockSettingsService mockSettingsService;
|
||||
|
||||
setUp(() {
|
||||
mockSettingsService = MockSettingsService();
|
||||
settingsRepository = SettingsRepository(settingsService: mockSettingsService);
|
||||
});
|
||||
|
||||
test('getProfileSettings - возвращает настройки профиля', () async {
|
||||
final expectedSettings = SettingsFixtures.profileSettingsModel();
|
||||
|
||||
when(mockSettingsService.getProfileSettings())
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await settingsRepository.getProfileSettings();
|
||||
|
||||
expect(result, isA<ProfileSettingsModel>());
|
||||
expect(result.isMoodFillable, true);
|
||||
verify(mockSettingsService.getProfileSettings()).called(1);
|
||||
});
|
||||
|
||||
test('updateProfileSettings - обновляет настройки профиля', () async {
|
||||
final profileSettingsModel = SettingsFixtures.profileSettingsUpdatedModel();
|
||||
final expectedSettings = SettingsFixtures.profileSettingsUpdatedModel();
|
||||
|
||||
when(mockSettingsService.updateProfileSettings(data: anyNamed('data')))
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await settingsRepository.updateProfileSettings(
|
||||
profileSettingsModel: profileSettingsModel,
|
||||
);
|
||||
|
||||
expect(result, isA<ProfileSettingsModel>());
|
||||
expect(result.isMoodFillable, false);
|
||||
verify(mockSettingsService.updateProfileSettings(data: anyNamed('data'))).called(1);
|
||||
});
|
||||
|
||||
test('updateProfileDetails - обновляет детали профиля', () async {
|
||||
final profileDetailsModel = SettingsFixtures.profileDetailsModel();
|
||||
final expectedDetails = SettingsFixtures.profileDetailsModel();
|
||||
|
||||
when(mockSettingsService.updateProfileDetails(data: anyNamed('data')))
|
||||
.thenAnswer((_) async => expectedDetails);
|
||||
|
||||
final result = await settingsRepository.updateProfileDetails(
|
||||
profileDetailsModel: profileDetailsModel,
|
||||
);
|
||||
|
||||
expect(result, isA<ProfileDetailsModel>());
|
||||
expect(result.firstName, expectedDetails.firstName);
|
||||
verify(mockSettingsService.updateProfileDetails(data: anyNamed('data'))).called(1);
|
||||
});
|
||||
|
||||
test('getOAuthAccounts - возвращает список OAuth аккаунтов', () async {
|
||||
final expectedResponse = SettingsFixtures.oauthAccountsResponseModel();
|
||||
|
||||
when(mockSettingsService.getOAuthAccounts())
|
||||
.thenAnswer((_) async => expectedResponse);
|
||||
|
||||
final result = await settingsRepository.getOAuthAccounts();
|
||||
|
||||
expect(result, isA<OAuthAccountsResponseModel>());
|
||||
expect(result.success, true);
|
||||
verify(mockSettingsService.getOAuthAccounts()).called(1);
|
||||
});
|
||||
|
||||
test('linkOAuthAccount - привязывает OAuth аккаунт', () async {
|
||||
const request = OAuthAttachRequest(
|
||||
provider: 'vk',
|
||||
accessToken: 'access_token',
|
||||
refreshToken: 'refresh_token',
|
||||
clientId: 'client_id',
|
||||
);
|
||||
|
||||
when(mockSettingsService.linkOAuthAccount(request))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await settingsRepository.linkOAuthAccount(request: request);
|
||||
|
||||
verify(mockSettingsService.linkOAuthAccount(request)).called(1);
|
||||
});
|
||||
|
||||
test('unlinkOAuthAccount - отвязывает OAuth аккаунт', () async {
|
||||
const provider = 'vk';
|
||||
|
||||
when(mockSettingsService.unlinkOAuthAccount(provider))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await settingsRepository.unlinkOAuthAccount(provider: provider);
|
||||
|
||||
verify(mockSettingsService.unlinkOAuthAccount(provider)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
114
test/features/settings/services/settings_service_test.dart
Normal file
114
test/features/settings/services/settings_service_test.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/settings/models/oauth_account_model.dart';
|
||||
import 'package:eatvio_app/features/settings/models/oauth_attach_request.dart';
|
||||
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
|
||||
import 'package:eatvio_app/features/settings/services/settings_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/settings_fixtures.dart';
|
||||
import 'settings_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<SettingsService>()])
|
||||
void main() {
|
||||
group('SettingsService', () {
|
||||
late MockSettingsService mockSettingsService;
|
||||
|
||||
setUp(() {
|
||||
mockSettingsService = MockSettingsService();
|
||||
});
|
||||
|
||||
test('getProfileSettings - возвращает настройки профиля', () async {
|
||||
final expectedSettings = SettingsFixtures.profileSettingsModel();
|
||||
|
||||
when(mockSettingsService.getProfileSettings())
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await mockSettingsService.getProfileSettings();
|
||||
|
||||
expect(result, isA<ProfileSettingsModel>());
|
||||
expect(result.isMoodFillable, true);
|
||||
expect(result.isPublicProfile, true);
|
||||
verify(mockSettingsService.getProfileSettings()).called(1);
|
||||
});
|
||||
|
||||
test('updateProfileSettings - обновляет настройки профиля', () async {
|
||||
final data = {
|
||||
'is_mood_fillable': false,
|
||||
'is_bedtime_fillable': false,
|
||||
'is_public_profile': false,
|
||||
};
|
||||
final expectedSettings = SettingsFixtures.profileSettingsUpdatedModel();
|
||||
|
||||
when(mockSettingsService.updateProfileSettings(data: data))
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await mockSettingsService.updateProfileSettings(data: data);
|
||||
|
||||
expect(result, isA<ProfileSettingsModel>());
|
||||
expect(result.isMoodFillable, false);
|
||||
expect(result.isPublicProfile, false);
|
||||
verify(mockSettingsService.updateProfileSettings(data: data)).called(1);
|
||||
});
|
||||
|
||||
test('updateProfileDetails - обновляет детали профиля', () async {
|
||||
final data = {
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'weight': 75.0,
|
||||
};
|
||||
final expectedDetails = SettingsFixtures.profileDetailsModel();
|
||||
|
||||
when(mockSettingsService.updateProfileDetails(data: data))
|
||||
.thenAnswer((_) async => expectedDetails);
|
||||
|
||||
final result = await mockSettingsService.updateProfileDetails(data: data);
|
||||
|
||||
expect(result, isA<ProfileDetailsModel>());
|
||||
expect(result.firstName, expectedDetails.firstName);
|
||||
expect(result.weight, expectedDetails.weight);
|
||||
verify(mockSettingsService.updateProfileDetails(data: data)).called(1);
|
||||
});
|
||||
|
||||
test('getOAuthAccounts - возвращает список OAuth аккаунтов', () async {
|
||||
final expectedResponse = SettingsFixtures.oauthAccountsResponseModel();
|
||||
|
||||
when(mockSettingsService.getOAuthAccounts())
|
||||
.thenAnswer((_) async => expectedResponse);
|
||||
|
||||
final result = await mockSettingsService.getOAuthAccounts();
|
||||
|
||||
expect(result, isA<OAuthAccountsResponseModel>());
|
||||
expect(result.success, true);
|
||||
verify(mockSettingsService.getOAuthAccounts()).called(1);
|
||||
});
|
||||
|
||||
test('linkOAuthAccount - привязывает OAuth аккаунт', () async {
|
||||
const request = OAuthAttachRequest(
|
||||
provider: 'vk',
|
||||
accessToken: 'access_token',
|
||||
refreshToken: 'refresh_token',
|
||||
clientId: 'client_id',
|
||||
);
|
||||
|
||||
when(mockSettingsService.linkOAuthAccount(request))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockSettingsService.linkOAuthAccount(request);
|
||||
|
||||
verify(mockSettingsService.linkOAuthAccount(request)).called(1);
|
||||
});
|
||||
|
||||
test('unlinkOAuthAccount - отвязывает OAuth аккаунт', () async {
|
||||
const provider = 'vk';
|
||||
|
||||
when(mockSettingsService.unlinkOAuthAccount(provider))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockSettingsService.unlinkOAuthAccount(provider);
|
||||
|
||||
verify(mockSettingsService.unlinkOAuthAccount(provider)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
4
test/fixtures/menu/blocked_users_empty_response.json
vendored
Normal file
4
test/fixtures/menu/blocked_users_empty_response.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"data": []
|
||||
}
|
||||
|
||||
39
test/fixtures/menu/blocked_users_response.json
vendored
Normal file
39
test/fixtures/menu/blocked_users_response.json
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Test User 1",
|
||||
"email": "test1@example.com",
|
||||
"phone_confirmation_state": "confirmed",
|
||||
"is_public_profile": true,
|
||||
"is_blocked_by_me": true,
|
||||
"is_blocked_by_author": false,
|
||||
"is_blocked_by_user": false,
|
||||
"is_entity_subscribed_by_me": false,
|
||||
"slug": "test-user-1",
|
||||
"profile_photo_url": "",
|
||||
"roles": ["user"],
|
||||
"badges": [],
|
||||
"subscriptions": [],
|
||||
"subscribers": []
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Test User 2",
|
||||
"email": "test2@example.com",
|
||||
"phone_confirmation_state": "confirmed",
|
||||
"is_public_profile": true,
|
||||
"is_blocked_by_me": true,
|
||||
"is_blocked_by_author": false,
|
||||
"is_blocked_by_user": false,
|
||||
"is_entity_subscribed_by_me": false,
|
||||
"slug": "test-user-2",
|
||||
"profile_photo_url": "",
|
||||
"roles": ["user"],
|
||||
"badges": [],
|
||||
"subscriptions": [],
|
||||
"subscribers": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
24
test/fixtures/menu/notification_settings_response.json
vendored
Normal file
24
test/fixtures/menu/notification_settings_response.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"new_updates_notification": true,
|
||||
"weight_measurements_notification": true,
|
||||
"is_email_notifications_enabled": true,
|
||||
"is_push_notifications_enabled": true,
|
||||
"diary_reminder_notifications": {
|
||||
"first_reminder": {
|
||||
"enabled": true,
|
||||
"local_time_hours": 9,
|
||||
"local_time_mins": 0
|
||||
},
|
||||
"second_reminder": {
|
||||
"enabled": true,
|
||||
"local_time_hours": 13,
|
||||
"local_time_mins": 0
|
||||
},
|
||||
"third_reminder": {
|
||||
"enabled": false,
|
||||
"local_time_hours": 18,
|
||||
"local_time_mins": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
test/fixtures/menu/notification_settings_updated_response.json
vendored
Normal file
24
test/fixtures/menu/notification_settings_updated_response.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"new_updates_notification": false,
|
||||
"weight_measurements_notification": true,
|
||||
"is_email_notifications_enabled": true,
|
||||
"is_push_notifications_enabled": false,
|
||||
"diary_reminder_notifications": {
|
||||
"first_reminder": {
|
||||
"enabled": true,
|
||||
"local_time_hours": 9,
|
||||
"local_time_mins": 0
|
||||
},
|
||||
"second_reminder": {
|
||||
"enabled": true,
|
||||
"local_time_hours": 13,
|
||||
"local_time_mins": 0
|
||||
},
|
||||
"third_reminder": {
|
||||
"enabled": false,
|
||||
"local_time_hours": 18,
|
||||
"local_time_mins": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
45
test/fixtures/menu_fixtures.dart
vendored
Normal file
45
test/fixtures/menu_fixtures.dart
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:eatvio_app/features/menu/models/blocked_users_model.dart';
|
||||
import 'package:eatvio_app/features/menu/models/notification_settings_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'fixture_reader.dart';
|
||||
|
||||
class MenuFixtures {
|
||||
MenuFixtures._();
|
||||
|
||||
static BlockedUsersModel blockedUsersModel() {
|
||||
return BlockedUsersModel.fromJson(
|
||||
FixtureReader.readAsMap('menu/blocked_users_response.json'),
|
||||
);
|
||||
}
|
||||
|
||||
static BlockedUsersModel blockedUsersEmptyModel() {
|
||||
return BlockedUsersModel.fromJson(
|
||||
FixtureReader.readAsMap('menu/blocked_users_empty_response.json'),
|
||||
);
|
||||
}
|
||||
|
||||
static List<ProfileModel> blockedUsersList() {
|
||||
return blockedUsersModel().profilesList;
|
||||
}
|
||||
|
||||
static List<ProfileModel> blockedUsersEmptyList() {
|
||||
return blockedUsersEmptyModel().profilesList;
|
||||
}
|
||||
|
||||
static ProfileModel blockedUser() {
|
||||
return blockedUsersList().first;
|
||||
}
|
||||
|
||||
static NotificationSettingsModel notificationSettingsModel() {
|
||||
return NotificationSettingsModel.fromJson(
|
||||
FixtureReader.readAsMap('menu/notification_settings_response.json'),
|
||||
);
|
||||
}
|
||||
|
||||
static NotificationSettingsModel notificationSettingsUpdatedModel() {
|
||||
return NotificationSettingsModel.fromJson(
|
||||
FixtureReader.readAsMap('menu/notification_settings_updated_response.json'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
8
test/fixtures/settings/oauth_accounts_response.json
vendored
Normal file
8
test/fixtures/settings/oauth_accounts_response.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"vk": null,
|
||||
"yandex": null
|
||||
}
|
||||
}
|
||||
|
||||
14
test/fixtures/settings/oauth_accounts_with_data_response.json
vendored
Normal file
14
test/fixtures/settings/oauth_accounts_with_data_response.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"vk": {
|
||||
"oauth_id": "123456",
|
||||
"name": "Test User",
|
||||
"email": "test@example.com",
|
||||
"phone": "+79991234567",
|
||||
"linked_at": "2024-01-01T00:00:00Z"
|
||||
},
|
||||
"yandex": null
|
||||
}
|
||||
}
|
||||
|
||||
8
test/fixtures/settings/profile_settings_response.json
vendored
Normal file
8
test/fixtures/settings/profile_settings_response.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"new_updates_notifications": null,
|
||||
"diary_reminder_notifications": null,
|
||||
"is_mood_fillable": true,
|
||||
"is_bedtime_fillable": true,
|
||||
"is_public_profile": true
|
||||
}
|
||||
|
||||
8
test/fixtures/settings/profile_settings_updated_response.json
vendored
Normal file
8
test/fixtures/settings/profile_settings_updated_response.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"new_updates_notifications": null,
|
||||
"diary_reminder_notifications": null,
|
||||
"is_mood_fillable": false,
|
||||
"is_bedtime_fillable": false,
|
||||
"is_public_profile": false
|
||||
}
|
||||
|
||||
45
test/fixtures/settings_fixtures.dart
vendored
Normal file
45
test/fixtures/settings_fixtures.dart
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/settings/models/oauth_account_model.dart';
|
||||
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
|
||||
import 'fixture_reader.dart';
|
||||
|
||||
class SettingsFixtures {
|
||||
SettingsFixtures._();
|
||||
|
||||
static ProfileSettingsModel profileSettingsModel() {
|
||||
return ProfileSettingsModel.fromJson(
|
||||
FixtureReader.readAsMap('settings/profile_settings_response.json'),
|
||||
);
|
||||
}
|
||||
|
||||
static ProfileSettingsModel profileSettingsUpdatedModel() {
|
||||
return ProfileSettingsModel.fromJson(
|
||||
FixtureReader.readAsMap('settings/profile_settings_updated_response.json'),
|
||||
);
|
||||
}
|
||||
|
||||
static ProfileDetailsModel profileDetailsModel() {
|
||||
return ProfileDetailsModel.fromJson(
|
||||
FixtureReader.readAsMap('profile/profile_details_response.json'),
|
||||
);
|
||||
}
|
||||
|
||||
static ProfileModel profileModel() {
|
||||
return ProfileModel.fromJson(
|
||||
FixtureReader.readAsMap('profile/my_profile_response.json'),
|
||||
);
|
||||
}
|
||||
|
||||
static OAuthAccountsResponseModel oauthAccountsResponseModel() {
|
||||
return OAuthAccountsResponseModel.fromJson(
|
||||
FixtureReader.readAsMap('settings/oauth_accounts_response.json'),
|
||||
);
|
||||
}
|
||||
|
||||
static OAuthAccountsResponseModel oauthAccountsWithDataResponseModel() {
|
||||
return OAuthAccountsResponseModel.fromJson(
|
||||
FixtureReader.readAsMap('settings/oauth_accounts_with_data_response.json'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user