How to use realm - 10 common examples

To help you get started, we’ve selected a few realm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github realm / realm-js / tests / js / session-tests.js View on Github external
return Realm.Sync.User.login('http://127.0.0.1:9080', credentials).then(user => {
            let config = {
                sync: {
                    user: user,
                    url: 'realm://127.0.0.1:9080/~/default',
                    fullSynchronization: true, // <---- calling subscribe should fail
                    error: (session, error) => console.log(error)
                },
                schema: [{ name: 'Dog', properties: { name: 'string' } }]
            };

            Realm.deleteFile(config);
            const realm = new Realm(config);
            TestCase.assertEqual(realm.objects('Dog').length, 0);
            TestCase.assertThrows(() => realm.objects('Dog').filtered("name == 'Lassy 1'").subscribe());
            realm.close();
        });
    },
github realm / realm-js / tests / electron / spec.js View on Github external
assert.equal(Realm.name, "Realm");
  });

  /*
  it("fails", (done) => {
    assert(false);
  });
  */
});

// Almost a copy-paste from the ../spec/unit_tests.js - so it might be possible to generalize.

// Setting the timeout to the same as the ../../spec/unit_tests.js
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

Realm.copyBundledRealmFiles = function() {
  const sourceDir = path.join(__dirname, '../data');
  const destinationDir = path.dirname(Realm.defaultPath);

  for (let filename of fs.readdirSync(sourceDir)) {
    let src = path.join(sourceDir, filename);
    let dest = path.join(destinationDir, filename);

    // If the destination file already exists, then don't overwrite it.
    try {
        fs.accessSync(dest);
        continue;
    } catch (e) {}

    fs.writeFileSync(dest, fs.readFileSync(src));
  }
};
github realm / realm-js / tests / spec / unit_tests.js View on Github external
RealmLogging.patch(Realm);

const RealmTests = require('../js');

jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
let isDebuggerAttached = typeof v8debug === 'object';
if (!isDebuggerAttached && isNodeProccess) {
    isDebuggerAttached = /--debug|--inspect/.test(process.execArgv.join(' '));
}

if (isDebuggerAttached) {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000000;
}

// Create this method with appropriate implementation for Node testing.
Realm.copyBundledRealmFiles = function () {
    let sourceDir = path.join(__dirname, '../data');
    let destinationDir = path.dirname(Realm.defaultPath);

    for (let filename of fs.readdirSync(sourceDir)) {
        let src = path.join(sourceDir, filename);
        let dest = path.join(destinationDir, filename);

        // If the destination file already exists, then don't overwrite it.
        try {
            fs.accessSync(dest);
            continue;
        } catch (e) { }

        fs.writeFileSync(dest, fs.readFileSync(src));
    }
};
github realm / realm-js / tests / js / user-tests.js View on Github external
testLogout() {
    return Realm.Sync.User.login('http://127.0.0.1:9080', Realm.Sync.Credentials.anonymous()).then((user) => {
      assertIsUser(user);

      assertIsSameUser(user, Realm.Sync.User.current);
      user.logout();

      // Is now logged out.
      TestCase.assertUndefined(Realm.Sync.User.current);

      // Can we open a realm with the registered user?
      TestCase.assertThrows(() => new Realm({sync: {user: user, url: 'realm://127.0.0.1:9080/~/test'}}));
    });
  },
github realm / realm-js / tests / js / index.js View on Github external
// FIXME: Permission tests currently fail in react native
        TESTS.PermissionTests = require('./permission-tests');
        node_require('./adapter-tests');
        node_require('./notifier-tests');
    }
}

// If on node, run the async tests
if (isNodeProcess && process.platform !== 'win32') {
    TESTS.AsyncTests = node_require('./async-tests');
}

if (global.enableSyncTests) {
    // Ensure that the sync manager is initialized as initializing it
    // after calling clearTestState() doesn't work
    Realm.Sync.User.all;
}

var SPECIAL_METHODS = {
    beforeEach: true,
    afterEach: true,
};

