MotorSignal-App/test/cloud_ride_identity_migrati...

38 lines
1.2 KiB
Dart

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);
});
}