2014-09-06 08:55:16 +00:00
|
|
|
var loopback = require('../');
|
2014-08-28 18:56:43 +00:00
|
|
|
var request = require('supertest');
|
|
|
|
|
|
|
|
describe('remoting coercion', function() {
|
|
|
|
it('should coerce arguments based on the type', function(done) {
|
|
|
|
var called = false;
|
|
|
|
var app = loopback();
|
|
|
|
app.use(loopback.rest());
|
|
|
|
|
2016-04-01 09:14:26 +00:00
|
|
|
var TestModel = app.model('TestModel', { base: 'Model', dataSource: null, public: true });
|
2014-08-28 18:56:43 +00:00
|
|
|
TestModel.test = function(inst, cb) {
|
|
|
|
called = true;
|
|
|
|
assert(inst instanceof TestModel);
|
|
|
|
assert(inst.foo === 'bar');
|
|
|
|
cb();
|
2014-11-21 01:46:21 +00:00
|
|
|
};
|
2014-08-28 18:56:43 +00:00
|
|
|
TestModel.remoteMethod('test', {
|
2016-04-01 09:14:26 +00:00
|
|
|
accepts: { arg: 'inst', type: 'TestModel', http: { source: 'body' }},
|
|
|
|
http: { path: '/test', verb: 'post' },
|
2014-08-28 18:56:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
.post('/TestModels/test')
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.send({
|
2016-04-01 09:14:26 +00:00
|
|
|
foo: 'bar',
|
2014-08-28 18:56:43 +00:00
|
|
|
})
|
|
|
|
.end(function(err) {
|
2014-11-21 02:35:36 +00:00
|
|
|
if (err) return done(err);
|
2014-08-28 18:56:43 +00:00
|
|
|
assert(called);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-11-21 01:46:21 +00:00
|
|
|
});
|