From 7d187286e032ac1cc53566e13737ee9c31172aff Mon Sep 17 00:00:00 2001 From: bponders12-cell Date: Tue, 1 Sep 2026 21:00:39 -0400 Subject: [PATCH] Test persisted stable cloud ride identity lifecycle --- test/cloud_ride_identity_migration_test.dart | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/cloud_ride_identity_migration_test.dart diff --git a/test/cloud_ride_identity_migration_test.dart b/test/cloud_ride_identity_migration_test.dart new file mode 100644 index 0000000..269ad22 --- /dev/null +++ b/test/cloud_ride_identity_migration_test.dart @@ -0,0 +1,37 @@ +import 'package:drift/native.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:motorcycle_dash/database/database.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + test('new rides receive a persisted cloudRideId independent of local id', () async { + final db = AppDatabase.forTesting(NativeDatabase.memory()); + addTearDown(db.close); + + final localId = await db.startRide(); + final cloudId = await db.getCloudRideId(localId); + + expect(cloudId, isNotNull); + expect(cloudId, startsWith('ride_')); + expect(cloudId, isNot(localId.toString())); + + final secondLocalId = await db.startRide(); + final secondCloudId = await db.getCloudRideId(secondLocalId); + expect(secondCloudId, isNot(cloudId)); + + // Re-reading the same local row returns the exact persisted identity. + expect(await db.getCloudRideId(localId), cloudId); + }); + + test('ensureCloudRideId is idempotent', () async { + final db = AppDatabase.forTesting(NativeDatabase.memory()); + addTearDown(db.close); + + final localId = await db.startRide(); + final first = await db.ensureCloudRideId(localId); + final second = await db.ensureCloudRideId(localId); + + expect(second, first); + }); +}