From cb72fe19772f0118f20d42656d60a3b2e20c65f6 Mon Sep 17 00:00:00 2001 From: blagoev Date: Mon, 15 May 2017 15:33:53 +0300 Subject: [PATCH] addressed pr review comments --- src/js_realm.hpp | 18 +++++-------- tests/js/download-api-helper.js | 3 +++ tests/js/session-tests.js | 48 ++++++++++++++++----------------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 10930dbd..e7a15242 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -549,13 +549,11 @@ void RealmClass::wait_for_download_completion(ContextType ctx, FunctionType, auto callback_function = Value::validated_to_function(ctx, arguments[1]); ValueType sync_config_value = Object::get_property(ctx, config_object, "sync"); - if (!Value::is_undefined(ctx, sync_config_value)) - { + if (!Value::is_undefined(ctx, sync_config_value)) { realm::Realm::Config config; static const String encryption_key_string = "encryptionKey"; ValueType encryption_key_value = Object::get_property(ctx, config_object, encryption_key_string); - if (!Value::is_undefined(ctx, encryption_key_value)) - { + if (!Value::is_undefined(ctx, encryption_key_value)) { std::string encryption_key = NativeAccessor::to_binary(ctx, encryption_key_value); config.encryption_key = std::vector(encryption_key.begin(), encryption_key.end()); } @@ -587,13 +585,10 @@ void RealmClass::wait_for_download_completion(ContextType ctx, FunctionType, std::function waitFunc = std::move(wait_handler); auto realm = realm::Realm::get_shared_realm(config); - if (auto sync_config = config.sync_config) - { + if (auto sync_config = config.sync_config) { std::shared_ptr user = sync_config->user; - if (user && user->state() != SyncUser::State::Error) - { - if (auto session = user->session_for_on_disk_path(config.path)) - { + if (user && user->state() != SyncUser::State::Error) { + if (auto session = user->session_for_on_disk_path(config.path)) { session->wait_for_download_completion([=](std::error_code error_code) { realm->config(); //capture and keep realm instance for till here waitFunc(error_code); @@ -611,7 +606,6 @@ void RealmClass::wait_for_download_completion(ContextType ctx, FunctionType, Function::call(protected_ctx, protected_callback, protected_this, 1, callback_arguments); return; } - } ValueType callback_arguments[1]; @@ -804,4 +798,4 @@ void RealmClass::close(ContextType ctx, FunctionType, ObjectType this_object, } } // js -} // realm +} // realm \ No newline at end of file diff --git a/tests/js/download-api-helper.js b/tests/js/download-api-helper.js index b73d000e..674e468b 100644 --- a/tests/js/download-api-helper.js +++ b/tests/js/download-api-helper.js @@ -1,3 +1,6 @@ +/* +This script creates 3 new objects into a new realm. These are objects are validated to exists by the download api tests. +*/ 'use strict'; const username = process.argv[2]; diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index 51ef57e6..08a5fbd7 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -128,7 +128,6 @@ module.exports = { } const username = uuid(); - const username2 = uuid(); const realmName = uuid(); const expectedObjectsCount = 3; @@ -138,6 +137,7 @@ module.exports = { fs.appendFileSync(tmpFile.fd, content, { encoding: 'utf8' }); return new Promise((resolve, reject) => { + //execute download-api-helper which inserts predefined number of objects into the synced realm. const child = execFile('node', [tmpFile.name, username, realmName, REALM_MODULE_PATH], { cwd: tmpDir.name }, (error, stdout, stderr) => { if (error) { reject(new Error('Error executing download api helper' + error)); @@ -145,33 +145,33 @@ module.exports = { resolve(); }); }) - .then(() => { - return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { - return new Promise((resolve, reject) => { - const accessTokenRefreshed = this; - let successCounter = 0; + .then(() => { + return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { + return new Promise((resolve, reject) => { + const accessTokenRefreshed = this; + let successCounter = 0; - let config = { - sync: { user, url: `realm://localhost:9080/~/${realmName}` }, - schema: [{ name: 'Dog', properties: { name: 'string' } }], - }; + let config = { + sync: { user, url: `realm://localhost:9080/~/${realmName}` }, + schema: [{ name: 'Dog', properties: { name: 'string' } }], + }; - Realm.open(config) - .then(realm => { - let actualObjectsCount = realm.objects('Dog').length; - TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count"); + Realm.open(config) + .then(realm => { + let actualObjectsCount = realm.objects('Dog').length; + TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count"); - const session = realm.syncSession; - TestCase.assertInstanceOf(session, Realm.Sync.Session); - TestCase.assertEqual(session.user.identity, user.identity); - TestCase.assertEqual(session.config.url, config.sync.url); - TestCase.assertEqual(session.config.user.identity, config.sync.user.identity); - TestCase.assertEqual(session.state, 'active'); - resolve(); - }).catch(e => { reject(e) }); - }); + const session = realm.syncSession; + TestCase.assertInstanceOf(session, Realm.Sync.Session); + TestCase.assertEqual(session.user.identity, user.identity); + TestCase.assertEqual(session.config.url, config.sync.url); + TestCase.assertEqual(session.config.user.identity, config.sync.user.identity); + TestCase.assertEqual(session.state, 'active'); + resolve(); + }).catch(e => { reject(e) }); }); }); + }); }, testRealmOpenAsync() { @@ -180,7 +180,6 @@ module.exports = { } const username = uuid(); - const username2 = uuid(); const realmName = uuid(); const expectedObjectsCount = 3; @@ -190,6 +189,7 @@ module.exports = { fs.appendFileSync(tmpFile.fd, content, { encoding: 'utf8' }); return new Promise((resolve, reject) => { + //execute download-api-helper which inserts predefined number of objects into the synced realm. const child = execFile('node', [tmpFile.name, username, realmName, REALM_MODULE_PATH], { cwd: tmpDir.name }, (error, stdout, stderr) => { if (error) { reject(new Error('Error executing download api helper' + error));