Catch nullable date-only columns and unsynced Drift tables

This commit is contained in:
Roland Geider
2026-12-03 15:44:40 +01:00
parent 9016054794
commit f3abdae272
2 changed files with 31 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:drift/drift.dart' show GeneratedColumnWithTypeConverter;
import 'package:drift/drift.dart' show GeneratedColumnWithTypeConverter, TypeConverter;
import 'package:fake_async/fake_async.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
@@ -29,7 +29,6 @@ import 'package:logging/logging.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:powersync/powersync.dart';
import 'package:wger/database/converters/date_only_text_converter.dart';
import 'package:wger/powersync/api_client.dart';
import 'package:wger/powersync/connector.dart';
@@ -179,16 +178,30 @@ void main() {
final db = await openTestDatabase();
addTearDown(db.close);
// Recognized by what the converter writes, not by its class: Drift
// wraps the converter of a nullable column, so an `is` check misses
// every open-ended date such as `nutrition_nutritionplan.end`.
final probe = DateTime.utc(2024, 11, 1, 13, 45);
final dateOnlyColumns = <(String, String)>[];
for (final table in db.allTables) {
for (final column in table.$columns) {
if (column is GeneratedColumnWithTypeConverter &&
column.converter is DateOnlyTextConverter) {
dateOnlyColumns.add((table.actualTableName, column.name));
if (column is GeneratedColumnWithTypeConverter) {
final converter = column.converter;
if (converter is TypeConverter<DateTime?, String?> &&
converter.toSql(probe) == '2024-11-01') {
dateOnlyColumns.add((table.actualTableName, column.name));
}
}
}
}
expect(dateOnlyColumns, isNotEmpty);
expect(
dateOnlyColumns,
containsAll([
('manager_routine', 'start'),
('nutrition_nutritionplan', 'end'),
('gallery_image', 'date'),
]),
);
for (final (table, column) in dateOnlyColumns) {
final out = connector.genericTransform(table, {column: '2024-11-01T00:00:00.000Z'}, '1');

View File

@@ -65,6 +65,18 @@ void main() {
}
});
test('every Drift table is synced', () {
// The in-memory test database creates every Drift table itself, so a
// table missing from the PowerSync schema only shows on a device: there
// the view does not exist and every query against it fails.
final synced = {
...schema.tables.map((table) => table.name),
...schema.rawTables.map((table) => table.name),
};
expect(driftTables.keys.toSet().difference(synced), isEmpty);
});
test('every column is declared with the type of its Drift column', () {
for (final table in schema.tables) {
final driftColumns = {