97 lines
2.7 KiB
Dart
97 lines
2.7 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:ignis_app/features/homes/services/geofence_automation_service.dart';
|
|
import 'package:ignis_app/models/home_config.dart';
|
|
import 'package:ignis_app/services/settings_service.dart';
|
|
|
|
import 'test_support.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
const channel = MethodChannel('ignis/geofence_automation');
|
|
final calls = <MethodCall>[];
|
|
|
|
setUp(() {
|
|
calls.clear();
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(channel, (call) async {
|
|
calls.add(call);
|
|
return null;
|
|
});
|
|
});
|
|
|
|
tearDown(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(channel, null);
|
|
});
|
|
|
|
test('disarms native geofence when active home is null', () async {
|
|
final service = GeofenceAutomationService(
|
|
settingsService: SettingsService(
|
|
credentialsStorage: InMemoryCredentialsStorage(),
|
|
),
|
|
);
|
|
|
|
await service.syncActiveHome(null);
|
|
|
|
expect(calls, hasLength(1));
|
|
expect(calls.single.method, 'disarmGeofence');
|
|
expect(calls.single.arguments, isNull);
|
|
});
|
|
|
|
test('disarms native geofence when home is not geofence-ready', () async {
|
|
final service = GeofenceAutomationService(
|
|
settingsService: SettingsService(
|
|
credentialsStorage: InMemoryCredentialsStorage(),
|
|
),
|
|
);
|
|
|
|
await service.syncActiveHome(
|
|
HomeConfig(
|
|
id: 'home-1',
|
|
name: 'Home 1',
|
|
url: 'https://one.example',
|
|
latitude: 55.75,
|
|
longitude: 37.61,
|
|
geofenceEnabled: false,
|
|
),
|
|
);
|
|
|
|
expect(calls, hasLength(1));
|
|
expect(calls.single.method, 'disarmGeofence');
|
|
});
|
|
|
|
test('arms native geofence with stored api key and radius', () async {
|
|
final settingsService = SettingsService(
|
|
credentialsStorage: InMemoryCredentialsStorage(),
|
|
);
|
|
await settingsService.setHomeApiKey('home-1', 'secret-key');
|
|
final service = GeofenceAutomationService(settingsService: settingsService);
|
|
|
|
await service.syncActiveHome(
|
|
HomeConfig(
|
|
id: 'home-1',
|
|
name: 'Home 1',
|
|
url: 'https://one.example',
|
|
latitude: 55.75,
|
|
longitude: 37.61,
|
|
geofenceEnabled: true,
|
|
geofenceRadiusMeters: 750,
|
|
),
|
|
);
|
|
|
|
expect(calls, hasLength(1));
|
|
expect(calls.single.method, 'armGeofence');
|
|
expect(calls.single.arguments, <String, Object?>{
|
|
'homeId': 'home-1',
|
|
'homeName': 'Home 1',
|
|
'baseUrl': 'https://one.example',
|
|
'apiKey': 'secret-key',
|
|
'latitude': 55.75,
|
|
'longitude': 37.61,
|
|
'radiusMeters': 750,
|
|
});
|
|
});
|
|
}
|