feat(push_notifications): issue-660, fix: issue-908

This commit is contained in:
misha
2026-10-14 08:16:20 +03:00
parent 98c175df44
commit dcd343e765
29 changed files with 2281 additions and 608 deletions

View 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',
);
});
});
}