From dbe06078fba134756ac35ef810fb1bb836d7f9ed Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Thu, 26 Nov 2015 16:17:33 -0500 Subject: [PATCH] Add test for custom http.path configuration. --- test/remote-connector.test.js | 74 +++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/test/remote-connector.test.js b/test/remote-connector.test.js index 4b4c4d6..2eabfd6 100644 --- a/test/remote-connector.test.js +++ b/test/remote-connector.test.js @@ -3,6 +3,24 @@ var defineModelTestsWithDataSource = require('./util/model-tests'); var assert = require('assert'); 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() { var remoteApp; var remote; @@ -10,16 +28,8 @@ describe('RemoteConnector', function() { defineModelTestsWithDataSource({ beforeEach: function(done) { var test = this; - remoteApp = loopback(); - remoteApp.use(loopback.rest()); - remoteApp.listen(0, function() { - test.dataSource = loopback.createDataSource({ - host: '127.0.0.1', - port: remoteApp.get('port'), - connector: Remote - }); - done(); - }); + remoteApp = createAppWithRest(); + listenAndSetupRemoteDS(test, remoteApp, 'dataSource', done); }, onDefine: function(Model) { var RemoteModel = Model.extend(Model.modelName); @@ -32,21 +42,13 @@ describe('RemoteConnector', function() { beforeEach(function(done) { var test = this; - remoteApp = this.remoteApp = loopback(); - remoteApp.use(loopback.rest()); var ServerModel = this.ServerModel = loopback.PersistedModel.extend('TestModel'); + remoteApp = test.remoteApp = createAppWithRest(); remoteApp.model(ServerModel); - remoteApp.listen(0, function() { - test.remote = loopback.createDataSource({ - host: '127.0.0.1', - port: remoteApp.get('port'), - connector: Remote - }); - done(); - }); + listenAndSetupRemoteDS(test, remoteApp, 'remote', 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(); + }); + }); +}); \ No newline at end of file