diff --git a/api.planx.uk/modules/misc/controller.ts b/api.planx.uk/modules/misc/controller.ts index 8090efb5d3..ae3ac6094c 100644 --- a/api.planx.uk/modules/misc/controller.ts +++ b/api.planx.uk/modules/misc/controller.ts @@ -17,4 +17,6 @@ export const getLoggedInUserDetails: RequestHandler = async (_req, res, next) => } catch (error) { next(error) } -}; \ No newline at end of file +}; + +export const healthCheck: RequestHandler = (_req, res) => res.json({ hello: "world" }); \ No newline at end of file diff --git a/api.planx.uk/modules/misc/docs.yaml b/api.planx.uk/modules/misc/docs.yaml index 452955b95c..7422e8fef3 100644 --- a/api.planx.uk/modules/misc/docs.yaml +++ b/api.planx.uk/modules/misc/docs.yaml @@ -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 diff --git a/api.planx.uk/modules/misc/routes.test.ts b/api.planx.uk/modules/misc/routes.test.ts index 0fa5be05f7..3fb675d0e5 100644 --- a/api.planx.uk/modules/misc/routes.test.ts +++ b/api.planx.uk/modules/misc/routes.test.ts @@ -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")) + }); +}); \ No newline at end of file diff --git a/api.planx.uk/modules/misc/routes.ts b/api.planx.uk/modules/misc/routes.ts index 89962da319..0b0d9cb6f4 100644 --- a/api.planx.uk/modules/misc/routes.ts +++ b/api.planx.uk/modules/misc/routes.ts @@ -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; \ No newline at end of file diff --git a/api.planx.uk/server.test.js b/api.planx.uk/server.test.js index 125375c05e..7428f7baef 100644 --- a/api.planx.uk/server.test.js +++ b/api.planx.uk/server.test.js @@ -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", diff --git a/api.planx.uk/server.ts b/api.planx.uk/server.ts index e548140a98..8b1a3bb5fb 100644 --- a/api.planx.uk/server.ts +++ b/api.planx.uk/server.ts @@ -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);