New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hmcts/nodejs-healthcheck

Package Overview
Dependencies
Maintainers
11
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hmcts/nodejs-healthcheck - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

healthcheck/versionFile.js

57

healthcheck/routes.js
'use strict'
const checks = require('./checks'),
outputs = require('./outputs');
outputs = require('./outputs'),
versionFile = require('./versionFile');
function getBuildInfo(extra) {
let buildInfo = {
environment: process.env.PACKAGES_ENVIRONMENT || "unknown",
project: process.env.PACKAGES_PROJECT || "unknown",
name: process.env.PACKAGES_NAME || "unknown",
version: process.env.PACKAGES_VERSION || "unknown",
};
if (extra) {
buildInfo.extra = extra;
}
return buildInfo;
return Promise.all([
versionFile.commit(),
versionFile.date()
]).then(([commit, date]) => {
let buildInfo = {
environment: process.env.PACKAGES_ENVIRONMENT || "unknown",
project: process.env.PACKAGES_PROJECT || "unknown",
name: process.env.PACKAGES_NAME || "unknown",
version: process.env.PACKAGES_VERSION || "unknown",
commit,
date
};
if (extra) {
return Object.assign(buildInfo, { extra });
} else {
return buildInfo;
}
});
}

@@ -22,15 +31,15 @@

return (req, res) => {
check.call().then(results => {
const allOk = Object.values(results)
.every(result => result.status === outputs.UP);
const output = Object.assign(
outputs.status(allOk),
results,
{
buildInfo: getBuildInfo(config.buildInfo)
}
);
const status = allOk ? 200 : 500;
res.status(status).json(output);
});
return Promise
.all([check.call(), getBuildInfo(config.buildInfo)])
.then(([results, buildInfo]) => {
const allOk = Object.values(results)
.every(result => result.status === outputs.UP);
const output = Object.assign(
outputs.status(allOk),
results,
{ buildInfo }
);
const status = allOk ? 200 : 500;
res.status(status).json(output);
});
}

@@ -37,0 +46,0 @@ }

{
"name": "@hmcts/nodejs-healthcheck",
"version": "1.4.0",
"version": "1.4.1",
"description": "Healthcheck endpoint for Reform nodejs applications",

@@ -16,2 +16,4 @@ "main": "index.js",

"dependencies": {
"fs-extra": "^3.0.1",
"js-yaml": "^3.8.4",
"superagent": "^3.5.1"

@@ -21,7 +23,9 @@ },

"chai": "^3.5.0",
"chai-as-promised": "^7.1.1",
"mocha": "^3.4.2",
"sinon": "^1.17.7",
"sinon-chai": "^2.10.0",
"nock": "^9.0.0"
"nock": "^9.0.0",
"proxyquire": "^1.8.0",
"sinon": "^2.3.6",
"sinon-chai": "^2.10.0"
}
}
const chai = require('chai');
const chaiAsPromised = require("chai-as-promised");
const expect = chai.expect;

@@ -7,2 +8,3 @@ const sinon = require('sinon');

chai.use(sinonChai);
chai.use(chaiAsPromised);

@@ -9,0 +11,0 @@ module.exports = {

@@ -8,2 +8,3 @@ 'use strict'

outputs = require('../../healthcheck/outputs'),
versionFile = require('../../healthcheck/versionFile'),
nock = require('nock');

@@ -20,2 +21,6 @@

beforeEach(() => {
sinon.stub(versionFile, 'commit');
sinon.stub(versionFile, 'date');
versionFile.commit.resolves('abc1234');
versionFile.date.resolves('Jan 1 1970');
envKeys.forEach(key => {

@@ -28,2 +33,4 @@ originalEnv[key] = process.env[key];

afterEach(() => {
versionFile.commit.restore();
versionFile.date.restore();
envKeys.forEach(key => {

@@ -42,3 +49,3 @@ if (typeof originalEnv[key] === "undefined") {

it('should add build info from environment', () => {
expect(routes.getBuildInfo()).to.eql({
return expect(routes.getBuildInfo()).to.eventually.eql({
environment: "test PACKAGES_ENVIRONMENT",

@@ -48,2 +55,4 @@ project: "test PACKAGES_PROJECT",

version: "test PACKAGES_VERSION",
commit: 'abc1234',
date: 'Jan 1 1970'
});

@@ -53,5 +62,4 @@ });

it('should include extra build info', () => {
expect(routes.getBuildInfo({"foo": "bar"}).extra).to.eql({
"foo": "bar"
});
const extra = routes.getBuildInfo({ foo: "bar" }).then(_ => _.extra);
return expect(extra).to.eventually.eql({ foo: "bar" });
});

@@ -63,3 +71,3 @@

let makeCheck = isOk => checks.RawCheck.create(() => isOk ? outputs.up() : outputs.down());
let makeReqRes = (done, expectedStatus, expectedJson) => {
let makeReqRes = (expectedStatus, expectedJson) => {
let req = sinon.spy(),

@@ -73,3 +81,2 @@ res = {};

expect(json).to.eql(expectedJson);
done();
return res;

@@ -80,3 +87,3 @@ };

it('should return 200 OK if all checks pass', (done) => {
it('should return 200 OK if all checks pass', () => {
let route = routes.configure({

@@ -88,3 +95,3 @@ checks: {

});
let [req, res] = makeReqRes(done, 200, {
let [req, res] = makeReqRes(200, {
status: outputs.UP,

@@ -98,9 +105,11 @@ check1: {status: "UP"},

version: "test PACKAGES_VERSION",
commit: 'abc1234',
date: 'Jan 1 1970'
}
});
route(req, res);
return route(req, res);
});
it('should return 500 DOWN if any checks fail', (done) => {
it('should return 500 DOWN if any checks fail', () => {
let route = routes.configure({

@@ -112,3 +121,3 @@ checks: {

});
let [req, res] = makeReqRes(done, 500, {
let [req, res] = makeReqRes(500, {
status: "DOWN",

@@ -122,10 +131,12 @@ check1: {status: "DOWN"},

version: "test PACKAGES_VERSION",
commit: 'abc1234',
date: 'Jan 1 1970'
}
});
route(req, res);
return route(req, res);
});
it('should return the extra build info', (done) => {
it('should return the extra build info', () => {
let route = routes.configure({

@@ -139,3 +150,3 @@ checks: {

});
let [req, res] = makeReqRes(done, 200, {
let [req, res] = makeReqRes(200, {
status: "UP",

@@ -148,2 +159,4 @@ check1: {status: "UP"},

version: "test PACKAGES_VERSION",
commit: 'abc1234',
date: 'Jan 1 1970',
extra: {

@@ -155,3 +168,3 @@ foo: "bar"

route(req, res);
return route(req, res);
});

@@ -158,0 +171,0 @@

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