From 7531df869e009e60f86084e8aab24cd60a3db010 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 3 Jun 2025 11:45:14 +0200 Subject: [PATCH] Fix detecting changes in sync options --- .../powersync_core/lib/src/sync/options.dart | 6 +-- .../test/sync/options_test.dart | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 packages/powersync_core/test/sync/options_test.dart diff --git a/packages/powersync_core/lib/src/sync/options.dart b/packages/powersync_core/lib/src/sync/options.dart index f13f7e38..2b447aa1 100644 --- a/packages/powersync_core/lib/src/sync/options.dart +++ b/packages/powersync_core/lib/src/sync/options.dart @@ -47,9 +47,9 @@ extension type ResolvedSyncOptions(SyncOptions source) { params: other.params ?? params, ); - final didChange = !_mapEquality.equals(other.params, params) || - other.crudThrottleTime != crudThrottleTime || - other.retryDelay != retryDelay; + final didChange = !_mapEquality.equals(newOptions.params, params) || + newOptions.crudThrottleTime != crudThrottleTime || + newOptions.retryDelay != retryDelay; return (ResolvedSyncOptions(newOptions), didChange); } diff --git a/packages/powersync_core/test/sync/options_test.dart b/packages/powersync_core/test/sync/options_test.dart new file mode 100644 index 00000000..d8784c9e --- /dev/null +++ b/packages/powersync_core/test/sync/options_test.dart @@ -0,0 +1,37 @@ +import 'package:powersync_core/src/sync/options.dart'; +import 'package:test/test.dart'; + +void main() { + group('sync options', () { + test('can merge with changes', () { + final a = ResolvedSyncOptions(SyncOptions( + params: {'client': 'a'}, + crudThrottleTime: const Duration(seconds: 1), + )); + + final (b, didChange) = a.applyFrom(SyncOptions( + params: {'client': 'a'}, + retryDelay: const Duration(seconds: 1), + )); + + expect(b.params, {'client': 'a'}); + expect(b.crudThrottleTime, const Duration(seconds: 1)); + expect(b.retryDelay, const Duration(seconds: 1)); + expect(didChange, isTrue); + }); + + test('can merge without changes', () { + final a = ResolvedSyncOptions(SyncOptions( + params: {'client': 'a'}, + crudThrottleTime: const Duration(seconds: 1), + )); + + final (_, didChange) = a.applyFrom(SyncOptions( + // This is the default, so no change from a + retryDelay: const Duration(seconds: 5), + )); + + expect(didChange, isFalse); + }); + }); +}