forked from eatvio/eatvio_app
feat(push_notifications): issue-660, fix: issue-908
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/error_report_policy.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
@@ -72,6 +73,24 @@ void main() {
|
||||
test('returns true for arbitrary exceptions', () {
|
||||
expect(ErrorReportPolicy.shouldReport(StateError('x')), true);
|
||||
});
|
||||
|
||||
test('returns false for HMS client api invalid', () {
|
||||
expect(
|
||||
ErrorReportPolicy.shouldReport(
|
||||
PlatformException(code: 'HMS_TOKEN_ERROR', message: '907135003: client api invalid'),
|
||||
),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('returns true for other HMS token errors', () {
|
||||
expect(
|
||||
ErrorReportPolicy.shouldReport(
|
||||
PlatformException(code: 'HMS_TOKEN_ERROR', message: 'Missing Huawei appId'),
|
||||
),
|
||||
true,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('ErrorReportPolicy.allowSentryEvent', () {
|
||||
@@ -121,6 +140,13 @@ void main() {
|
||||
expect(ErrorReportPolicy.allowSentryEvent(event, hint), true);
|
||||
});
|
||||
|
||||
test('drops HMS client api invalid before send', () {
|
||||
final event = SentryEvent(
|
||||
throwable: PlatformException(code: 'HMS_TOKEN_ERROR', message: '907135003: client api invalid'),
|
||||
);
|
||||
expect(ErrorReportPolicy.allowSentryEvent(event, hint), false);
|
||||
});
|
||||
|
||||
test('drops cancelled Dio from SDK', () {
|
||||
final e = DioException(
|
||||
requestOptions: RequestOptions(path: '/x'),
|
||||
|
||||
112
test/core/push/hms_client_error_test.dart
Normal file
112
test/core/push/hms_client_error_test.dart
Normal file
@@ -0,0 +1,112 @@
|
||||
import 'package:eatvio_app/core/push/hms_client_error.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('isHuaweiFamilyBrand', () {
|
||||
test('matches Huawei and Honor brand or manufacturer', () {
|
||||
expect(
|
||||
isHuaweiFamilyBrand(brand: 'HONOR', manufacturer: 'HONOR'),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
isHuaweiFamilyBrand(brand: 'Huawei', manufacturer: 'HUAWEI'),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
isHuaweiFamilyBrand(brand: 'samsung', manufacturer: 'HONOR'),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('does not match other Android brands', () {
|
||||
expect(
|
||||
isHuaweiFamilyBrand(brand: 'samsung', manufacturer: 'Samsung'),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('isHmsClientUnavailable', () {
|
||||
test('matches 907135003 client api invalid', () {
|
||||
expect(
|
||||
isHmsClientUnavailable(
|
||||
PlatformException(
|
||||
code: 'HMS_TOKEN_ERROR',
|
||||
message: '907135003: client api invalid',
|
||||
),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('does not match a missing app id', () {
|
||||
expect(
|
||||
isHmsClientUnavailable(
|
||||
PlatformException(
|
||||
code: 'HMS_TOKEN_ERROR',
|
||||
message: 'Missing Huawei appId',
|
||||
),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(isHmsClientUnavailable(StateError('907135003')), isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('pushPlatform', () {
|
||||
test('uses huawei only when an HMS token exists', () {
|
||||
expect(
|
||||
pushPlatform(
|
||||
isIos: false,
|
||||
huaweiFamily: true,
|
||||
hmsAvailable: true,
|
||||
hasHmsToken: true,
|
||||
),
|
||||
'huawei',
|
||||
);
|
||||
});
|
||||
|
||||
test('falls back to android on Honor without a valid HMS client', () {
|
||||
expect(
|
||||
pushPlatform(
|
||||
isIos: false,
|
||||
huaweiFamily: true,
|
||||
hmsAvailable: false,
|
||||
hasHmsToken: false,
|
||||
),
|
||||
'android',
|
||||
);
|
||||
expect(
|
||||
pushPlatform(
|
||||
isIos: false,
|
||||
huaweiFamily: true,
|
||||
hmsAvailable: true,
|
||||
hasHmsToken: false,
|
||||
),
|
||||
'android',
|
||||
);
|
||||
});
|
||||
|
||||
test('keeps ios and plain android', () {
|
||||
expect(
|
||||
pushPlatform(
|
||||
isIos: true,
|
||||
huaweiFamily: false,
|
||||
hmsAvailable: false,
|
||||
hasHmsToken: false,
|
||||
),
|
||||
'ios',
|
||||
);
|
||||
expect(
|
||||
pushPlatform(
|
||||
isIos: false,
|
||||
huaweiFamily: false,
|
||||
hmsAvailable: false,
|
||||
hasHmsToken: false,
|
||||
),
|
||||
'android',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
26
test/core/utils/url_utils_test.dart
Normal file
26
test/core/utils/url_utils_test.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:eatvio_app/core/utils/url_utils.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
const baseUrl = 'https://dev2.eatvio.com';
|
||||
|
||||
test('keeps an absolute default avatar url unchanged', () {
|
||||
const avatar =
|
||||
'https://ui-avatars.dev2.eatvio.com/api/?name=%D0%9A+%D0%90&color=7F9CF5&background=EBF4FF';
|
||||
|
||||
expect(joinBaseUrl(baseUrl, avatar), avatar);
|
||||
});
|
||||
|
||||
test('keeps an absolute http url unchanged', () {
|
||||
const photo = 'http://localhost/storage/avatar.jpg';
|
||||
|
||||
expect(joinBaseUrl(baseUrl, photo), photo);
|
||||
});
|
||||
|
||||
test('prefixes a relative storage path with the base url', () {
|
||||
expect(
|
||||
joinBaseUrl(baseUrl, '/storage/profile-photos/photo.jpg'),
|
||||
'https://dev2.eatvio.com/storage/profile-photos/photo.jpg',
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user