47 lines
1.4 KiB
Dart
47 lines
1.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:marianum_mobile/push/direct_push_registration.dart';
|
|
import 'package:marianum_mobile/push/push_secure_storage.dart';
|
|
|
|
class _MemoryStorage implements FlutterSecureStorageLike {
|
|
final Map<String, String> values = {};
|
|
|
|
@override
|
|
Future<String?> read({required String key}) async => values[key];
|
|
|
|
@override
|
|
Future<void> write({required String key, required String? value}) async {
|
|
if (value == null) {
|
|
values.remove(key);
|
|
} else {
|
|
values[key] = value;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> delete({required String key}) async => values.remove(key);
|
|
}
|
|
|
|
void main() {
|
|
test('device identifier is generated once and then reused', () async {
|
|
final storage = _MemoryStorage();
|
|
final registration = DirectPushRegistration(storage: storage);
|
|
final first = await registration.deviceIdentifier();
|
|
expect(first, matches(RegExp(r'^[0-9a-f]{32}$')));
|
|
expect(await registration.deviceIdentifier(), first);
|
|
expect(
|
|
await DirectPushRegistration(storage: storage).deviceIdentifier(),
|
|
first,
|
|
);
|
|
});
|
|
|
|
test('separate installs get different identifiers', () async {
|
|
final a = await DirectPushRegistration(
|
|
storage: _MemoryStorage(),
|
|
).deviceIdentifier();
|
|
final b = await DirectPushRegistration(
|
|
storage: _MemoryStorage(),
|
|
).deviceIdentifier();
|
|
expect(a, isNot(b));
|
|
});
|
|
}
|