feat(tests): tests coverage 67.2

This commit is contained in:
misha
2026-01-19 12:32:11 +03:00
parent 13ccf56df0
commit 44ede73ceb
20 changed files with 5084 additions and 409 deletions

View File

@@ -254,6 +254,254 @@ void main() {
expect(() => notificationsService.markNotificationsAsRead(), throwsA(isA<DioException>()));
});
test('getNotifications - определяет тип из поля notification_class_name в data', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'data': {
'notification_class_name': 'App\\Notifications\\Diet\\DietStarted',
'diet_name': 'Test Diet',
},
'read_at': null,
'created_at': '2024-01-01T12:00:00Z',
},
],
'current_page': 1,
'last_page': 1,
'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, isNotNull);
expect(result!['notifications'], isA<List>());
expect(result['notifications'].length, 1);
});
test('getNotifications - обрабатывает уведомление без типа (unknown)', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'data': {
'some_field': 'value',
},
'read_at': null,
'created_at': '2024-01-01T12:00:00Z',
},
],
'current_page': 1,
'last_page': 1,
'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, isNotNull);
expect(result!['notifications'], isA<List>());
expect(result['notifications'].length, 1);
});
test('getNotifications - обрабатывает уведомление с data не Map', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'type': 'chosen-plan-started-to-client',
'data': 'not-a-map', // data не является Map
'read_at': null,
'created_at': '2024-01-01T12:00:00Z',
},
],
'current_page': 1,
'last_page': 1,
'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, isNotNull);
expect(result!['notifications'], isA<List>());
// При ошибке парсинга возвращается UnknownNotification
expect(result['notifications'].length, 1);
});
test('getNotifications - обрабатывает уведомление с null data', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'type': 'chosen-plan-started-to-client',
'data': null,
'read_at': null,
'created_at': '2024-01-01T12:00:00Z',
},
],
'current_page': 1,
'last_page': 1,
'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, isNotNull);
expect(result!['notifications'], isA<List>());
// При ошибке парсинга возвращается UnknownNotification
expect(result['notifications'].length, 1);
});
test('getNotifications - обрабатывает уведомление с пустым списком', () async {
const page = 1;
final response = Response(
data: {
'data': [],
'current_page': 1,
'last_page': 1,
'per_page': 10,
'total': 0,
},
statusCode: 200,
requestOptions: RequestOptions(path: '/api/profile/notifications'),
);
when(mockDio.get(any)).thenAnswer((_) async => response);
final result = await notificationsService.getNotifications(page: page);
expect(result, isNotNull);
expect(result!['notifications'], isA<List>());
expect(result['notifications'].length, 0);
expect(result['pagination']['total'], 0);
});
test('getNotifications - обрабатывает уведомление с различными типами пагинации', () async {
const page = 2;
final response = Response(
data: {
'data': [
{
'type': 'chosen-plan-started-to-client',
'data': {
'plan_name': 'Test Plan',
'plan_id': 1,
},
'read_at': null,
'created_at': '2024-01-01T12:00:00Z',
},
],
'current_page': 2,
'last_page': 3,
'per_page': 10,
'total': 25,
},
statusCode: 200,
requestOptions: RequestOptions(path: '/api/profile/notifications'),
);
when(mockDio.get(any)).thenAnswer((_) async => response);
final result = await notificationsService.getNotifications(page: page);
expect(result, isNotNull);
expect(result!['pagination']['current_page'], 2);
expect(result['pagination']['last_page'], 3);
expect(result['pagination']['per_page'], 10);
expect(result['pagination']['total'], 25);
});
test('getNotifications - обрабатывает уведомление с type null', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'type': null,
'data': {
'some_field': 'value',
},
'read_at': null,
'created_at': '2024-01-01T12:00:00Z',
},
],
'current_page': 1,
'last_page': 1,
'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, isNotNull);
expect(result!['notifications'], isA<List>());
expect(result['notifications'].length, 1);
});
test('getNotifications - обрабатывает уведомление с notification_class_name null', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'notification_class_name': null,
'data': {
'some_field': 'value',
},
'read_at': null,
'created_at': '2024-01-01T12:00:00Z',
},
],
'current_page': 1,
'last_page': 1,
'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, isNotNull);
expect(result!['notifications'], isA<List>());
expect(result['notifications'].length, 1);
});
});
}