diff --git a/test/application_test.dart b/test/application_test.dart index 0928f9e8a..4cb879421 100644 --- a/test/application_test.dart +++ b/test/application_test.dart @@ -15,21 +15,30 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +import 'dart:async'; import 'dart:io'; +import 'package:test/expect.dart'; + import '../lib/realm.dart'; import 'test.dart'; Future main([List? args]) async { print("Current PID $pid"); - setupTests(args); + await setupTests(args); test('Application can be created', () async { + final tmp = await Directory.systemTemp.createTemp(); final configuration = ApplicationConfiguration( - Platform.environment['BAAS_PROJECT_ID'] ?? generateRandomString(10), - baseFilePath: Directory.current, + generateRandomString(10), + baseFilePath: tmp, ); + final application = Application(configuration); + expect(application.configuration, configuration); + }); + + testWithBaaS('Application log in', (configuration) async { final application = Application(configuration); final credentials = Credentials.anonymous(); final user = await application.logIn(credentials); diff --git a/test/test.dart b/test/test.dart index 50ec2e950..4ec16591b 100644 --- a/test/test.dart +++ b/test/test.dart @@ -16,6 +16,7 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'dart:async'; import 'dart:collection'; import 'dart:io'; import 'dart:math'; @@ -207,3 +208,28 @@ Future setupBaas() async { baasApps.addAll(await client.getOrCreateApps()); } + +Future testWithBaaS( + String? name, + FutureOr Function(ApplicationConfiguration configuration) testFunction, { + String appName = 'flexible', + bool skip = false, +}) async { + final url = Uri.tryParse(Platform.environment['BAAS_URL'] ?? 'https://realm-dev.mongodb.com'); + final apiKey = Platform.environment['BAAS_API_KEY']; + final projectId = Platform.environment['BAAS_PROJECT_ID']; + + final missingOrSkip = skip || url == null || apiKey == null || projectId == null; + test(name, () async { + if (!missingOrSkip) { + final app = baasApps[appName] ?? baasApps.values.first; + final temporary = await Directory.systemTemp.createTemp('realm_dart_test_'); + final configuration = ApplicationConfiguration( + app.clientAppId, + baseUrl: url, + baseFilePath: temporary, + ); + return await testFunction(configuration); + } + }, skip: missingOrSkip); +}