Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common sync schema collection for all tests #1399

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Future<void> main([List<String>? 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;

Expand Down
38 changes: 19 additions & 19 deletions test/client_reset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,34 @@ Future<void> main([List<String>? 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);

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 {
Expand All @@ -72,7 +72,7 @@ Future<void> main([List<String>? args]) async {
final resetCompleter = Completer<void>();
final config = Configuration.flexibleSync(
user,
[Task.schema, Schedule.schema],
syncSchema,
clientResetHandler: ManualRecoveryHandler((syncError) {
resetCompleter.completeError(syncError);
}),
Expand All @@ -93,7 +93,7 @@ Future<void> main([List<String>? args]) async {
final resetCompleter = Completer<void>();
final config = Configuration.flexibleSync(
user,
[Task.schema, Schedule.schema],
syncSchema,
clientResetHandler: ManualRecoveryHandler((clientResetError) {
resetCompleter.completeError(clientResetError);
}),
Expand Down Expand Up @@ -122,7 +122,7 @@ Future<void> main([List<String>? args]) async {
final resetCompleter = Completer<bool>();
final config = Configuration.flexibleSync(
user,
[Task.schema, Schedule.schema],
syncSchema,
clientResetHandler: ManualRecoveryHandler((clientResetError) {
resetCompleter.completeError(clientResetError);
}),
Expand Down Expand Up @@ -152,7 +152,7 @@ Future<void> main([List<String>? args]) async {
final user = await getIntegrationUser(app);

final onManualResetFallback = Completer<void>();
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!"),
Expand All @@ -177,7 +177,7 @@ Future<void> main([List<String>? 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,
Expand All @@ -204,7 +204,7 @@ Future<void> main([List<String>? 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(),
Expand Down Expand Up @@ -233,7 +233,7 @@ Future<void> main([List<String>? args]) async {
int onAfterRecoveryOccurred = 0;
final onAfterCompleter = Completer<void>();

final config = Configuration.flexibleSync(user, [Task.schema, Schedule.schema],
final config = Configuration.flexibleSync(user, syncSchema,
clientResetHandler: Creator.create(
clientResetHandlerType,
onBeforeReset: (beforeResetRealm) => onBeforeResetOccurred++,
Expand Down Expand Up @@ -300,7 +300,7 @@ Future<void> main([List<String>? 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) {
Expand Down Expand Up @@ -349,7 +349,7 @@ Future<void> main([List<String>? 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) {
Expand Down Expand Up @@ -389,7 +389,7 @@ Future<void> main([List<String>? args]) async {

final config = Configuration.flexibleSync(
user,
[Task.schema, Schedule.schema],
syncSchema,
clientResetHandler: DiscardUnsyncedChangesHandler(
onBeforeReset: (beforeResetRealm) async {
await Future<void>.delayed(Duration(seconds: 1));
Expand Down Expand Up @@ -426,7 +426,7 @@ Future<void> main([List<String>? args]) async {
late ClientResetError clientResetErrorOnManualFallback;
final config = Configuration.flexibleSync(
user,
[Task.schema, Schedule.schema],
syncSchema,
clientResetHandler: DiscardUnsyncedChangesHandler(
onBeforeReset: (beforeResetRealm) {
onBeforeResetOccurred++;
Expand Down Expand Up @@ -481,7 +481,7 @@ Future<void> main([List<String>? 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]);
Expand All @@ -493,7 +493,7 @@ Future<void> main([List<String>? 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]);
Expand Down Expand Up @@ -540,7 +540,7 @@ Future<void> main([List<String>? args]) async {
late ClientResetError clientResetError;
final config = Configuration.flexibleSync(
user,
[Task.schema, Schedule.schema],
syncSchema,
clientResetHandler: ManualRecoveryHandler((syncError) {
clientResetError = syncError;
resetCompleter.complete();
Expand Down
29 changes: 14 additions & 15 deletions test/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Future<void> main([List<String>? 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);
Expand All @@ -91,7 +91,7 @@ Future<void> main([List<String>? 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);
});
Expand All @@ -108,7 +108,7 @@ Future<void> main([List<String>? 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);
Expand All @@ -125,7 +125,7 @@ Future<void> main([List<String>? 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)));
});
Expand Down Expand Up @@ -497,7 +497,7 @@ Future<void> main([List<String>? 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;
});
Expand All @@ -510,7 +510,7 @@ Future<void> main([List<String>? 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));
Expand All @@ -520,7 +520,7 @@ Future<void> main([List<String>? 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');
});
Expand All @@ -532,7 +532,7 @@ Future<void> main([List<String>? 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);
});

Expand All @@ -543,8 +543,7 @@ Future<void> main([List<String>? 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) {
Expand All @@ -553,7 +552,7 @@ Future<void> main([List<String>? 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<Task>(oid), isNotNull);
});
Expand Down Expand Up @@ -587,7 +586,7 @@ Future<void> main([List<String>? args]) async {

List<int> key = List<int>.generate(encryptionKeySize + 10, (i) => random.nextInt(256));
expect(
() => Configuration.flexibleSync(user, [Task.schema], encryptionKey: key),
() => Configuration.flexibleSync(user, syncSchema, encryptionKey: key),
throws<RealmException>("Wrong encryption key size"),
);
});
Expand All @@ -611,7 +610,7 @@ Future<void> main([List<String>? 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<Task>()));
expect(() => realm.write(() {}), throws<RealmException>("in the Realm exceeded the limit of 1"));
Expand All @@ -621,9 +620,9 @@ Future<void> main([List<String>? 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<RealmException>("in the Realm exceeded the limit of 1"));
});
Expand Down
6 changes: 3 additions & 3 deletions test/embedded_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Future<void> main([List<String>? 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);
}

Expand All @@ -58,10 +58,10 @@ Future<void> main([List<String>? 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<RealmException>("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();
Expand Down
Loading
Loading