express-json-data
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -62,7 +62,11 @@ 'use strict'; | ||
return res.end(); | ||
return res.status(204).end(); | ||
}).delete('/*', function (req, res) { | ||
if (getData(req.path) === undefined) { | ||
return res.status(404).end(); | ||
} | ||
_fastJsonPatch2.default.apply(data, [{ op: 'remove', path: req.path }]); | ||
return res.end(); | ||
return res.status(204).end(); | ||
}).use(_bodyParser2.default.json({ limit: limit, type: type })).put('/', function (req, res) { | ||
@@ -69,0 +73,0 @@ clearData(); |
{ | ||
"name": "express-json-data", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Express JSON data router", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -15,3 +15,3 @@ import _ from 'lodash'; | ||
} | ||
function clearData() { | ||
@@ -36,8 +36,12 @@ Object.keys(data).forEach(key => delete data[key]); | ||
return res.end(); | ||
return res.status(204).end(); | ||
}) | ||
.delete('/*', (req, res) => { | ||
if (getData(req.path) === undefined) { | ||
return res.status(404).end(); | ||
} | ||
fastJsonPatch.apply(data, [{ op: 'remove', path: req.path }]); | ||
return res.end(); | ||
return res.status(204).end(); | ||
}) | ||
@@ -44,0 +48,0 @@ .use(bodyParser.json({ limit, type })) |
@@ -71,2 +71,5 @@ import nodeMocksHttp from 'node-mocks-http'; | ||
sinon.spy(res, 'status'); | ||
sinon.spy(res, 'end'); | ||
// When | ||
@@ -77,2 +80,5 @@ expressJsonData({ data })(req, res); | ||
expect(data).to.eql({}); | ||
expect(res.status).to.have.been.calledWith(204); | ||
expect(res.end).to.have.been.called; | ||
}); | ||
@@ -82,13 +88,39 @@ }); | ||
context('on DELETE /*', () => { | ||
it('should remove the data item', () => { | ||
// Given | ||
let req = nodeMocksHttp.createRequest({ method: 'DELETE', url: '/testItem' }); | ||
let res = nodeMocksHttp.createResponse(); | ||
context('when the data item exists', () => { | ||
it('should remove the data item', () => { | ||
// Given | ||
let req = nodeMocksHttp.createRequest({ method: 'DELETE', url: '/testItem' }); | ||
let res = nodeMocksHttp.createResponse(); | ||
// When | ||
expressJsonData({ data })(req, res); | ||
sinon.spy(res, 'status'); | ||
sinon.spy(res, 'end'); | ||
// Then | ||
expect(data).to.eql({}); | ||
// When | ||
expressJsonData({ data })(req, res); | ||
// Then | ||
expect(data).to.eql({}); | ||
expect(res.status).to.have.been.calledWith(204); | ||
expect(res.end).to.have.been.called; | ||
}); | ||
}); | ||
context('when the data item does not exist', () => { | ||
it('should respond with HTTP 404 Not Found', () => { | ||
// Given | ||
let req = nodeMocksHttp.createRequest({ method: 'DELETE', url: '/notTestItem' }); | ||
let res = nodeMocksHttp.createResponse(); | ||
sinon.spy(res, 'status'); | ||
sinon.spy(res, 'end'); | ||
// When | ||
expressJsonData({ data })(req, res); | ||
// Then | ||
expect(res.status).to.have.been.calledWith(404); | ||
expect(res.end).to.have.been.called; | ||
}); | ||
}); | ||
}); | ||
@@ -95,0 +127,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33548
385