restful-goose
Advanced tools
Comparing version 1.1.3 to 1.1.5
@@ -44,3 +44,3 @@ var crypto = require('crypto'); | ||
//TODO Figure out how to satisfy JSON API spec for source string | ||
obj.source = error.trace || ''; | ||
obj.source = error.detail; | ||
@@ -47,0 +47,0 @@ return obj; |
@@ -69,3 +69,5 @@ var express = require('express'); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); | ||
/* Mount error-handling middleware to res object */ | ||
@@ -79,2 +81,3 @@ app.use(function(req, res, next) { | ||
app.use(baseURL, mountRouter(router, Model, options)); | ||
return app; | ||
@@ -81,0 +84,0 @@ }; |
@@ -207,3 +207,3 @@ var express = require('express'); | ||
if (!data || !data.attributes) { | ||
return res.__onError(req, res, { name: 'BadRequest', message: 'Request not an object or missing attributes property'}); | ||
return res.__onError(req, res, { name: 'BadRequest', message: 'Request not an object or missing attributes property', detail: { request_body: req.body }}); | ||
} | ||
@@ -210,0 +210,0 @@ |
{ | ||
"name": "restful-goose", | ||
"version": "1.1.3", | ||
"version": "1.1.5", | ||
"description": "Yet another RESTful microservice generator for Mongoose with an emphasis on flexibility", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -79,2 +79,22 @@ var chai = require('chai'); | ||
it('should return a specific object on /tests/:item GET when Content-Type is set to application/vnd.api+json', function(done) { | ||
var item = _.head(items); | ||
chai.request(app) | ||
.get('/tests/' + item._id.toString()) | ||
.set('Content-Type', 'application/vnd.api+json') | ||
.end(function(err, res) { | ||
expect(res.status).to.equal(200); | ||
expect(res).to.be.json; | ||
expect(res.body).to.be.a('object'); | ||
expect(res.body).to.have.property('data'); | ||
expect(res.body.data).to.have.property('attributes'); | ||
expect(res.body.data).to.have.property('id'); | ||
expect(res.body.data).to.have.property('type'); | ||
expect(res.body.data.id).to.equal(item._id.toString()); | ||
expect(res.body.data.attributes.name).to.equal(item.name); | ||
expect(res.body.data.attributes.rank).to.equal(item.rank); | ||
done(); | ||
}); | ||
}); | ||
it('should return a specific object on /tests/:item GET', function(done) { | ||
@@ -81,0 +101,0 @@ var item = _.head(items); |
@@ -59,2 +59,20 @@ var chai = require('chai'); | ||
}); | ||
it('should update an existing item on /tests/:item PATCH and Content-Type is application/vnd.api+json', function(done) { | ||
var item = _.sample(items); | ||
var update = { data: { attributes: { name: faker.name.firstName(), rank: faker.random.number() }}}; | ||
chai.request(app) | ||
.patch('/tests/' + item.id) | ||
.set('Content-Type', 'application/vnd.api+json') | ||
.send(JSON.stringify(update)) | ||
.end(function(err, res) { | ||
expect(res.status).to.equal(200); | ||
expect(res).to.be.json; | ||
expect(res.body).to.be.a('object'); | ||
expect(res.body.data.attributes.name).to.equal(update.data.attributes.name); | ||
expect(res.body.data.attributes.rank).to.equal(update.data.attributes.rank); | ||
expect(res.body.data.id).to.equal(item.id); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -60,2 +60,21 @@ var chai = require('chai'); | ||
it('should create a new item on / POST when Content-Type is set to application/vnd.api+json', function(done) { | ||
var data = { data: { attributes: { name: faker.name.firstName(), rank: faker.random.number() }}}; | ||
chai.request(app) | ||
.post('/tests') | ||
.set('Content-Type', 'application/vnd.api+json') | ||
.send(JSON.stringify(data)) | ||
.end(function(err, res) { | ||
expect(res.status).to.equal(201); | ||
expect(res).to.be.json; | ||
expect(res.body).to.be.a('object'); | ||
expect(res.body).to.have.property('data'); | ||
expect(res.body.data.attributes.name).to.equal(data.data.attributes.name); | ||
expect(res.body.data.attributes.rank).to.equal(data.data.attributes.rank); | ||
expect(res.body.data).to.have.property('id'); | ||
done(); | ||
}); | ||
}); | ||
}); |
53384
1376