Skip to content

Commit

Permalink
feat: Move healthcheck to misc module
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 19, 2023
1 parent 7a49fb4 commit db5506b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 36 deletions.
4 changes: 3 additions & 1 deletion api.planx.uk/modules/misc/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ export const getLoggedInUserDetails: RequestHandler = async (_req, res, next) =>
} catch (error) {
next(error)
}
};
};

export const healthCheck: RequestHandler = (_req, res) => res.json({ hello: "world" });
18 changes: 18 additions & 0 deletions api.planx.uk/modules/misc/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ tags:
- name: misc
description: Miscellaneous
paths:
/:
get:
summary: Health check
description: Confirms the API is healthy
tags:
- misc
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
hello:
type: string
example:
hello: world
/me:
get:
summary: Get information about currently logged in user
Expand Down
9 changes: 9 additions & 0 deletions api.planx.uk/modules/misc/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ describe("/me endpoint", () => {
});
});
});

describe("healthcheck endpoint", () => {
it("always returns a 200", async () => {
await supertest(app)
.get("/")
.expect(200)
.then(res => expect(res.body).toHaveProperty("hello", "world"))
});
});
3 changes: 2 additions & 1 deletion api.planx.uk/modules/misc/routes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Router } from "express";
import { useLoginAuth } from "../auth/middleware";
import { getLoggedInUserDetails } from "./controller";
import { getLoggedInUserDetails, healthCheck } from "./controller";

const router = Router();

router.get("/", healthCheck);
router.get("/me", useLoginAuth, getLoggedInUserDetails);

export default router;
9 changes: 0 additions & 9 deletions api.planx.uk/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ import supertest from "supertest";
import { queryMock } from "./tests/graphqlQueryMock";
import app from "./server";

it("works", async () => {
await supertest(app)
.get("/")
.expect(200)
.then((response) => {
expect(response.body).toEqual({ hello: "world" });
});
});

it("mocks hasura", async () => {
queryMock.mockQuery({
name: "GetTeams",
Expand Down
25 changes: 0 additions & 25 deletions api.planx.uk/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,31 +224,6 @@ app.get("/gis/:localAuthority", locationSearch);

app.get("/roads", classifiedRoadsSearch);

/**
* @swagger
* /:
* get:
* summary: Health check
* description: Confirms the API is healthy
* tags:
* - misc
* responses:
* '200':
* description: OK
* content:
* application/json:
* schema:
* type: object
* properties:
* hello:
* type: string
* example:
* hello: world
*/
app.get("/", (_req, res) => {
res.json({ hello: "world" });
});

app.use("/admin", usePlatformAdminAuth);
app.get("/admin/feedback", downloadFeedbackCSV);
app.get("/admin/session/:sessionId/xml", getOneAppXML);
Expand Down

0 comments on commit db5506b

Please sign in to comment.