addressed pr review comments

This commit is contained in:
blagoev 2017-05-15 15:33:53 +03:00
parent a0f963775b
commit cb72fe1977
3 changed files with 33 additions and 36 deletions

View File

@ -549,13 +549,11 @@ void RealmClass<T>::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<char>(encryption_key.begin(), encryption_key.end());
}
@ -587,13 +585,10 @@ void RealmClass<T>::wait_for_download_completion(ContextType ctx, FunctionType,
std::function<WaitHandler> 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<SyncUser> 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<T>::wait_for_download_completion(ContextType ctx, FunctionType,
Function<T>::call(protected_ctx, protected_callback, protected_this, 1, callback_arguments);
return;
}
}
ValueType callback_arguments[1];

View File

@ -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];

View File

@ -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));
@ -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));