@@ -0,0 +1,81 @@
|
||||
import 'package:baron_safe_app/src/features/bridge/baron_safe_bridge_command.dart';
|
||||
import 'package:baron_safe_app/src/features/bridge/baron_safe_bridge_models.dart';
|
||||
import 'package:baron_safe_app/src/features/bridge/baron_safe_bridge_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('BaronSafeBridgeCommand', () {
|
||||
test('parses allowed command names', () {
|
||||
expect(
|
||||
BaronSafeBridgeCommand.tryParse('getDeviceInfo'),
|
||||
BaronSafeBridgeCommand.getDeviceInfo,
|
||||
);
|
||||
expect(
|
||||
BaronSafeBridgeCommand.tryParse('openBiometricPrompt'),
|
||||
BaronSafeBridgeCommand.openBiometricPrompt,
|
||||
);
|
||||
});
|
||||
|
||||
test('returns null for unknown command names', () {
|
||||
expect(BaronSafeBridgeCommand.tryParse('unknownCommand'), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('PlaceholderBaronSafeBridgeService', () {
|
||||
test('returns placeholder device info', () async {
|
||||
const service = PlaceholderBaronSafeBridgeService();
|
||||
|
||||
final response = await service.handle(
|
||||
const BaronSafeBridgeRequest(
|
||||
command: BaronSafeBridgeCommand.getDeviceInfo,
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.isSuccess, isTrue);
|
||||
expect(response.data['deviceId'], 'placeholder-device');
|
||||
expect(response.data['platform'], 'flutter');
|
||||
});
|
||||
|
||||
test('returns placeholder biometric result', () async {
|
||||
const service = PlaceholderBaronSafeBridgeService();
|
||||
|
||||
final response = await service.handle(
|
||||
const BaronSafeBridgeRequest(
|
||||
command: BaronSafeBridgeCommand.openBiometricPrompt,
|
||||
payload: {'reason': 'Confirm session block'},
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.isSuccess, isTrue);
|
||||
expect(response.data['verified'], isFalse);
|
||||
expect(response.data['reason'], contains('Confirm session block'));
|
||||
});
|
||||
|
||||
test('registers placeholder push token', () async {
|
||||
const service = PlaceholderBaronSafeBridgeService();
|
||||
|
||||
final response = await service.handle(
|
||||
const BaronSafeBridgeRequest(
|
||||
command: BaronSafeBridgeCommand.registerPushToken,
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.isSuccess, isTrue);
|
||||
expect(response.data['registered'], isTrue);
|
||||
expect(response.data['token'], isA<Map<String, Object?>>());
|
||||
});
|
||||
|
||||
test('marks sensitive backend commands as not implemented', () async {
|
||||
const service = PlaceholderBaronSafeBridgeService();
|
||||
|
||||
final response = await service.handle(
|
||||
const BaronSafeBridgeRequest(
|
||||
command: BaronSafeBridgeCommand.blockSession,
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.isSuccess, isFalse);
|
||||
expect(response.error?.code, 'not_implemented');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:baron_safe_app/src/features/push/baron_safe_push_models.dart';
|
||||
import 'package:baron_safe_app/src/features/push/baron_safe_push_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('PlaceholderBaronSafePushService', () {
|
||||
test('registers the current placeholder token', () async {
|
||||
const service = PlaceholderBaronSafePushService();
|
||||
|
||||
final result = await service.registerCurrentToken();
|
||||
|
||||
expect(result.registered, isTrue);
|
||||
expect(result.token?.token, 'placeholder-push-token');
|
||||
expect(result.token?.platform, BaronSafePushPlatform.unknown);
|
||||
});
|
||||
|
||||
test('reports unavailable token without registration', () async {
|
||||
const service = PlaceholderBaronSafePushService(
|
||||
tokenProvider: _EmptyPushTokenProvider(),
|
||||
);
|
||||
|
||||
final result = await service.registerCurrentToken();
|
||||
|
||||
expect(result.registered, isFalse);
|
||||
expect(result.token, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _EmptyPushTokenProvider implements BaronSafePushTokenProvider {
|
||||
const _EmptyPushTokenProvider();
|
||||
|
||||
@override
|
||||
Future<BaronSafePushToken?> readCurrentToken() async {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:baron_safe_app/src/features/secure_storage/baron_safe_secure_storage.dart';
|
||||
import 'package:baron_safe_app/src/features/secure_storage/baron_safe_secure_storage_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('DefaultBaronSafeSecureStorageService', () {
|
||||
test('stores and clears the device id', () async {
|
||||
final service = DefaultBaronSafeSecureStorageService(
|
||||
MemoryBaronSafeKeyValueStore(),
|
||||
);
|
||||
|
||||
await service.saveDeviceId('device-123');
|
||||
|
||||
expect(await service.readDeviceId(), 'device-123');
|
||||
|
||||
await service.clearDeviceBinding();
|
||||
|
||||
expect(await service.readDeviceId(), isNull);
|
||||
});
|
||||
|
||||
test('stores app lock and biometric settings as booleans', () async {
|
||||
final service = DefaultBaronSafeSecureStorageService(
|
||||
MemoryBaronSafeKeyValueStore(),
|
||||
);
|
||||
|
||||
expect(await service.isAppLockEnabled(), isFalse);
|
||||
expect(await service.isBiometricEnabled(), isFalse);
|
||||
|
||||
await service.setAppLockEnabled(enabled: true);
|
||||
await service.setBiometricEnabled(enabled: true);
|
||||
|
||||
expect(await service.isAppLockEnabled(), isTrue);
|
||||
expect(await service.isBiometricEnabled(), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user