loopback/test/remoting-coercion.test.js

35 lines
930 B
JavaScript
Raw Normal View History

2014-09-06 08:55:16 +00:00
var loopback = require('../');
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());
var TestModel = app.model('TestModel', {base: 'Model', dataSource: null, public: true});
TestModel.test = function(inst, cb) {
called = true;
assert(inst instanceof TestModel);
assert(inst.foo === 'bar');
cb();
};
TestModel.remoteMethod('test', {
accepts: {arg: 'inst', type: 'TestModel', http: {source: 'body'}},
http: {path: '/test', verb: 'post'}
});
request(app)
.post('/TestModels/test')
.set('Content-Type', 'application/json')
.send({
foo: 'bar'
})
.end(function(err) {
2014-11-21 02:35:36 +00:00
if (err) return done(err);
assert(called);
done();
});
});
});