loopback/test/remote-connector.test.js

34 lines
991 B
JavaScript
Raw Normal View History

var loopback = require('../');
describe('RemoteConnector', function() {
beforeEach(function(done) {
var LocalModel = this.LocalModel = loopback.DataModel.extend('LocalModel');
var RemoteModel = loopback.DataModel.extend('LocalModel');
var localApp = loopback();
var remoteApp = loopback();
localApp.model(LocalModel);
remoteApp.model(RemoteModel);
remoteApp.use(loopback.rest());
RemoteModel.attachTo(loopback.memory());
remoteApp.listen(0, function() {
var ds = loopback.createDataSource({
host: remoteApp.get('host'),
port: remoteApp.get('port'),
connector: loopback.Remote
});
LocalModel.attachTo(ds);
done();
});
});
it('should alow methods to be called remotely', function (done) {
var data = {foo: 'bar'};
this.LocalModel.create(data, function(err, result) {
if(err) return done(err);
expect(result).to.deep.equal({id: 1, foo: 'bar'});
done();
});
});
});