Add test for custom http.path configuration.

This commit is contained in:
Richard Pringle 2015-11-26 16:17:33 -05:00
parent 7e2c4042ba
commit dbe06078fb
1 changed files with 54 additions and 20 deletions

View File

@ -3,6 +3,24 @@ var defineModelTestsWithDataSource = require('./util/model-tests');
var assert = require('assert'); var assert = require('assert');
var Remote = require('..'); var Remote = require('..');
function createAppWithRest() {
var app = loopback();
app.set('host', '127.0.0.1');
app.use(loopback.rest());
return app;
}
function listenAndSetupRemoteDS(test, app, remoteName, cb) {
app.listen(0, function() {
test[remoteName] = loopback.createDataSource({
host: '127.0.0.1',
port: app.get('port'),
connector: Remote,
});
cb();
});
}
describe('RemoteConnector', function() { describe('RemoteConnector', function() {
var remoteApp; var remoteApp;
var remote; var remote;
@ -10,16 +28,8 @@ describe('RemoteConnector', function() {
defineModelTestsWithDataSource({ defineModelTestsWithDataSource({
beforeEach: function(done) { beforeEach: function(done) {
var test = this; var test = this;
remoteApp = loopback(); remoteApp = createAppWithRest();
remoteApp.use(loopback.rest()); listenAndSetupRemoteDS(test, remoteApp, 'dataSource', done);
remoteApp.listen(0, function() {
test.dataSource = loopback.createDataSource({
host: '127.0.0.1',
port: remoteApp.get('port'),
connector: Remote
});
done();
});
}, },
onDefine: function(Model) { onDefine: function(Model) {
var RemoteModel = Model.extend(Model.modelName); var RemoteModel = Model.extend(Model.modelName);
@ -32,21 +42,13 @@ describe('RemoteConnector', function() {
beforeEach(function(done) { beforeEach(function(done) {
var test = this; var test = this;
remoteApp = this.remoteApp = loopback();
remoteApp.use(loopback.rest());
var ServerModel = this.ServerModel = var ServerModel = this.ServerModel =
loopback.PersistedModel.extend('TestModel'); loopback.PersistedModel.extend('TestModel');
remoteApp = test.remoteApp = createAppWithRest();
remoteApp.model(ServerModel); remoteApp.model(ServerModel);
remoteApp.listen(0, function() { listenAndSetupRemoteDS(test, remoteApp, 'remote', done);
test.remote = loopback.createDataSource({
host: '127.0.0.1',
port: remoteApp.get('port'),
connector: Remote
});
done();
});
}); });
it('should support the save method', function(done) { it('should support the save method', function(done) {
@ -87,3 +89,35 @@ describe('RemoteConnector', function() {
}); });
}); });
}); });
describe('Custom Path', function() {
var test = this;
before(function(done) {
var ServerModel = loopback.PersistedModel.extend('TestModel', {}, {
http: {path: '/custom'}
});
server = test.server = createAppWithRest();
server.dataSource('db', {
connector: loopback.Memory,
name: 'db'
});
server.model(ServerModel, {dataSource: 'db'});
listenAndSetupRemoteDS(test, server, 'remote', done);
});
it('should support http.path configuration', function(done) {
var RemoteModel = loopback.PersistedModel.extend('TestModel', {}, {
dataSource: 'remote',
http: {path: '/custom'}
});
RemoteModel.attachTo(test.remote);
RemoteModel.create({}, function(err, instance) {
if (err) return assert(err);
done();
});
});
});