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]); auto callback_function = Value::validated_to_function(ctx, arguments[1]);
ValueType sync_config_value = Object::get_property(ctx, config_object, "sync"); 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; realm::Realm::Config config;
static const String encryption_key_string = "encryptionKey"; static const String encryption_key_string = "encryptionKey";
ValueType encryption_key_value = Object::get_property(ctx, config_object, encryption_key_string); 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); std::string encryption_key = NativeAccessor::to_binary(ctx, encryption_key_value);
config.encryption_key = std::vector<char>(encryption_key.begin(), encryption_key.end()); 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); std::function<WaitHandler> waitFunc = std::move(wait_handler);
auto realm = realm::Realm::get_shared_realm(config); 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; std::shared_ptr<SyncUser> user = sync_config->user;
if (user && user->state() != SyncUser::State::Error) if (user && user->state() != SyncUser::State::Error) {
{ if (auto session = user->session_for_on_disk_path(config.path)) {
if (auto session = user->session_for_on_disk_path(config.path))
{
session->wait_for_download_completion([=](std::error_code error_code) { session->wait_for_download_completion([=](std::error_code error_code) {
realm->config(); //capture and keep realm instance for till here realm->config(); //capture and keep realm instance for till here
waitFunc(error_code); 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); Function<T>::call(protected_ctx, protected_callback, protected_this, 1, callback_arguments);
return; return;
} }
} }
ValueType callback_arguments[1]; ValueType callback_arguments[1];
@ -804,4 +798,4 @@ void RealmClass<T>::close(ContextType ctx, FunctionType, ObjectType this_object,
} }
} // js } // js
} // realm } // realm

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'; 'use strict';
const username = process.argv[2]; const username = process.argv[2];

View File

@ -128,7 +128,6 @@ module.exports = {
} }
const username = uuid(); const username = uuid();
const username2 = uuid();
const realmName = uuid(); const realmName = uuid();
const expectedObjectsCount = 3; const expectedObjectsCount = 3;
@ -138,6 +137,7 @@ module.exports = {
fs.appendFileSync(tmpFile.fd, content, { encoding: 'utf8' }); fs.appendFileSync(tmpFile.fd, content, { encoding: 'utf8' });
return new Promise((resolve, reject) => { 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) => { const child = execFile('node', [tmpFile.name, username, realmName, REALM_MODULE_PATH], { cwd: tmpDir.name }, (error, stdout, stderr) => {
if (error) { if (error) {
reject(new Error('Error executing download api helper' + error)); reject(new Error('Error executing download api helper' + error));
@ -145,33 +145,33 @@ module.exports = {
resolve(); resolve();
}); });
}) })
.then(() => { .then(() => {
return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { return promisifiedLogin('http://localhost:9080', username, 'password').then(user => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const accessTokenRefreshed = this; const accessTokenRefreshed = this;
let successCounter = 0; let successCounter = 0;
let config = { let config = {
sync: { user, url: `realm://localhost:9080/~/${realmName}` }, sync: { user, url: `realm://localhost:9080/~/${realmName}` },
schema: [{ name: 'Dog', properties: { name: 'string' } }], schema: [{ name: 'Dog', properties: { name: 'string' } }],
}; };
Realm.open(config) Realm.open(config)
.then(realm => { .then(realm => {
let actualObjectsCount = realm.objects('Dog').length; let actualObjectsCount = realm.objects('Dog').length;
TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count"); TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count");
const session = realm.syncSession; const session = realm.syncSession;
TestCase.assertInstanceOf(session, Realm.Sync.Session); TestCase.assertInstanceOf(session, Realm.Sync.Session);
TestCase.assertEqual(session.user.identity, user.identity); TestCase.assertEqual(session.user.identity, user.identity);
TestCase.assertEqual(session.config.url, config.sync.url); TestCase.assertEqual(session.config.url, config.sync.url);
TestCase.assertEqual(session.config.user.identity, config.sync.user.identity); TestCase.assertEqual(session.config.user.identity, config.sync.user.identity);
TestCase.assertEqual(session.state, 'active'); TestCase.assertEqual(session.state, 'active');
resolve(); resolve();
}).catch(e => { reject(e) }); }).catch(e => { reject(e) });
});
}); });
}); });
});
}, },
testRealmOpenAsync() { testRealmOpenAsync() {
@ -180,7 +180,6 @@ module.exports = {
} }
const username = uuid(); const username = uuid();
const username2 = uuid();
const realmName = uuid(); const realmName = uuid();
const expectedObjectsCount = 3; const expectedObjectsCount = 3;
@ -190,6 +189,7 @@ module.exports = {
fs.appendFileSync(tmpFile.fd, content, { encoding: 'utf8' }); fs.appendFileSync(tmpFile.fd, content, { encoding: 'utf8' });
return new Promise((resolve, reject) => { 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) => { const child = execFile('node', [tmpFile.name, username, realmName, REALM_MODULE_PATH], { cwd: tmpDir.name }, (error, stdout, stderr) => {
if (error) { if (error) {
reject(new Error('Error executing download api helper' + error)); reject(new Error('Error executing download api helper' + error));