Skip to content

Commit

Permalink
Use qbs v2 and reenable schema migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Jul 29, 2024
1 parent 28e0e5a commit ba12c9f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
57 changes: 40 additions & 17 deletions packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ class BaasClient {

static final String defaultAppName = AppName.flexible.name;

final String _adminApiUrl;
String get _adminApiUrl => '$baseUrl/api/admin/v3.0';
String get _privateApiUrl => '$baseUrl/api/private/v1.0';

final String? _clusterName;
final Map<String, String> _headers;
final String _appSuffix;
Expand All @@ -170,8 +172,7 @@ class BaasClient {
late String publicRSAKey = '';

BaasClient._(this.baseUrl, String differentiator, [this._clusterName])
: _adminApiUrl = '$baseUrl/api/admin/v3.0',
_headers = <String, String>{'Accept': 'application/json'},
: _headers = <String, String>{'Accept': 'application/json'},
_appSuffix = '-${shortenDifferentiator(differentiator)}${_clusterName == null ? '' : '-$_clusterName'}';

/// A client that imports apps in a MongoDB Atlas docker image. See https://github.com/realm/ci/tree/master/realm/docker/mongodb-realm
Expand Down Expand Up @@ -333,18 +334,25 @@ class BaasClient {
try {
final response = await _get('groups/$_groupId/apps/$appId/sync/progress');

final progressInfo = response['progress'] as Map<String, dynamic>;
for (final key in progressInfo.keys) {
final error = progressInfo[key]['error'] as String?;
if (error != null) {
print(error);
return false;
}
final acceptingClients = response['accepting_clients'] as bool? ?? false;
if (acceptingClients) {
return true;
}

final progressInfo = response['progress'] as Map<String, dynamic>?;
if (progressInfo != null) {
for (final key in (progressInfo?.keys ?? <String>{})) {
final error = progressInfo[key]['error'] as String?;
if (error != null) {
print(error);
return false;
}

final namespaceComplete = progressInfo[key]['complete'] as bool;
final namespaceComplete = progressInfo[key]['complete'] as bool;

if (!namespaceComplete) {
return false;
if (!namespaceComplete) {
return false;
}
}
}

Expand Down Expand Up @@ -538,6 +546,10 @@ class BaasClient {
}''');
}

print('Enable qbsv2 for ${app.name}');

await _setFeatureFlag(app, 'allow_qbs_v2');

print('Creating database db_$uniqueName');

final mongoServiceId = await _createMongoDBService(
Expand Down Expand Up @@ -631,6 +643,17 @@ class BaasClient {
return result['key'] as String;
}

Future<void> _setFeatureFlag(BaasApp app, String feature, {bool enabled = true}) async {
final action = enabled ? 'enable' : 'disable';
await _post(
'groups/$_groupId/apps/$app/features',
'''{
"action": "$action",
"feature_flags": [ "$feature" ]
}''',
apiRootPath: _privateApiUrl);
}

Future<void> _authenticate(String provider, String credentials) async {
dynamic response = await _post('auth/providers/$provider/login', credentials);

Expand Down Expand Up @@ -766,12 +789,12 @@ class BaasClient {
return additionalHeaders;
}

Uri _getUri(String relativePath) {
return Uri.parse('$_adminApiUrl/$relativePath');
Uri _getUri(String relativePath, {String? apiRootPath}) {
return Uri.parse('${apiRootPath ?? _adminApiUrl}/$relativePath');
}

Future<dynamic> _post(String relativePath, String payload) async {
var response = await http.post(_getUri(relativePath), headers: _getHeaders({'Content-Type': 'application/json'}), body: payload);
Future<dynamic> _post(String relativePath, String payload, {String? apiRootPath}) async {
var response = await http.post(_getUri(relativePath, apiRootPath: apiRootPath), headers: _getHeaders({'Content-Type': 'application/json'}), body: payload);
return _decodeResponse(response, payload);
}

Expand Down
7 changes: 3 additions & 4 deletions packages/realm_dart/test/sync_migration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:typed_data';

import 'package:realm_dart/realm.dart';
import 'package:realm_dart/src/configuration.dart';
import 'package:test/test.dart' hide test, throws;

import 'test.dart';

Expand Down Expand Up @@ -159,7 +158,7 @@ void main() {
expect(objv2.stringValue, isNull);
expect(objv2.uuidValue, isNull);
expect(objv2.binaryValue, isNull);
}, appName: AppName.staticSchema, skip: true);
}, appName: AppName.staticSchema);

baasTest('Can remove field', (appConfig) async {
final differentiator = ObjectId();
Expand Down Expand Up @@ -237,7 +236,7 @@ void main() {
expect(objv2.stringValue, isNull);
expect(objv2.uuidValue, isNull);
expect(objv2.binaryValue, isNull);
}, appName: AppName.staticSchema, skip:true);
}, appName: AppName.staticSchema);

baasTest('Realm can be migrated skipping versions (0->2)', (appConfig) async {
final differentiator = ObjectId();
Expand All @@ -262,5 +261,5 @@ void main() {
expect(objv2.stringValue, isNull);
expect(objv2.uuidValue, isNull);
expect(objv2.binaryValue, isNull);
}, appName: AppName.staticSchema, skip: true);
}, appName: AppName.staticSchema);
}

0 comments on commit ba12c9f

Please sign in to comment.