|
| 1 | +var request = require('supertest'); |
| 2 | +var loopback = require('loopback'); |
| 3 | +var expect = require('chai').expect; |
| 4 | +var JSONAPIComponent = require('../'); |
| 5 | +var app, Post; |
| 6 | + |
| 7 | +describe('loopback json api remote methods', function () { |
| 8 | + beforeEach(function () { |
| 9 | + app = loopback(); |
| 10 | + app.set('legacyExplorer', false); |
| 11 | + var ds = loopback.createDataSource('memory'); |
| 12 | + Post = ds.createModel('post', { |
| 13 | + id: {type: Number, id: true}, |
| 14 | + title: String, |
| 15 | + content: String |
| 16 | + }); |
| 17 | + Post.greet = function (msg, cb) { |
| 18 | + cb(null, 'Greetings... ' + msg); |
| 19 | + }; |
| 20 | + Post.remoteMethod( |
| 21 | + 'greet', |
| 22 | + { |
| 23 | + accepts: {arg: 'msg', type: 'string'}, |
| 24 | + returns: {arg: 'greeting', type: 'string'} |
| 25 | + } |
| 26 | + ); |
| 27 | + app.model(Post); |
| 28 | + app.use(loopback.rest()); |
| 29 | + JSONAPIComponent(app); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('status codes', function () { |
| 33 | + it('POST /models should return a 201 CREATED status code', function (done) { |
| 34 | + request(app).post('/posts') |
| 35 | + .send({'msg': 'John'}) |
| 36 | + .set('Content-Type', 'application/json') |
| 37 | + .expect(201) |
| 38 | + .end(function (err, res) { |
| 39 | + expect(err).to.equal(null); |
| 40 | + expect(res.body).to.equal('Greetings... John!'); |
| 41 | + done(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
0 commit comments