Comparing version 1.2.0 to 1.3.0
@@ -5,3 +5,3 @@ { | ||
"description": "A pluggable JSON API server", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"tags": [], | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -8,3 +8,3 @@ module.exports = createServer | ||
, accepts = require('./middleware/accepts') | ||
, contentTypeJson = require('./middleware/content-type-json') | ||
, contentType = require('./middleware/content-type') | ||
, cors = require('./middleware/cors') | ||
@@ -46,3 +46,3 @@ , errorHandler = require('./middleware/error') | ||
.use(accepts) | ||
.use(contentTypeJson) | ||
.use(contentType([ 'application/json', 'text/csv' ])) | ||
@@ -49,0 +49,0 @@ // Set headers to prevent caching |
var request = require('supertest') | ||
, express = require('express') | ||
, middleware = require('../../../middleware/content-type-json') | ||
, middleware = require('../../../middleware/content-type')([ 'application/json', 'application/csv' ]) | ||
describe('middleware/content-type-json integration tests', function () { | ||
describe('middleware/content-type integration tests', function () { | ||
@@ -35,3 +35,4 @@ var app | ||
it('should send a 400 response to a request without json in the "Content-Type" header', function (done) { | ||
it('should send a 400 response to a request without an allowed content-type in the "Content-Type" header' | ||
, function (done) { | ||
request(app) | ||
@@ -43,3 +44,4 @@ .post('/') | ||
it('should send a 200 response to a request with json in the "Content-Type" header', function (done) { | ||
it('should send a 200 response to a request with an allowed content-type in the "Content-Type" header' | ||
, function (done) { | ||
request(app) | ||
@@ -46,0 +48,0 @@ .post('/') |
var assert = require('assert') | ||
, middleware = require('../../../middleware/content-type-json') | ||
, middleware = require('../../../middleware/content-type')([ 'application/json', 'application/csv' ]) | ||
describe('middleware/content-type-json unit tests', function () { | ||
describe('middleware/content-type unit tests', function () { | ||
@@ -37,3 +37,3 @@ it('should pass through on non PUT/POST/PATCH requests', function (done) { | ||
function mockJson(err) { | ||
assert.equal(err.error, 'API only supports application/json content-type') | ||
assert.equal(err.error, 'API requires a content-type') | ||
if (++i === 3) done() | ||
@@ -59,3 +59,3 @@ } | ||
it('should send a 406 response to a request with a "Content-Type" header that is not json', function (done) { | ||
it('should send a 406 response to a request with a "Content-Type" header that is not valid', function (done) { | ||
@@ -65,3 +65,3 @@ var res = { status: mockStatus, json: mockJson } | ||
function mockJson(err) { | ||
assert.equal('API only supports application/json content-type', err.error) | ||
assert.equal('API does not support application/xml content-type', err.error) | ||
done() | ||
@@ -99,2 +99,8 @@ } | ||
it('should be ok with a content-type that is not json', function (done) { | ||
middleware({ method: 'POST', headers: { 'content-type': 'application/csv' } }, {}, function () { | ||
done() | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
31357
810