Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-json-data

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-json-data - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

8

lib/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc