mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-05 23:44:02 +01:00
Catch nullable date-only columns and unsynced Drift tables
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user