Test persisted stable cloud ride identity lifecycle
This commit is contained in:
parent
d6a0d52f8c
commit
7d187286e0
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue