forked from strongloop/loopback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoting-coercion.test.js
46 lines (39 loc) · 1.16 KB
/
remoting-coercion.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
// Node module: loopback
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
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.registry.createModel('TestModel',
{},
{ base: 'Model' }
);
app.model(TestModel, { 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) {
if (err) return done(err);
assert(called);
done();
});
});
});