Add replication e2e tests
This commit is contained in:
parent
e86a00de69
commit
b660f8a59e
|
@ -143,7 +143,8 @@ module.exports = function(grunt) {
|
|||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
'test/e2e/remote-connector.e2e.js'
|
||||
'test/e2e/remote-connector.e2e.js',
|
||||
'test/e2e/replication.e2e.js'
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
|
|
|
@ -51,4 +51,4 @@ Connector._createJDBAdapter = function (jdbModule) {
|
|||
|
||||
Connector.prototype._addCrudOperationsFromJDBAdapter = function (connector) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,4 @@ inherits(Memory, Connector);
|
|||
* JugglingDB Compatibility
|
||||
*/
|
||||
|
||||
Memory.initialize = JdbMemory.initialize;
|
||||
Memory.initialize = JdbMemory.initialize;
|
||||
|
|
|
@ -51,6 +51,9 @@ RemoteConnector.prototype.define = function(definition) {
|
|||
var url = this.url;
|
||||
var adapter = this.adapter;
|
||||
|
||||
assert(Model.app, 'Cannot attach Model: ' + Model.modelName
|
||||
+ ' to a RemoteConnector. You must first attach it to an app!');
|
||||
|
||||
Model.remotes(function(err, remotes) {
|
||||
var sharedClass = getSharedClass(remotes, className);
|
||||
remotes.connect(url, adapter);
|
||||
|
|
|
@ -384,6 +384,8 @@ Change.getCheckpointModel = function() {
|
|||
var checkpointModel = this.Checkpoint;
|
||||
if(checkpointModel) return checkpointModel;
|
||||
this.checkpoint = checkpointModel = require('./checkpoint').extend('checkpoint');
|
||||
assert(this.dataSource, 'Cannot getCheckpointModel(): ' + this.modelName
|
||||
+ ' is not attached to a dataSource');
|
||||
checkpointModel.attachTo(this.dataSource);
|
||||
return checkpointModel;
|
||||
}
|
||||
|
|
|
@ -593,6 +593,9 @@ Model.getChangeModel = function() {
|
|||
var changeModel = this.Change;
|
||||
if(changeModel) return changeModel;
|
||||
this.Change = changeModel = require('./change').extend(this.modelName + '-change');
|
||||
|
||||
assert(this.dataSource, 'Cannot getChangeModel(): ' + this.modelName
|
||||
+ ' is not attached to a dataSource');
|
||||
changeModel.attachTo(this.dataSource);
|
||||
return changeModel;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
var path = require('path');
|
||||
var loopback = require('../../');
|
||||
var models = require('../fixtures/e2e/models');
|
||||
var TestModel = models.TestModel;
|
||||
var LocalTestModel = TestModel.extend('LocalTestModel');
|
||||
var assert = require('assert');
|
||||
|
||||
describe('ReplicationModel', function () {
|
||||
it('ReplicationModel.enableChangeTracking()', function (done) {
|
||||
var TestReplicationModel = loopback.DataModel.extend('TestReplicationModel');
|
||||
var remote = loopback.createDataSource({
|
||||
url: 'http://localhost:3000/api',
|
||||
connector: loopback.Remote
|
||||
});
|
||||
var testApp = loopback();
|
||||
testApp.model(TestReplicationModel);
|
||||
TestReplicationModel.attachTo(remote);
|
||||
// chicken-egg condition
|
||||
// getChangeModel() requires it to be attached to an app
|
||||
// attaching to the app requires getChangeModel()
|
||||
var Change = TestReplicationModel.getChangeModel();
|
||||
testApp.model(Change);
|
||||
Change.attachTo(remote);
|
||||
TestReplicationModel.enableChangeTracking();
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('Replication', function() {
|
||||
beforeEach(function() {
|
||||
// setup the remote connector
|
||||
var localApp = loopback();
|
||||
var ds = loopback.createDataSource({
|
||||
url: 'http://localhost:3000/api',
|
||||
connector: loopback.Remote
|
||||
});
|
||||
localApp.model(TestModel);
|
||||
localApp.model(LocalTestModel);
|
||||
TestModel.attachTo(ds);
|
||||
var memory = loopback.memory();
|
||||
LocalTestModel.attachTo(memory);
|
||||
|
||||
// TODO(ritch) this should be internal...
|
||||
LocalTestModel.getChangeModel().attachTo(memory);
|
||||
|
||||
LocalTestModel.enableChangeTracking();
|
||||
|
||||
// failing because change model is not properly attached
|
||||
TestModel.enableChangeTracking();
|
||||
});
|
||||
|
||||
it('should replicate local data to the remote', function (done) {
|
||||
LocalTestModel.create({
|
||||
foo: 'bar'
|
||||
}, function() {
|
||||
LocalTestModel.replicate(0, TestModel, function() {
|
||||
console.log('replicated');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue