forked from eatvio/eatvio_app
feat(tests): menu, settings, remove icov, remove generated files from % tests
This commit is contained in:
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user