Ad and purchases enabled (still need actual testing)

This commit is contained in:
Courtney Arnold 2026-08-16 18:27:56 -05:00
parent 2fcc6dcab7
commit faf319322a
35 changed files with 1676 additions and 34 deletions

View file

@ -36,6 +36,7 @@ void main() {
try {
await local.execute(mergeVehiclesSql);
await local.execute(mergeFuelEntriesSql);
await local.execute(mergeAdFreeEntitlementSql);
} finally {
await local.execute('DETACH DATABASE remote_db');
}
@ -153,6 +154,59 @@ void main() {
expect(rows.first['receipt_image_path'], isNull);
});
});
group('ad_free_entitlement merge', () {
test('pulls in the entitlement when only remote has one', () async {
await remote.insert('ad_free_entitlement', _entitlementRow(adFreeUntil: 5000, updatedAt: 1000));
await merge();
final rows = await local.query('ad_free_entitlement');
expect(rows, hasLength(1));
expect(rows.first['id'], 1);
expect(rows.first['ad_free_until'], 5000);
});
test('remote wins when strictly newer than local', () async {
await local.insert('ad_free_entitlement', _entitlementRow(adFreeUntil: 1000, updatedAt: 1000));
await remote.insert('ad_free_entitlement', _entitlementRow(adFreeUntil: 9000, updatedAt: 2000));
await merge();
final rows = await local.query('ad_free_entitlement');
expect(rows, hasLength(1));
expect(rows.first['ad_free_until'], 9000);
});
test('local wins on a tie or when strictly newer', () async {
await local.insert('ad_free_entitlement', _entitlementRow(adFreeUntil: 9000, updatedAt: 2000));
await remote.insert('ad_free_entitlement', _entitlementRow(adFreeUntil: 1000, updatedAt: 1000));
await merge();
final rows = await local.query('ad_free_entitlement');
expect(rows, hasLength(1));
expect(rows.first['ad_free_until'], 9000);
});
test('a null ad_free_until merges in fine (e.g. purchase consumed/lapsed remotely)', () async {
await remote.insert(
'ad_free_entitlement', _entitlementRow(adFreeUntil: null, updatedAt: 1000));
await merge();
final rows = await local.query('ad_free_entitlement');
expect(rows, hasLength(1));
expect(rows.first['ad_free_until'], isNull);
});
test('no-op when neither side has a row yet', () async {
await merge();
final rows = await local.query('ad_free_entitlement');
expect(rows, isEmpty);
});
});
}
Future<Database> _openFreshDb(String path) async {
@ -160,6 +214,7 @@ Future<Database> _openFreshDb(String path) async {
await db.execute(createVehiclesTableSql);
await db.execute(createFuelEntriesTableSql);
await db.execute(createFuelEntriesIndexSql);
await db.execute(createAdFreeEntitlementTableSql);
return db;
}
@ -180,6 +235,12 @@ Map<String, Object?> _vehicleRow({
'dirty': dirty,
};
Map<String, Object?> _entitlementRow({int? adFreeUntil, int updatedAt = 0}) => {
'id': 1,
'ad_free_until': adFreeUntil,
'updated_at': updatedAt,
};
Map<String, Object?> _fuelEntryRow({
required String id,
required String vehicleId,