Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #924 from Fdawgs/chore/tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Dec 2, 2023
2 parents f8d01b8 + c8985f0 commit 0533046
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 101 deletions.
11 changes: 2 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
"plugin:promise/recommended",
"plugin:regexp/recommended",
"plugin:security/recommended",
"plugin:security-node/recommended",
"prettier",
],
overrides: [
Expand Down Expand Up @@ -40,14 +39,7 @@ module.exports = {
// Explicitly tell ESLint to parse JavaScript as CommonJS, as airbnb-base sets this to "modules" for ECMAScript
sourceType: "script",
},
plugins: [
"import",
"jsdoc",
"promise",
"regexp",
"security",
"security-node",
],
plugins: ["import", "jsdoc", "promise", "regexp", "security"],
root: true,
rules: {
"@eslint-community/eslint-comments/disable-enable-pair": "off",
Expand All @@ -57,6 +49,7 @@ module.exports = {
"jsdoc/check-syntax": "error",
"jsdoc/require-hyphen-before-param-description": "error",
"no-multiple-empty-lines": ["error", { max: 1 }],
"no-param-reassign": ["error", { props: false }],
"prefer-destructuring": ["error", { object: true, array: false }],
"promise/prefer-await-to-callbacks": "warn",
"promise/prefer-await-to-then": "warn",
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-alpine
FROM node:20-alpine

# Workdir
WORKDIR /usr/app
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
> **Note**
> As of 2023-05-03 I am no longer employed by Somerset NHS Foundation Trust.
> However, this repository will continue to be maintained as it acts as
> a 'canary in the coalmine' for changes to Node and other dependencies.
> This repository is unmaintained as of 2023-05-03 as
> I am no longer employed by Somerset NHS Foundation Trust.
<a href="https://somersetft.nhs.uk/yeovilhospital/">
<img alttext="Somerset NHSFT logo" src="https://raw.githubusercontent.com/Fdawgs/yh-community-contacts-api/main/docs/images/somerset-nhsft-logo-left-aligned-transparent-background.png" width="480" />
Expand Down
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"db:migrate": "node src/migrate.js",
"jest": "jest",
"jest:coverage": "jest --coverage",
"lint": "eslint . --cache --ext js,jsx,ts,tsx --ignore-path .gitignore",
"lint": "eslint . --cache --ext js,jsx --ignore-path .gitignore",
"lint:licenses": "node scripts/license-checker.js",
"lint:lockfile": "lockfile-lint -p package-lock.json -t npm -a npm -s -i",
"lint:prettier": "prettier . -c -u",
"lint:prettier:fix": "prettier . -w -u",
"prepare": "husky install",
"prepare": "husky install && npx playwright install firefox --with-deps",
"start": "node .",
"start:dev": "nodemon src/app.js | pino-pretty",
"test": "npm run lint && npm run jest",
Expand Down Expand Up @@ -91,7 +91,6 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-regexp": "^2.1.1",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-security-node": "^1.1.1",
"glob": "^10.3.10",
"husky": "^8.0.3",
"jest": "^29.7.0",
Expand Down
13 changes: 6 additions & 7 deletions src/plugins/clean-object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ async function plugin(server) {
* @returns {object} cleaned object.
*/
function cleanObject(object = {}) {
const obj = object;
Object.keys(obj).forEach((key) => {
if (obj[key] && typeof obj[key] === "object") {
cleanObject(obj[key]);
} else if (obj[key] === null || obj[key] === undefined) {
delete obj[key];
Object.keys(object).forEach((key) => {
if (object[key] && typeof object[key] === "object") {
cleanObject(object[key]);
} else if (object[key] === null || object[key] === undefined) {
delete object[key];
}
});
return obj;
return object;
}

server.decorate("cleanObject", cleanObject);
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/clean-object/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ describe("Clean-Object plugin", () => {
await server.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

it("Recursively removes keys from request object where value is undefined or null", async () => {
const response = await server.inject({
Expand Down
36 changes: 13 additions & 23 deletions src/plugins/convert-date-param-operator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

const fp = require("fastify-plugin");

const operatorMap = {
ap: "=",
eb: "<",
eq: "=",
ge: ">=",
gt: ">",
le: "<=",
lt: "<",
ne: "!=",
sa: ">",
};

/**
* @author Frazer Smith
* @description Plugin that decorates Fastify instance with `convertDateParamOperator` function,
Expand All @@ -11,34 +23,12 @@ const fp = require("fastify-plugin");
async function plugin(server) {
/**
* @author Frazer Smith
* @author NextGen Healthcare
* @description Converts date param operator to corresponding value.
* @param {string} operator - Date param operator, in any letter case.
* @returns {string} converted date param operator.
*/
function convDateParamOperator(operator) {
switch (operator.toLowerCase()) {
case "ap":
return "=";
case "eb":
return "<";
case "eq":
return "=";
case "ge":
return ">=";
case "gt":
return ">";
case "le":
return "<=";
case "lt":
return "<";
case "ne":
return "!=";
case "sa":
return ">";
default:
return "=";
}
return operatorMap[operator.toLowerCase()] || "=";
}

server.decorate("convertDateParamOperator", convDateParamOperator);
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/convert-date-param-operator/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ describe("Convert-Date-Param-Operator plugin", () => {
await server.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

it("Converts date param operators to expected value", async () => {
const values = {
Expand Down
8 changes: 2 additions & 6 deletions src/plugins/db/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ describe("DB plugin", () => {
await server.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

it("Returns 'test' string", async () => {
const response = await server.inject({
Expand Down Expand Up @@ -88,9 +86,7 @@ describe("DB plugin", () => {
await server.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

it("Returns 'test' string", async () => {
const response = await server.inject({
Expand Down
4 changes: 1 addition & 3 deletions src/routes/admin/access/bearer-token/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ describe("Access route", () => {
.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

describe("/:id DELETE requests", () => {
it("Deletes a bearer token record", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/routes/admin/healthcheck/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ describe("Healthcheck route", () => {
.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

it("Returns `ok`", async () => {
const response = await server.inject({
Expand Down
8 changes: 2 additions & 6 deletions src/routes/contact/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ describe("Contact route", () => {
.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

describe("/:id DELETE requests", () => {
it("Deletes a contact record", async () => {
Expand Down Expand Up @@ -875,9 +873,7 @@ describe("Contact route", () => {
.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

describe("/:id DELETE requests", () => {
it("Returns HTTP status code 401 if not in permitted access", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/routes/docs/openapi/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ describe("OpenAPI route", () => {
.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

it("Returns OpenAPI definitions", async () => {
const response = await server.inject({
Expand Down
4 changes: 1 addition & 3 deletions src/routes/docs/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ describe("Docs route", () => {
.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

it("Returns HTML", async () => {
const response = await server.inject({
Expand Down
20 changes: 5 additions & 15 deletions src/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ describe("Server deployment", () => {
await server.register(startServer, config).ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

describe("/admin/healthcheck route", () => {
it("Returns `ok`", async () => {
Expand Down Expand Up @@ -388,9 +386,7 @@ describe("Server deployment", () => {
await server.register(startServer, config).ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

describe("/admin/healthcheck route", () => {
it("Returns `ok`", async () => {
Expand Down Expand Up @@ -578,9 +574,7 @@ describe("Server deployment", () => {
await server.register(startServer, config).ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

describe("/admin/access/bearer-token/:id route", () => {
/** @todo use `it.concurrent.each()` once it is no longer experimental */
Expand Down Expand Up @@ -958,9 +952,7 @@ describe("Server deployment", () => {
await server.register(startServer, config).listen(config.fastify);
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

describe("Content", () => {
describe("/docs route", () => {
Expand Down Expand Up @@ -1049,9 +1041,7 @@ describe("Server deployment", () => {
await server.ready();
});

afterAll(async () => {
await server.close();
});
afterAll(async () => server.close());

describe("/error route", () => {
it("Returns HTTP status code 500", async () => {
Expand Down

0 comments on commit 0533046

Please sign in to comment.