diff --git a/test/app_test.dart b/test/app_test.dart index 5b0d9f74f..660163ac1 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -260,7 +260,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final user = await app.logIn(Credentials.anonymous()); - final configuration = Configuration.flexibleSync(user, [Task.schema]); + final configuration = Configuration.flexibleSync(user, syncSchema); final realm = getRealm(configuration); final session = realm.syncSession; diff --git a/test/client_reset_test.dart b/test/client_reset_test.dart index 1ad1eaaeb..61138cfc5 100644 --- a/test/client_reset_test.dart +++ b/test/client_reset_test.dart @@ -35,21 +35,21 @@ Future main([List? args]) async { expect( Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: ManualRecoveryHandler((syncError) {}), ).clientResetHandler.clientResyncMode, ClientResyncModeInternal.manual); expect( Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: const DiscardUnsyncedChangesHandler(), ).clientResetHandler.clientResyncMode, ClientResyncModeInternal.discardLocal); expect( Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: const RecoverUnsyncedChangesHandler(), ).clientResetHandler.clientResyncMode, ClientResyncModeInternal.recover); @@ -57,12 +57,12 @@ Future main([List? args]) async { expect( Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: const RecoverOrDiscardUnsyncedChangesHandler(), ).clientResetHandler.clientResyncMode, ClientResyncModeInternal.recoverOrDiscard); - expect(Configuration.flexibleSync(user, [Task.schema, Schedule.schema]).clientResetHandler.clientResyncMode, ClientResyncModeInternal.recoverOrDiscard); + expect(Configuration.flexibleSync(user, syncSchema).clientResetHandler.clientResyncMode, ClientResyncModeInternal.recoverOrDiscard); }); baasTest('ManualRecoveryHandler error is reported in callback', (appConfig) async { @@ -72,7 +72,7 @@ Future main([List? args]) async { final resetCompleter = Completer(); final config = Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: ManualRecoveryHandler((syncError) { resetCompleter.completeError(syncError); }), @@ -93,7 +93,7 @@ Future main([List? args]) async { final resetCompleter = Completer(); final config = Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: ManualRecoveryHandler((clientResetError) { resetCompleter.completeError(clientResetError); }), @@ -122,7 +122,7 @@ Future main([List? args]) async { final resetCompleter = Completer(); final config = Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: ManualRecoveryHandler((clientResetError) { resetCompleter.completeError(clientResetError); }), @@ -152,7 +152,7 @@ Future main([List? args]) async { final user = await getIntegrationUser(app); final onManualResetFallback = Completer(); - final config = Configuration.flexibleSync(user, [Task.schema, Schedule.schema], + final config = Configuration.flexibleSync(user, syncSchema, clientResetHandler: Creator.create( clientResetHandlerType, onBeforeReset: (beforeResetRealm) => throw Exception("This fails!"), @@ -177,7 +177,7 @@ Future main([List? args]) async { throw Exception("This fails!"); } - final config = Configuration.flexibleSync(user, [Task.schema, Schedule.schema], + final config = Configuration.flexibleSync(user, syncSchema, clientResetHandler: Creator.create( clientResetHandlerType, onAfterRecovery: clientResetHandlerType != DiscardUnsyncedChangesHandler ? onAfterReset : null, @@ -204,7 +204,7 @@ Future main([List? args]) async { onAfterCompleter.complete(); } - final config = Configuration.flexibleSync(user, [Task.schema, Schedule.schema], + final config = Configuration.flexibleSync(user, syncSchema, clientResetHandler: Creator.create( clientResetHandlerType, onBeforeReset: (beforeResetRealm) => onBeforeCompleter.complete(), @@ -233,7 +233,7 @@ Future main([List? args]) async { int onAfterRecoveryOccurred = 0; final onAfterCompleter = Completer(); - final config = Configuration.flexibleSync(user, [Task.schema, Schedule.schema], + final config = Configuration.flexibleSync(user, syncSchema, clientResetHandler: Creator.create( clientResetHandlerType, onBeforeReset: (beforeResetRealm) => onBeforeResetOccurred++, @@ -300,7 +300,7 @@ Future main([List? args]) async { final maybeProduct = Product(ObjectId(), "maybe synced"); comparer(Product p1, Product p2) => p1.id == p2.id; - final config = Configuration.flexibleSync(user, [Product.schema], + final config = Configuration.flexibleSync(user, syncSchema, clientResetHandler: Creator.create( clientResetHandlerType, onBeforeReset: (beforeResetRealm) { @@ -349,7 +349,7 @@ Future main([List? args]) async { bool recovery = false; bool discard = false; - final config = Configuration.flexibleSync(user, [Task.schema, Schedule.schema], + final config = Configuration.flexibleSync(user, syncSchema, clientResetHandler: RecoverOrDiscardUnsyncedChangesHandler( onBeforeReset: (beforeResetRealm) => onBeforeCompleter.complete(), onAfterRecovery: (Realm beforeResetRealm, Realm afterResetRealm) { @@ -389,7 +389,7 @@ Future main([List? args]) async { final config = Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: DiscardUnsyncedChangesHandler( onBeforeReset: (beforeResetRealm) async { await Future.delayed(Duration(seconds: 1)); @@ -426,7 +426,7 @@ Future main([List? args]) async { late ClientResetError clientResetErrorOnManualFallback; final config = Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: DiscardUnsyncedChangesHandler( onBeforeReset: (beforeResetRealm) { onBeforeResetOccurred++; @@ -481,7 +481,7 @@ Future main([List? args]) async { comparer(Task t1, ObjectId id) => t1.id == id; - final configA = Configuration.flexibleSync(userA, [Task.schema], clientResetHandler: RecoverUnsyncedChangesHandler( + final configA = Configuration.flexibleSync(userA, syncSchema, clientResetHandler: RecoverUnsyncedChangesHandler( onAfterReset: (beforeResetRealm, afterResetRealm) { try { _checkProducts(beforeResetRealm, comparer, expectedList: [task0Id, task1Id], notExpectedList: [task2Id, task3Id]); @@ -493,7 +493,7 @@ Future main([List? args]) async { }, )); - final configB = Configuration.flexibleSync(userB, [Schedule.schema, Task.schema], clientResetHandler: RecoverUnsyncedChangesHandler( + final configB = Configuration.flexibleSync(userB, syncSchema, clientResetHandler: RecoverUnsyncedChangesHandler( onAfterReset: (beforeResetRealm, afterResetRealm) { try { _checkProducts(beforeResetRealm, comparer, expectedList: [task0Id, task1Id, task2Id, task3Id]); @@ -540,7 +540,7 @@ Future main([List? args]) async { late ClientResetError clientResetError; final config = Configuration.flexibleSync( user, - [Task.schema, Schedule.schema], + syncSchema, clientResetHandler: ManualRecoveryHandler((syncError) { clientResetError = syncError; resetCompleter.complete(); diff --git a/test/configuration_test.dart b/test/configuration_test.dart index 93b80494f..831c181e3 100644 --- a/test/configuration_test.dart +++ b/test/configuration_test.dart @@ -82,7 +82,7 @@ Future main([List? args]) async { var customDefaultRealmName = "myRealmName.realm"; Configuration.defaultRealmName = customDefaultRealmName; - var config = Configuration.flexibleSync(user, [Task.schema]); + var config = Configuration.flexibleSync(user, syncSchema); expect(path.basename(config.path), path.basename(customDefaultRealmName)); var realm = getRealm(config); @@ -91,7 +91,7 @@ Future main([List? args]) async { //set a new defaultRealmName customDefaultRealmName = "anotherRealmName.realm"; Configuration.defaultRealmName = customDefaultRealmName; - config = Configuration.flexibleSync(user, [Task.schema]); + config = Configuration.flexibleSync(user, syncSchema); realm = getRealm(config); expect(path.basename(realm.config.path), customDefaultRealmName); }); @@ -108,7 +108,7 @@ Future main([List? args]) async { var app = App(appConfig); var user = await app.logIn(Credentials.anonymous()); - var config = Configuration.flexibleSync(user, [Task.schema]); + var config = Configuration.flexibleSync(user, syncSchema); expect(path.dirname(config.path), startsWith(path.dirname(customDefaultRealmPath))); var realm = getRealm(config); @@ -125,7 +125,7 @@ Future main([List? args]) async { app = App(appConfig); user = await app.logIn(Credentials.anonymous()); - config = Configuration.flexibleSync(user, [Task.schema]); + config = Configuration.flexibleSync(user, syncSchema); realm = getRealm(config); expect(path.dirname(realm.config.path), startsWith(path.dirname(customDefaultRealmPath))); }); @@ -497,7 +497,7 @@ Future main([List? args]) async { final user = await app.logIn(Credentials.emailPassword(testUsername, testPassword)); var invoked = false; - var config = Configuration.flexibleSync(user, [Event.schema], shouldCompactCallback: (totalSize, usedSize) { + var config = Configuration.flexibleSync(user, syncSchema, shouldCompactCallback: (totalSize, usedSize) { invoked = true; return false; }); @@ -510,7 +510,7 @@ Future main([List? args]) async { final app = App(appConfig); final user = await app.logIn(Credentials.emailPassword(testUsername, testPassword)); - final config = Configuration.flexibleSync(user, [Car.schema]); + final config = Configuration.flexibleSync(user, syncSchema); expect(config.path, contains(user.id)); expect(config.path, contains(appConfig.appId)); @@ -520,7 +520,7 @@ Future main([List? args]) async { final app = App(appConfig); final user = await app.logIn(Credentials.emailPassword(testUsername, testPassword)); - final config = Configuration.flexibleSync(user, [Car.schema], path: 'my-custom-path.realm'); + final config = Configuration.flexibleSync(user, syncSchema, path: 'my-custom-path.realm'); expect(config.path, 'my-custom-path.realm'); }); @@ -532,7 +532,7 @@ Future main([List? args]) async { path.dirname(Configuration.defaultStoragePath), path.basename('my-custom-realm-name.realm'), ); - final config = Configuration.flexibleSync(user, [Event.schema], path: customPath); + final config = Configuration.flexibleSync(user, syncSchema, path: customPath); var realm = getRealm(config); }); @@ -543,8 +543,7 @@ Future main([List? args]) async { final dir = await Directory.systemTemp.createTemp(); final realmPath = path.join(dir.path, 'test.realm'); - final schema = [Task.schema]; - final flexibleSyncConfig = Configuration.flexibleSync(user, schema, path: realmPath); + final flexibleSyncConfig = Configuration.flexibleSync(user, syncSchema, path: realmPath); final realm = getRealm(flexibleSyncConfig); final oid = ObjectId(); realm.subscriptions.update((mutableSubscriptions) { @@ -553,7 +552,7 @@ Future main([List? args]) async { realm.write(() => realm.add(Task(oid))); realm.close(); - final disconnectedSyncConfig = Configuration.disconnectedSync(schema, path: realmPath); + final disconnectedSyncConfig = Configuration.disconnectedSync(syncSchema, path: realmPath); final disconnectedRealm = getRealm(disconnectedSyncConfig); expect(disconnectedRealm.find(oid), isNotNull); }); @@ -587,7 +586,7 @@ Future main([List? args]) async { List key = List.generate(encryptionKeySize + 10, (i) => random.nextInt(256)); expect( - () => Configuration.flexibleSync(user, [Task.schema], encryptionKey: key), + () => Configuration.flexibleSync(user, syncSchema, encryptionKey: key), throws("Wrong encryption key size"), ); }); @@ -611,7 +610,7 @@ Future main([List? args]) async { final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final config = Configuration.flexibleSync(user, [Task.schema], maxNumberOfActiveVersions: 1); + final config = Configuration.flexibleSync(user, syncSchema, maxNumberOfActiveVersions: 1); final realm = await getRealmAsync(config); // First writing to the Realm when opening realm.subscriptions.update((mutableSubscriptions) => mutableSubscriptions.add(realm.all())); expect(() => realm.write(() {}), throws("in the Realm exceeded the limit of 1")); @@ -621,9 +620,9 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final config = Configuration.flexibleSync(user, [Task.schema]); + final config = Configuration.flexibleSync(user, syncSchema); - final disconnectedConfig = Configuration.disconnectedSync([Task.schema], path: config.path, maxNumberOfActiveVersions: 1); + final disconnectedConfig = Configuration.disconnectedSync(syncSchema, path: config.path, maxNumberOfActiveVersions: 1); final realm = getRealm(disconnectedConfig); // First writing to the Realm when opening expect(() => realm.write(() {}), throws("in the Realm exceeded the limit of 1")); }); diff --git a/test/embedded_test.dart b/test/embedded_test.dart index 656c52180..e0c811a62 100644 --- a/test/embedded_test.dart +++ b/test/embedded_test.dart @@ -40,7 +40,7 @@ Future main([List? args]) async { final app = App(config); final user = await getAnonymousUser(app); final realmConfig = Configuration.flexibleSync( - user, [AllTypesEmbedded.schema, ObjectWithEmbedded.schema, RecursiveEmbedded1.schema, RecursiveEmbedded2.schema, RecursiveEmbedded3.schema]); + user, syncSchema); return getRealm(realmConfig); } @@ -58,10 +58,10 @@ Future main([List? args]) async { baasTest('Synchronized Realm with orphan embedded schemas throws', (configuration) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [AllTypesEmbedded.schema]); + final config = Configuration.flexibleSync(user, syncSchema); expect(() => getRealm(config), throws("Embedded object 'AllTypesEmbedded' is unreachable by any link path from top level objects")); - }); + }, skip: "This test requires a new app service with missing embedded parent schema."); test('Embedded object roundtrip', () { final realm = getLocalRealm(); diff --git a/test/realm_test.dart b/test/realm_test.dart index 09c17a3cc..72c22d58c 100644 --- a/test/realm_test.dart +++ b/test/realm_test.dart @@ -995,12 +995,12 @@ Future main([List? args]) async { final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); List key = List.generate(encryptionKeySize, (i) => random.nextInt(256)); - final configuration = Configuration.flexibleSync(user, [Task.schema], encryptionKey: key); + final configuration = Configuration.flexibleSync(user, syncSchema, encryptionKey: key); final realm = getRealm(configuration); expect(realm.isClosed, false); expect( - () => getRealm(Configuration.flexibleSync(user, [Task.schema])), + () => getRealm(Configuration.flexibleSync(user, syncSchema)), throws("already opened with a different encryption key"), ); }); @@ -1231,7 +1231,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = Configuration.flexibleSync(user, [Task.schema]); + final configuration = Configuration.flexibleSync(user, syncSchema); final realm = await getRealmAsync(configuration); expect(realm.isClosed, false); @@ -1254,7 +1254,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = Configuration.flexibleSync(user, [Task.schema]); + final configuration = Configuration.flexibleSync(user, syncSchema); final cancellationToken = CancellationToken(); cancellationToken.cancel(); @@ -1265,7 +1265,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = Configuration.flexibleSync(user, [Task.schema]); + final configuration = Configuration.flexibleSync(user, syncSchema); final cancellationToken = CancellationToken(); final isRealmCancelled = getRealmAsync(configuration, cancellationToken: cancellationToken).isCancelled(); @@ -1277,7 +1277,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = Configuration.flexibleSync(user, [Task.schema]); + final configuration = Configuration.flexibleSync(user, syncSchema); final cancellationToken = CancellationToken(); @@ -1292,7 +1292,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = Configuration.flexibleSync(user, [Task.schema]); + final configuration = Configuration.flexibleSync(user, syncSchema); final cancellationToken1 = CancellationToken(); final isRealm1Cancelled = getRealmAsync(configuration, cancellationToken: cancellationToken1).isCancelled(); @@ -1308,12 +1308,12 @@ Future main([List? args]) async { final app = App(appConfiguration); final user1 = await app.logIn(Credentials.anonymous()); - final configuration1 = Configuration.flexibleSync(user1, [Task.schema]); + final configuration1 = Configuration.flexibleSync(user1, syncSchema); final cancellationToken1 = CancellationToken(); final isRealm1Cancelled = getRealmAsync(configuration1, cancellationToken: cancellationToken1).isCancelled(); final user2 = await app.logIn(Credentials.anonymous(reuseCredentials: false)); - final configuration2 = Configuration.flexibleSync(user2, [Task.schema]); + final configuration2 = Configuration.flexibleSync(user2, syncSchema); final cancellationToken2 = CancellationToken(); final isRealm2Cancelled = getRealmAsync(configuration2, cancellationToken: cancellationToken2).isCancelled(); @@ -1326,7 +1326,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = Configuration.flexibleSync(user, [Task.schema]); + final configuration = Configuration.flexibleSync(user, syncSchema); final cancellationToken = CancellationToken(); final realm = await getRealmAsync(configuration, cancellationToken: cancellationToken); @@ -1342,7 +1342,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = Configuration.flexibleSync(user, [Task.schema]); + final configuration = Configuration.flexibleSync(user, syncSchema); int transferredBytes = -1; final completer = Completer(); @@ -1519,7 +1519,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - var config = Configuration.disconnectedSync([Product.schema], path: p.join(Configuration.defaultStoragePath, "${generateRandomString(8)}.realm")); + var config = Configuration.disconnectedSync(syncSchema, path: p.join(Configuration.defaultStoragePath, "${generateRandomString(8)}.realm")); final beforeCompactSize = await createRealmForCompact(config); @@ -1536,7 +1536,7 @@ Future main([List? args]) async { final credentials = Credentials.anonymous(); var user = await app.logIn(credentials); final path = p.join(Configuration.defaultStoragePath, "${generateRandomString(8)}.realm"); - final config = Configuration.flexibleSync(user, [Product.schema], path: path); + final config = Configuration.flexibleSync(user, syncSchema, path: path); final beforeCompactSize = await createRealmForCompact(config); user.logOut(); Future.delayed(Duration(seconds: 5)); @@ -1546,7 +1546,7 @@ Future main([List? args]) async { validateCompact(compacted, config.path, beforeCompactSize); //test the realm can be opened. - final realm = getRealm(Configuration.disconnectedSync([Product.schema], path: path)); + final realm = getRealm(Configuration.disconnectedSync(syncSchema, path: path)); }); baasTest('Realm - synced encrypted realm can be compacted', (appConfiguration) async { @@ -1555,7 +1555,7 @@ Future main([List? args]) async { final path = p.join(Configuration.defaultStoragePath, "${generateRandomString(8)}.realm"); var user = await app.logIn(credentials); List key = List.generate(encryptionKeySize, (i) => random.nextInt(256)); - final config = Configuration.flexibleSync(user, [Product.schema], encryptionKey: key, path: path); + final config = Configuration.flexibleSync(user, syncSchema, encryptionKey: key, path: path); final beforeCompactSize = await createRealmForCompact(config); user.logOut(); Future.delayed(Duration(seconds: 5)); @@ -1566,7 +1566,7 @@ Future main([List? args]) async { user = await app.logIn(credentials); //test the realm can be opened. - final realm = getRealm(Configuration.disconnectedSync([Product.schema], path: path, encryptionKey: key)); + final realm = getRealm(Configuration.disconnectedSync(syncSchema, path: path, encryptionKey: key)); }); test('Realm writeCopy local to existing file', () { @@ -1593,7 +1593,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final credentials = Credentials.anonymous(reuseCredentials: false); var user = await app.logIn(credentials); - final configCopy = Configuration.flexibleSync(user, [Product.schema]); + final configCopy = Configuration.flexibleSync(user, syncSchema); expect(() => originalRealm.writeCopy(configCopy), throws("Realm cannot be converted to a flexible sync realm unless flexible sync is already enabled")); }); @@ -1709,20 +1709,20 @@ Future main([List? args]) async { baasTest('Realm writeCopy Sync->Sync - $testDescription can be opened and synced', (appConfiguration) async { final app = App(appConfiguration); var user1 = await app.logIn(Credentials.anonymous(reuseCredentials: false)); - final originalConfig = Configuration.flexibleSync(user1, [Product.schema], encryptionKey: sourceEncryptedKey); + final originalConfig = Configuration.flexibleSync(user1, syncSchema, encryptionKey: sourceEncryptedKey); final originalRealm = getRealm(originalConfig); var itemsCount = 2; final productNamePrefix = generateRandomString(10); await _addDataToAtlas(originalRealm, productNamePrefix, itemsCount: itemsCount); var user2 = await app.logIn(Credentials.anonymous(reuseCredentials: false)); - final configCopy = Configuration.flexibleSync(user2, [Product.schema], encryptionKey: destinationEncryptedKey); + final configCopy = Configuration.flexibleSync(user2, syncSchema, encryptionKey: destinationEncryptedKey); originalRealm.writeCopy(configCopy); originalRealm.close(); expect(File(configCopy.path).existsSync(), isTrue); // Check data in copied realm before synchronization - final disconnectedConfig = Configuration.disconnectedSync([Product.schema], path: configCopy.path, encryptionKey: destinationEncryptedKey); + final disconnectedConfig = Configuration.disconnectedSync(syncSchema, path: configCopy.path, encryptionKey: destinationEncryptedKey); final disconnectedCopiedRealm = getRealm(disconnectedConfig); expect(disconnectedCopiedRealm.all().length, itemsCount); disconnectedCopiedRealm.close(); @@ -1737,7 +1737,7 @@ Future main([List? args]) async { // Create another user's realm and download the data var anotherUser = await app.logIn(Credentials.anonymous(reuseCredentials: false)); - final anotherUserRealm = getRealm(Configuration.flexibleSync(anotherUser, [Product.schema])); + final anotherUserRealm = getRealm(Configuration.flexibleSync(anotherUser, syncSchema)); await _addSubscriptions(anotherUserRealm, productNamePrefix); await anotherUserRealm.syncSession.waitForUpload(); await anotherUserRealm.syncSession.waitForDownload(); @@ -1757,7 +1757,7 @@ Future main([List? args]) async { baasTest('Realm writeCopy Sync->Local - $testDescription can be opened and synced', (appConfiguration) async { final app = App(appConfiguration); var user = await app.logIn(Credentials.anonymous(reuseCredentials: false)); - final originalConfig = Configuration.flexibleSync(user, [Product.schema], encryptionKey: sourceEncryptedKey); + final originalConfig = Configuration.flexibleSync(user, syncSchema, encryptionKey: sourceEncryptedKey); final originalRealm = getRealm(originalConfig); var itemsCount = 2; final productNamePrefix = generateRandomString(10); @@ -1896,7 +1896,7 @@ Future main([List? args]) async { final app = App(appConfiguration); final productName = generateRandomUnicodeString(); final user = await app.logIn(Credentials.anonymous(reuseCredentials: false)); - final config = Configuration.flexibleSync(user, [Product.schema]); + final config = Configuration.flexibleSync(user, syncSchema); final realm = getRealm(config); await _addSubscriptions(realm, productName); realm.write(() => realm.add(Product(ObjectId(), productName))); @@ -1954,13 +1954,13 @@ extension on Future { Future _subscribeForAtlasAddedData(App app, {String? queryDifferentiator, int itemsCount = 100}) async { final productNamePrefix = queryDifferentiator ?? generateRandomString(10); final user1 = await app.logIn(Credentials.anonymous(reuseCredentials: false)); - final config1 = Configuration.flexibleSync(user1, [Product.schema]); + final config1 = Configuration.flexibleSync(user1, syncSchema); final realm1 = getRealm(config1); await _addSubscriptions(realm1, productNamePrefix); realm1.close(); final user2 = await app.logIn(Credentials.anonymous(reuseCredentials: false)); - final config2 = Configuration.flexibleSync(user2, [Product.schema]); + final config2 = Configuration.flexibleSync(user2, syncSchema); final realm2 = getRealm(config2); await _addDataToAtlas(realm2, productNamePrefix, itemsCount: itemsCount); realm2.close(); diff --git a/test/session_test.dart b/test/session_test.dart index 6313778df..567e12e8b 100644 --- a/test/session_test.dart +++ b/test/session_test.dart @@ -43,7 +43,7 @@ Future main([List? args]) async { baasTest('SyncSession.user returns a valid user', (configuration) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Task.schema]); + final config = Configuration.flexibleSync(user, syncSchema); final realm = getRealm(config); expect(realm.syncSession.user, user); @@ -55,7 +55,7 @@ Future main([List? args]) async { baasTest('SyncSession when isolate is torn down does not crash', (configuration) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Task.schema]); + final config = Configuration.flexibleSync(user, syncSchema); // Don't use getRealm because we want the Realm to survive final realm = Realm(config); @@ -282,7 +282,7 @@ Future main([List? args]) async { baasTest('BadFlexibleSyncQueryError test error handler', (configuration) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Task.schema], syncErrorHandler: (syncError) { + final config = Configuration.flexibleSync(user, syncSchema, syncErrorHandler: (syncError) { expect(syncError, isA()); expect(syncError.message, isNotEmpty); }); @@ -295,7 +295,7 @@ Future main([List? args]) async { baasTest('UnrecoverableSyncError test error handler', (configuration) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Task.schema], syncErrorHandler: (syncError) { + final config = Configuration.flexibleSync(user, syncSchema, syncErrorHandler: (syncError) { expect(syncError, isA()); expect(syncError.message, isNotEmpty); }); @@ -307,7 +307,7 @@ Future main([List? args]) async { baasTest('WrongSyncTypeError test error handler', (configuration) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Task.schema], syncErrorHandler: (syncError) { + final config = Configuration.flexibleSync(user, syncSchema, syncErrorHandler: (syncError) { expect(syncError, isA()); expect(syncError.message, isNotEmpty); }); @@ -357,7 +357,7 @@ Future main([List? args]) async { baasTest('SyncSession when Realm is closed gets closed as well', (configuration) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Task.schema]); + final config = Configuration.flexibleSync(user, syncSchema); final realm = getRealm(config); final session = realm.syncSession; diff --git a/test/subscription_test.dart b/test/subscription_test.dart index 16ad28e94..48623ded8 100644 --- a/test/subscription_test.dart +++ b/test/subscription_test.dart @@ -35,11 +35,7 @@ void testSubscriptions(String name, FutureOr Function(Realm) testFunc) asy final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = Configuration.flexibleSync(user, [ - Task.schema, - Schedule.schema, - Event.schema, - ]) + final configuration = Configuration.flexibleSync(user, syncSchema) ..sessionStopPolicy = SessionStopPolicy.immediately; final realm = getRealm(configuration); await testFunc(realm); @@ -482,8 +478,8 @@ Future main([List? args]) async { final userX = await appX.logIn(credentials); final userY = await appY.logIn(credentials); - final realmX = getRealm(Configuration.flexibleSync(userX, [Task.schema])); - final realmY = getRealm(Configuration.flexibleSync(userY, [Task.schema])); + final realmX = getRealm(Configuration.flexibleSync(userX, syncSchema)); + final realmY = getRealm(Configuration.flexibleSync(userY, syncSchema)); realmX.subscriptions.update((mutableSubscriptions) { mutableSubscriptions.add(realmX.all()); @@ -510,10 +506,7 @@ Future main([List? args]) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync( - user, - [Task.schema], - ); + final config = Configuration.flexibleSync(user, syncSchema); final realm = getRealm(config); expect(() => realm.write(() => realm.add(Task(ObjectId()))), throws("no flexible sync subscription has been created")); @@ -553,7 +546,7 @@ Future main([List? args]) async { final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Task.schema]); + final config = Configuration.flexibleSync(user, syncSchema); final realm = getRealm(config); final subscriptions = realm.subscriptions; @@ -568,7 +561,7 @@ Future main([List? args]) async { final productNamePrefix = generateRandomString(4); final app = App(configuration); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Product.schema], syncErrorHandler: (syncError) { + final config = Configuration.flexibleSync(user, syncSchema, syncErrorHandler: (syncError) { compensatingWriteError = syncError; }); final realm = getRealm(config); diff --git a/test/test.dart b/test/test.dart index 093b7576b..27e62c0d7 100644 --- a/test/test.dart +++ b/test/test.dart @@ -347,6 +347,7 @@ O8BM8KOSx9wGyoGs4+OusvRkJizhPaIwa3FInLs4r+xZW9Bp6RndsmVECtvXRv5d RwIDAQAB -----END PUBLIC KEY-----'''; final int encryptionKeySize = 64; +final syncSchema = getSyncSchema(); enum AppNames { flexible, @@ -401,7 +402,7 @@ Future setupTests(List? args) async { addTearDown(() async { final paths = HashSet(); paths.add(path); - + realmCore.clearCachedApps(); while (_openRealms.isNotEmpty) { @@ -681,7 +682,7 @@ Future getIntegrationRealm({App? app, ObjectId? differentiator}) async { app ??= App(await getAppConfig()); final user = await getIntegrationUser(app); - final config = Configuration.flexibleSync(user, [Task.schema, Schedule.schema, NullableTypes.schema]); + final config = Configuration.flexibleSync(user, syncSchema); final realm = getRealm(config); if (differentiator != null) { realm.subscriptions.update((mutableSubscriptions) { @@ -806,3 +807,23 @@ void printSplunkLogLink(AppNames appName, String? uriVariable) { "https://splunk.corp.mongodb.com/en-US/app/search/search?q=search index=baas$host \"${app.uniqueName}-*\" | reverse | top error msg&earliest=-7d&latest=now&display.general.type=visualizations"); print("Splunk logs: $splunk"); } + +/// Schema list for default app service +/// used for all the flexible sync tests. +/// The full list of schemas is required when creating +/// a flexibleSync configuration to the default app service +/// to avoid causing breaking changes in development mode. +List getSyncSchema() { + return [ + Task.schema, + Schedule.schema, + Product.schema, + Event.schema, + AllTypesEmbedded.schema, + ObjectWithEmbedded.schema, + RecursiveEmbedded1.schema, + RecursiveEmbedded2.schema, + RecursiveEmbedded3.schema, + NullableTypes.schema, + ]; +}