feat(app): refactoring of sentry using, feat(become_consultant): fixed possible infinite loading, feat(push_notifications): fixed push navigation from paid plan push

This commit is contained in:
misha
2026-04-07 10:05:11 +03:00
parent b6b13b1db5
commit aac085def4
133 changed files with 2344 additions and 2456 deletions

View File

@@ -103,11 +103,12 @@ void main() {
.called(1);
});
test('rethrows exception when error occurs', () async {
test('returns false when prefs throws (error is reported)', () async {
when(mockPrefs.getInt(PrefsKeys.registrationDate))
.thenThrow(Exception('Test error'));
expect(() => cubit.checkRegistrationDate(), throwsException);
final result = await cubit.checkRegistrationDate();
expect(result, false);
});
});
}

View File

@@ -0,0 +1,114 @@
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:eatvio_app/core/error_reporting/error_report_policy.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
void main() {
group('ErrorReportPolicy.shouldReport', () {
test('returns false for null', () {
expect(ErrorReportPolicy.shouldReport(null), false);
});
test('returns false for String', () {
expect(ErrorReportPolicy.shouldReport('user message'), false);
});
test('returns false for SocketException', () {
expect(ErrorReportPolicy.shouldReport(const SocketException('offline')), false);
});
test('returns false for cancelled Dio request', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.cancel,
);
expect(ErrorReportPolicy.shouldReport(e), false);
});
test('returns false for Dio timeouts', () {
for (final type in [
DioExceptionType.connectionTimeout,
DioExceptionType.sendTimeout,
DioExceptionType.receiveTimeout,
]) {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: type,
);
expect(ErrorReportPolicy.shouldReport(e), false, reason: '$type');
}
});
test('returns false for HTTP 4xx with response', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
response: Response(statusCode: 422, requestOptions: RequestOptions(path: '/x')),
type: DioExceptionType.badResponse,
);
expect(ErrorReportPolicy.shouldReport(e), false);
});
test('returns false for HTTP 5xx (handled by sentry_dio failed-request)', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
response: Response(statusCode: 503, requestOptions: RequestOptions(path: '/x')),
type: DioExceptionType.badResponse,
);
expect(ErrorReportPolicy.shouldReport(e), false);
});
test('returns false for Dio connectionError / offline-style', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.connectionError,
error: const SocketException('offline'),
);
expect(ErrorReportPolicy.shouldReport(e), false);
});
test('returns true for arbitrary exceptions', () {
expect(ErrorReportPolicy.shouldReport(StateError('x')), true);
});
});
group('ErrorReportPolicy.allowSentryEvent', () {
final hint = Hint();
test('allows 5xx Dio so sentry_dio events are not dropped in beforeSend', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
response: Response(statusCode: 503, requestOptions: RequestOptions(path: '/x')),
type: DioExceptionType.badResponse,
);
final event = SentryEvent(throwable: e);
expect(ErrorReportPolicy.allowSentryEvent(event, hint), true);
});
test('drops 4xx Dio from SDK', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
response: Response(statusCode: 422, requestOptions: RequestOptions(path: '/x')),
type: DioExceptionType.badResponse,
);
final event = SentryEvent(throwable: e);
expect(ErrorReportPolicy.allowSentryEvent(event, hint), false);
});
test('drops transient Dio from SDK (connectionError)', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.connectionError,
error: const SocketException('reset'),
);
final event = SentryEvent(throwable: e);
expect(ErrorReportPolicy.allowSentryEvent(event, hint), false);
});
test('drops SocketException from SDK when not wrapped in Dio', () {
final event = SentryEvent(throwable: const SocketException('x'));
expect(ErrorReportPolicy.allowSentryEvent(event, hint), false);
});
});
}

View File

