mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-23 21:10:01 +00:00
addressed pr review comments
This commit is contained in:
parent
a0f963775b
commit
cb72fe1977
@ -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];
|
||||
@ -804,4 +798,4 @@ void RealmClass<T>::close(ContextType ctx, FunctionType, ObjectType this_object,
|
||||
}
|
||||
|
||||
} // js
|
||||
} // realm
|
||||
} // realm
|
@ -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];
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user