|
1 | 1 | var request = require('supertest'); |
2 | 2 | var loopback = require('loopback'); |
3 | 3 | var expect = require('chai').expect; |
| 4 | +var query = require('./util/query'); |
4 | 5 | var JSONAPIComponent = require('../'); |
5 | 6 | var app; |
6 | 7 | var Post; |
@@ -38,25 +39,35 @@ describe('loopback json api component create method', function () { |
38 | 39 | .end(done); |
39 | 40 | }); |
40 | 41 | it('POST /models should have the JSON API Content-Type header set on response', function (done) { |
41 | | - //TODO: superagent/supertest breaks when trying to use JSON API Content-Type header |
| 42 | + var data = { |
| 43 | + data: { |
| 44 | + type: 'posts', |
| 45 | + attributes: { |
| 46 | + title: 'my post', |
| 47 | + content: 'my post content' |
| 48 | + } |
| 49 | + } |
| 50 | + }; |
| 51 | + |
| 52 | + var options = { |
| 53 | + headers: { |
| 54 | + 'Accept': 'application/vnd.api+json', |
| 55 | + 'Content-Type': 'application/vnd.api+json' |
| 56 | + } |
| 57 | + }; |
| 58 | + |
| 59 | + //use http module via util to make this post to check headers are working since |
| 60 | + //superagent/supertest breaks when trying to use JSON API Content-Type header |
42 | 61 | //waiting on a fix |
43 | 62 | //see https://github.com/visionmedia/superagent/issues/753 |
44 | | - //using Content-Type: application/json in the mean time. |
45 | | - //Have tested correct header using curl and all is well |
46 | | - // request(app).post('/posts') |
47 | | - // .send({ |
48 | | - // data: { |
49 | | - // type: 'posts', |
50 | | - // attributes: { |
51 | | - // title: 'my post', |
52 | | - // content: 'my post content' |
53 | | - // } |
54 | | - // } |
55 | | - // }) |
56 | | - // .set('Content-Type', 'application/vnd.api+json') |
57 | | - // .expect('Content-Type', 'application/vnd.api+json; charset=utf-8') |
58 | | - // .end(done); |
59 | | - done(); |
| 63 | + query(app).post('/posts', data, options, function (err, res) { |
| 64 | + if (err) console.log(err); |
| 65 | + expect(res.headers['content-type']).to.match(/application\/vnd\.api\+json/); |
| 66 | + expect(res.statusCode).to.equal(201); |
| 67 | + expect(res.body).to.have.all.keys('data'); |
| 68 | + expect(res.body.data).to.have.all.keys('type', 'id', 'links', 'attributes'); |
| 69 | + done(); |
| 70 | + }); |
60 | 71 | }); |
61 | 72 |
|
62 | 73 | it('POST /models should have the Location header set on response', function (done) { |
|
0 commit comments