2014-02-21 23:03:45 +00:00
|
|
|
var loopback = require('../');
|
2014-05-03 01:12:24 +00:00
|
|
|
var defineModelTestsWithDataSource = require('./util/model-tests');
|
2014-02-21 23:03:45 +00:00
|
|
|
|
|
|
|
describe('RemoteConnector', function() {
|
2014-05-03 01:12:24 +00:00
|
|
|
var remoteApp;
|
|
|
|
var remote;
|
2014-02-21 23:03:45 +00:00
|
|
|
|
2014-05-03 01:12:24 +00:00
|
|
|
defineModelTestsWithDataSource({
|
|
|
|
beforeEach: function(done) {
|
|
|
|
var test = this;
|
|
|
|
remoteApp = loopback();
|
|
|
|
remoteApp.use(loopback.rest());
|
|
|
|
remoteApp.listen(0, function() {
|
|
|
|
test.dataSource = loopback.createDataSource({
|
|
|
|
host: remoteApp.get('host'),
|
|
|
|
port: remoteApp.get('port'),
|
|
|
|
connector: loopback.Remote
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onDefine: function(Model) {
|
|
|
|
var RemoteModel = Model.extend(Model.modelName);
|
2014-05-03 03:04:06 +00:00
|
|
|
RemoteModel.attachTo(loopback.createDataSource({
|
|
|
|
connector: loopback.Memory
|
|
|
|
}));
|
2014-05-03 01:12:24 +00:00
|
|
|
remoteApp.model(RemoteModel);
|
|
|
|
}
|
2014-04-14 21:17:56 +00:00
|
|
|
});
|
2014-05-06 20:31:23 +00:00
|
|
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
var test = this;
|
|
|
|
remoteApp = this.remoteApp = loopback();
|
|
|
|
remoteApp.use(loopback.rest());
|
|
|
|
var ServerModel = this.ServerModel = loopback.DataModel.extend('TestModel');
|
|
|
|
|
|
|
|
remoteApp.model(ServerModel);
|
|
|
|
|
|
|
|
remoteApp.listen(0, function() {
|
|
|
|
test.remote = loopback.createDataSource({
|
|
|
|
host: remoteApp.get('host'),
|
|
|
|
port: remoteApp.get('port'),
|
|
|
|
connector: loopback.Remote
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support the save method', function (done) {
|
|
|
|
var calledServerCreate = false;
|
|
|
|
var RemoteModel = loopback.DataModel.extend('TestModel');
|
|
|
|
RemoteModel.attachTo(this.remote);
|
|
|
|
|
|
|
|
var ServerModel = this.ServerModel;
|
|
|
|
|
|
|
|
ServerModel.create = function(data, cb) {
|
|
|
|
calledServerCreate = true;
|
|
|
|
data.id = 1;
|
|
|
|
cb(null, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerModel.setupRemoting();
|
|
|
|
|
|
|
|
var m = new RemoteModel({foo: 'bar'});
|
|
|
|
m.save(function(err, inst) {
|
|
|
|
assert(inst instanceof RemoteModel);
|
|
|
|
assert(calledServerCreate);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-21 23:03:45 +00:00
|
|
|
});
|