import 'package:flutter_test/flutter_test.dart'; import 'package:miler/controllers/pickups_controller.dart'; /// Whichever way the proximity fence is set, it must be set **once** and on /// purpose. /// /// [kGeofenceEnforced] decides whether "Picked up" means the rider was standing /// at the door or merely pressed a button, and it has already been wrong in /// three directions: it was `kDebugMode` — so every debug build had no fence /// and the fence was therefore never tested — then a hard `false`, so the flow /// could not be walked at a desk at all, then a define defaulting to off. /// /// **It is OFF, decided 2026-08-25.** It was turned on that morning with a /// radius of [kGeofenceRadiusMeters] and turned off again the same day, at the /// founder's call. Nothing was found wrong with it — this is a decision about /// *when* to switch it on. /// /// So the direction this file guards has flipped twice in a day, which is /// exactly the pattern that made the old defaults dangerous, and it is why the /// three tests below are not all about the direction. The measurement work is /// unchanged and still asserted: a `best` fix with a shelf life, the phone's /// error credited to the rider, and one radius rather than three. All of it is /// dormant while [kGeofenceEnforced] is false and none of it needs revisiting /// on the day it goes back on. void main() { test('there is one switch, and the legacy name derives from it', () { // Two constants that could disagree is exactly how a build ends up with // the fence on in one gate and off in the other — the bulk check on Home // and the per-stop check in the controller are separate code paths that // must never answer differently. expect(kBypassGeofenceForTesting, !kGeofenceEnforced); }); test('enforcement is off, and that is the recorded decision', () { // If this fails, one of two things happened, and both should be read rather // than silenced: // // • the default was turned back on — record the date and the reason here, // as the previous flips did; or // • this run passed `--dart-define=ENFORCE_GEOFENCE=true`, in which case // the failure is correct and is telling you this build has the fence on. expect( kGeofenceEnforced, isFalse, reason: 'Proximity enforcement is expected to be OFF (see kGeofenceEnforced). ' 'Either the default was restored, or this run passed ' '--dart-define=ENFORCE_GEOFENCE=true.', ); }); test('the radius is one number, and it is the tight one', () { // Asserted while the fence is off, deliberately. The app used to hold // three — a configured `pickupradius` defaulting to 100 in the controller, // a hardcoded 500 in Home's bulk gate, and no agreement between them — so // which fence a rider met depended on whether he ticked boxes or slid a // sheet. Whichever way the switch above is set, that must not come back. expect(kGeofenceRadiusMeters, 10); }); test('a cached fix has a shelf life', () { // On a round, a stale position is reliably the *previous* stop. Anything // much longer than this and the fence starts measuring from the last door. expect(kGeofenceFixMaxAge, const Duration(seconds: 30)); }); }