exports.getTestNames = function () {
    var testNames = {};

    for (var suiteName in TESTS) {
        var testSuite = TESTS[suiteName];

        testNames[suiteName] = Object.keys(testSuite).filter(function (testName) {
            return !(testName in SPECIAL_METHODS) && typeof testSuite[testName] == 'function';
        });
github realm / realm-js / tests / spec / unit_tests.js View on Github external
Realm.copyBundledRealmFiles = function () {
    let sourceDir = path.join(__dirname, '../data');
    let destinationDir = path.dirname(Realm.defaultPath);

    for (let filename of fs.readdirSync(sourceDir)) {
        let src = path.join(sourceDir, filename);
        let dest = path.join(destinationDir, filename);

        // If the destination file already exists, then don't overwrite it.
        try {
            fs.accessSync(dest);
            continue;
        } catch (e) { }

        fs.writeFileSync(dest, fs.readFileSync(src));
    }
};
github realm / realm-js / tests / shared / js / migration-tests.js View on Github external
// invalid migration function
        TestCase.assertThrows(function() {
            new Realm({schema: [], schemaVersion: 2, migration: 'invalid'});
        });

        // migration function exceptions should propogate
        var exception = new Error('expected exception');
        realm = undefined;
        TestCase.assertThrowsException(function() {
            realm = new Realm({schema: [], schemaVersion: 3, migration: function() {
                throw exception;
            }});
        }, exception);
        TestCase.assertEqual(realm, undefined);
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), 1);

        // migration function shouldn't run if nothing changes
        realm = new Realm({schema: [Schemas.TestObject], migration: migrationFunction, schemaVersion: 1});
        TestCase.assertEqual(1, count);
        realm.close();

        // migration function should run if only schemaVersion changes
        realm = new Realm({schema: [Schemas.TestObject], migration: function() { count++; }, schemaVersion: 2});
        TestCase.assertEqual(2, count);
        realm.close();
    },
github realm / realm-js / tests / js / realm-tests.js View on Github external
testRealmExists: function() {

        // Local Realms
        let config = {schema: [schemas.TestObject]};
        TestCase.assertFalse(Realm.exists(config));
        new Realm(config).close();
        TestCase.assertTrue(Realm.exists(config));

        // Sync Realms
        if (!global.enableSyncTests) {
            return;
        }
        return Realm.Sync.User.login('http://127.0.0.1:9080', Realm.Sync.Credentials.nickname("admin", true))
            .then(user => {
                const fullSyncConfig = user.createConfiguration({
                    schema: [schemas.TestObject],
                    sync: {
                        url: `realm://127.0.0.1:9080/testRealmExists_${Utils.uuid()}`,
                        fullSynchronization: true,
                    },
                });
                TestCase.assertFalse(Realm.exists(fullSyncConfig));
                new Realm(fullSyncConfig).close();
github realm / realm-js / tests / js / realm-tests.js View on Github external
testRealmExists: function() {

        // Local Realms
        let config = {schema: [schemas.TestObject]};
        TestCase.assertFalse(Realm.exists(config));
        new Realm(config).close();
        TestCase.assertTrue(Realm.exists(config));

        // Sync Realms
        if (!global.enableSyncTests) {
            return;
        }
        return Realm.Sync.User.login('http://127.0.0.1:9080', Realm.Sync.Credentials.nickname("admin", true))
            .then(user => {
                const fullSyncConfig = user.createConfiguration({
                    schema: [schemas.TestObject],
                    sync: {
                        url: `realm://127.0.0.1:9080/testRealmExists_${Utils.uuid()}`,
                        fullSynchronization: true,
                    },
                });
github realm / realm-js / tests / js / permission-tests.js View on Github external
// Full sync shouldn't include the permission schema
            config = {
                schema: [],
                sync: {
                    user: user,
                    url: `realm://NO_SERVER/foo`,
                    fullSynchronization: true
                }
            };
            realm = new Realm(config);
            TestCase.assertTrue(realm.empty);
            TestCase.assertEqual(realm.schema.length, 0);

            realm.close();
            Realm.deleteFile(config);
        });
    },