2017-05-15 12:33:53 +00:00
|
|
|
/*
|
|
|
|
This script creates 3 new objects into a new realm. These are objects are validated to exists by the download api tests.
|
|
|
|
*/
|
2017-05-11 20:22:28 +00:00
|
|
|
'use strict';
|
2017-09-01 14:46:46 +00:00
|
|
|
console.log("download-api-helper started");
|
2017-05-11 20:22:28 +00:00
|
|
|
const username = process.argv[2];
|
|
|
|
const realmName = process.argv[3];
|
|
|
|
const realmModule = process.argv[4];
|
|
|
|
|
|
|
|
var Realm = require(realmModule);
|
|
|
|
|
2017-09-01 14:46:46 +00:00
|
|
|
function createObjects(user) {
|
|
|
|
const config = {
|
|
|
|
sync: { user,
|
|
|
|
url: `realm://localhost:9080/~/${realmName}`,
|
|
|
|
error: err => console.log(err)
|
|
|
|
},
|
|
|
|
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
|
|
|
};
|
2017-05-11 20:22:28 +00:00
|
|
|
|
2017-09-01 14:46:46 +00:00
|
|
|
var realm = new Realm(config);
|
2017-05-11 20:22:28 +00:00
|
|
|
|
2017-09-01 14:46:46 +00:00
|
|
|
realm.write(() => {
|
|
|
|
for (let i = 1; i <= 3; i++) {
|
|
|
|
realm.create('Dog', { name: `Lassy ${i}` });
|
|
|
|
}
|
|
|
|
});
|
2017-05-11 20:22:28 +00:00
|
|
|
|
2017-09-01 14:46:46 +00:00
|
|
|
console.log("Dogs count " + realm.objects('Dog').length);
|
|
|
|
setTimeout(() => process.exit(0), 3000);
|
|
|
|
}
|
2017-05-11 20:22:28 +00:00
|
|
|
|
2017-09-01 14:46:46 +00:00
|
|
|
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, registeredUser) => {
|
|
|
|
if (error) {
|
|
|
|
const registrationError = JSON.stringify(error);
|
|
|
|
Realm.Sync.User.login('http://localhost:9080', username, 'password', (err, loggedUser) => {
|
|
|
|
if (err) {
|
|
|
|
const loginError = JSON.stringify(err);
|
2017-09-12 20:04:46 +00:00
|
|
|
console.error("download-api-helper failed:\n User.register() error:\n" + err + "\n" + registrationError + "\n User.login() error:\n" + loginError);
|
2017-09-01 14:46:46 +00:00
|
|
|
process.exit(-2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
createObjects(loggedUser);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
createObjects(registeredUser);
|
|
|
|
}
|
|
|
|
});
|