From 5d7ec04d1b8aa5516e788713adeee4cda610df5d Mon Sep 17 00:00:00 2001 From: Marius Rackwitz Date: Fri, 11 Nov 2016 18:16:40 +0100 Subject: [PATCH] Add a test which synchronizes a change between two clients --- tests/js/user-tests.js | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/js/user-tests.js b/tests/js/user-tests.js index 83202b62..e5bc90e1 100644 --- a/tests/js/user-tests.js +++ b/tests/js/user-tests.js @@ -275,5 +275,64 @@ module.exports = { }); }, + testSynchronizeChangesWithTwoClientsAndOneUser() { + // Test Schema + class Foo {} + Foo.schema = { + name: 'Foo', + properties: { + string: 'string', + bars: { type: 'list', objectType: 'Bar' }, + }, + }; + + class Bar {} + Bar.schema = { + name: 'Bar', + properties: { integer: 'int' }, + }; + + const schema = [Foo.schema, Bar.schema]; + + // Create a user, open two clients at different local paths, synchronize changes + const username = uuid(); + return new Promise((resolve) => { + Realm.Sync.User.register('http://localhost:9080', username, 'password', (error ,user) => { + failOnError(error); + + const clientA = new Realm({ + path: 'testSynchronizeChangesWithTwoClientsAndOneUser_clientA.realm', + schema: schema, + sync: { + user: user, + url: 'http://localhost:9080/~/test', + }, + }); + + const clientB = new Realm({ + path: 'testSynchronizeChangesWithTwoClientsAndOneUser_clientB.realm', + schema: schema, + sync: { + user: user, + url: 'http://localhost:9080/~/test', + }, + }); + + clientB.addListener('change', () => { + const foos = clientB.objects('Foo'); + if (foos.length > 0) { + TestCase.assertEqual(foos.length, 1); + TestCase.assertEqual(foos[0].string, 'Hello, World!'); + resolve(); + } + }); + + clientA.write(() => { + clientA.create('Foo', { string: 'Hello, World!' }); + }); + }); + }); + }, + };