Skip to content

Commit

Permalink
Add testWithBass function
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Apr 8, 2022
1 parent c2bf5a9 commit dc464a4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/application_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> main([List<String>? 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);
Expand Down
26 changes: 26 additions & 0 deletions test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//
////////////////////////////////////////////////////////////////////////////////
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:path/path.dart' as _path;
Expand Down Expand Up @@ -179,3 +180,28 @@ Future<void> setupBaas() async {

baasApps.addAll(await client.getOrCreateApps());
}

Future<void> testWithBaaS(
String? name,
FutureOr<void> 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);
}

0 comments on commit dc464a4

Please sign in to comment.