@@ -1,3 +1,4 @@
import 'package:eatvio_app/core/error_reporting/no_op_error_reporter.dart';
import 'package:eatvio_app/core/firebase_api.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -7,7 +8,7 @@ void main() {
// В тестах Firebase не может быть инициализирован
// Проверяем, что попытка создания приводит к ожидаемой ошибке
expect(
() => FirebaseApi(),
() => FirebaseApi(errorReporter: const NoOpErrorReporter()),
throwsA(isA<Exception>()),
);
});
@@ -16,7 +17,7 @@ void main() {
// Метод getToken требует инициализированный Firebase
// В тестах мы проверяем, что он выбрасывает ожидаемую ошибку
try {
final api = FirebaseApi();
final api = FirebaseApi(errorReporter: const NoOpErrorReporter());
expect(() => api.getToken(), throwsA(isA<Exception>()));
} catch (e) {
expect(e.toString(), contains('No Firebase App'));
@@ -26,7 +27,7 @@ void main() {
test('registerAnonymousPushToken возвращает Future', () {
// Метод registerAnonymousPushToken требует инициализированный Firebase
try {
final api = FirebaseApi();
final api = FirebaseApi(errorReporter: const NoOpErrorReporter());
expect(() => api.registerAnonymousPushToken(), throwsA(isA<Exception>()));
} catch (e) {
expect(e.toString(), contains('No Firebase App'));
@@ -36,7 +37,7 @@ void main() {
test('registerPushToken возвращает Future', () {
// Метод registerPushToken требует инициализированный Firebase
try {
final api = FirebaseApi();
final api = FirebaseApi(errorReporter: const NoOpErrorReporter());
expect(() => api.registerPushToken(), throwsA(isA<Exception>()));
} catch (e) {
expect(e.toString(), contains('No Firebase App'));

View File

@@ -1,3 +1,4 @@
import 'package:eatvio_app/core/error_reporting/no_op_error_reporter.dart';
import 'package:eatvio_app/core/app_config.dart';
import 'package:eatvio_app/core/app_initializer.dart';
import 'package:eatvio_app/core/locator_service.dart';
@@ -29,7 +30,7 @@ void main() {
test('initialize returns early when client is not null', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
await manager.initialize();
@@ -38,35 +39,35 @@ void main() {
test('newMessagesStream returns null when channel is null', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
expect(manager.newMessagesStream, isNull);
});
test('newNotificationsStream returns null when channel is null', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
expect(manager.newNotificationsStream, isNull);
});
test('directChatStream returns null when channel is null', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
expect(manager.directChatStream, isNull);
});
test('clientTypingStream returns null when channel is null', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
expect(manager.clientTypingStream, isNull);
});
test('subscribeDirectChatChannel does nothing when channel is null', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
// Не должно быть исключений
manager.subscribeDirectChatChannel();
@@ -74,7 +75,7 @@ void main() {
test('unsubscribeDirectChatChannel does nothing when channel is null', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
// Не должно быть исключений
manager.unsubscribeDirectChatChannel();
@@ -82,7 +83,7 @@ void main() {
test('clear sets client and userId to null', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
manager.userId = 1;
@@ -94,7 +95,7 @@ void main() {
test('initPrivateDirectChatChannel - создает канал для прямого чата', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
const chatId = 'chat-123';
const token = 'test-token';
@@ -109,7 +110,7 @@ void main() {
test('initialize - обрабатывает ошибку при отсутствии токена', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
// Убеждаемся, что токена нет
await TokenStorage.removeTokenInStorage();
@@ -122,7 +123,7 @@ void main() {
test('initialize - обрабатывает ошибку при ошибке getWebsocket', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
const token = 'test-token';
await TokenStorage.saveTokenInStorage(token);
@@ -136,7 +137,7 @@ void main() {
test('initialize - устанавливает userId из WebsocketInfoModel', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
const token = 'test-token';
const userId = 42;
@@ -158,7 +159,7 @@ void main() {
test('clear - отписывается от всех каналов', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
manager.userId = 1;
@@ -171,7 +172,7 @@ void main() {
test('initialize - не инициализирует повторно если client уже существует', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
const token = 'test-token';
await TokenStorage.saveTokenInStorage(token);
@@ -193,7 +194,7 @@ void main() {
test('subscribeDirectChatChannel - подписывается на канал когда он существует', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
// Когда канал null, метод не должен выбрасывать исключение
manager.subscribeDirectChatChannel();
@@ -203,7 +204,7 @@ void main() {
test('unsubscribeDirectChatChannel - отписывается от канала когда он существует', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
// Когда канал null, метод не должен выбрасывать исключение
manager.unsubscribeDirectChatChannel();
@@ -213,35 +214,35 @@ void main() {
test('newMessagesStream - возвращает null когда канал не инициализирован', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
expect(manager.newMessagesStream, isNull);
});
test('newNotificationsStream - возвращает null когда канал не инициализирован', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
expect(manager.newNotificationsStream, isNull);
});
test('directChatStream - возвращает null когда канал не инициализирован', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
expect(manager.directChatStream, isNull);
});
test('clientTypingStream - возвращает null когда канал не инициализирован', () {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
expect(manager.clientTypingStream, isNull);
});
test('initialize - обрабатывает случай когда TokenStorage.haveTokenInStorage возвращает false', () async {
final wsService = MockWsService();
final manager = WsManager(wsService: wsService);
final manager = WsManager(wsService: wsService, errorReporter: const NoOpErrorReporter());
// Убеждаемся, что токена нет
await TokenStorage.removeTokenInStorage();