forked from eatvio/eatvio_app
refactor: clean up imports and improve code readability across various files
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,79 +1,81 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/notifications/service/notifications_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
import 'notifications_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<Dio>()])
|
||||
void main() {
|
||||
group('NotificationsService', () {
|
||||
late NotificationsService notificationsService;
|
||||
late MockDio mockDio;
|
||||
|
||||
setUp(() {
|
||||
mockDio = MockDio();
|
||||
notificationsService = NotificationsService(mockDio);
|
||||
});
|
||||
|
||||
test('getNotifications - возвращает уведомления', () async {
|
||||
const page = 1;
|
||||
final json = FixtureReader.readAsMap('notifications/notifications_response.json');
|
||||
final response = Response(
|
||||
data: {
|
||||
'data': json['notifications'],
|
||||
'current_page': json['pagination']['current_page'],
|
||||
'last_page': json['pagination']['last_page'],
|
||||
'per_page': 10,
|
||||
'total': 1,
|
||||
},
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/profile/notifications'),
|
||||
);
|
||||
|
||||
when(mockDio.get(any))
|
||||
.thenAnswer((_) async => response);
|
||||
|
||||
final result = await notificationsService.getNotifications(page: page);
|
||||
|
||||
expect(result, isA<Map<String, dynamic>?>());
|
||||
expect(result, isNotNull);
|
||||
expect(result!['notifications'], isA<List>());
|
||||
verify(mockDio.get(any)).called(1);
|
||||
});
|
||||
|
||||
test('markNotificationsAsRead - помечает уведомления как прочитанные', () async {
|
||||
final response = Response(
|
||||
data: {},
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/profile/mark_notifications_as_readed'),
|
||||
);
|
||||
|
||||
when(mockDio.post(any))
|
||||
.thenAnswer((_) async => response);
|
||||
|
||||
await notificationsService.markNotificationsAsRead();
|
||||
|
||||
verify(mockDio.post(any)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/notifications/service/notifications_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
import 'notifications_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<Dio>()])
|
||||
void main() {
|
||||
group('NotificationsService', () {
|
||||
late NotificationsService notificationsService;
|
||||
late MockDio mockDio;
|
||||
|
||||
setUp(() {
|
||||
mockDio = MockDio();
|
||||
notificationsService = NotificationsService(mockDio);
|
||||
});
|
||||
|
||||
test('getNotifications - возвращает уведомления', () async {
|
||||
const page = 1;
|
||||
final json = FixtureReader.readAsMap('notifications/notifications_response.json');
|
||||
final response = Response(
|
||||
data: {
|
||||
'data': json['notifications'],
|
||||
'current_page': json['pagination']['current_page'],
|
||||
'last_page': json['pagination']['last_page'],
|
||||
'per_page': 10,
|
||||
'total': 1,
|
||||
},
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/profile/notifications'),
|
||||
);
|
||||
|
||||
when(mockDio.get(any))
|
||||
.thenAnswer((_) async => response);
|
||||
|
||||
final result = await notificationsService.getNotifications(page: page);
|
||||
|
||||
expect(result, isA<Map<String, dynamic>?>());
|
||||
expect(result, isNotNull);
|
||||
expect(result!['notifications'], isA<List>());
|
||||
verify(mockDio.get(any)).called(1);
|
||||
});
|
||||
|
||||
test('markNotificationsAsRead - помечает уведомления как прочитанные', () async {
|
||||
final response = Response(
|
||||
data: {},
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/profile/mark_notifications_as_readed'),
|
||||
);
|
||||
|
||||
when(mockDio.post(any))
|
||||
.thenAnswer((_) async => response);
|
||||
|
||||
await notificationsService.markNotificationsAsRead();
|
||||
|
||||
verify(mockDio.post(any)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user