2016-05-03 22:50:21 +00:00
|
|
|
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-11-15 21:46:23 +00:00
|
|
|
'use strict';
|
2014-04-16 14:33:17 +00:00
|
|
|
var path = require('path');
|
|
|
|
var loopback = require('../../');
|
|
|
|
var models = require('../fixtures/e2e/models');
|
|
|
|
var TestModel = models.TestModel;
|
2014-04-30 00:17:49 +00:00
|
|
|
var LocalTestModel = TestModel.extend('LocalTestModel', {}, {
|
2016-04-01 09:14:26 +00:00
|
|
|
trackChanges: true,
|
2014-04-16 14:33:17 +00:00
|
|
|
});
|
2014-04-30 00:17:49 +00:00
|
|
|
var assert = require('assert');
|
2014-04-16 14:33:17 +00:00
|
|
|
|
2014-04-30 00:17:49 +00:00
|
|
|
describe('Replication', function() {
|
|
|
|
before(function() {
|
2014-04-16 14:33:17 +00:00
|
|
|
// setup the remote connector
|
|
|
|
var ds = loopback.createDataSource({
|
2015-01-16 06:51:53 +00:00
|
|
|
url: 'http://127.0.0.1:3000/api',
|
2016-04-01 09:14:26 +00:00
|
|
|
connector: loopback.Remote,
|
2014-04-16 14:33:17 +00:00
|
|
|
});
|
|
|
|
TestModel.attachTo(ds);
|
|
|
|
var memory = loopback.memory();
|
|
|
|
LocalTestModel.attachTo(memory);
|
|
|
|
});
|
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
it('should replicate local data to the remote', function(done) {
|
2014-04-30 00:17:49 +00:00
|
|
|
var RANDOM = Math.random();
|
|
|
|
|
2014-04-16 14:33:17 +00:00
|
|
|
LocalTestModel.create({
|
2016-04-01 09:14:26 +00:00
|
|
|
n: RANDOM,
|
2014-04-30 00:17:49 +00:00
|
|
|
}, function(err, created) {
|
2014-04-16 14:33:17 +00:00
|
|
|
LocalTestModel.replicate(0, TestModel, function() {
|
2014-11-21 02:35:36 +00:00
|
|
|
if (err) return done(err);
|
2016-05-05 04:09:06 +00:00
|
|
|
|
2016-11-15 21:46:23 +00:00
|
|
|
TestModel.findOne({n: RANDOM}, function(err, found) {
|
2014-04-30 00:17:49 +00:00
|
|
|
assert.equal(created.id, found.id);
|
2016-05-05 04:09:06 +00:00
|
|
|
|
2014-04-30 00:17:49 +00:00
|
|
|
done();
|
|
|
|
});
|
2014-04-16 14:33:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|