diff --git a/api.planx.uk/modules/team/controller.test.ts b/api.planx.uk/modules/team/controller.test.ts index a93090d0b1..4ae7b073e9 100644 --- a/api.planx.uk/modules/team/controller.test.ts +++ b/api.planx.uk/modules/team/controller.test.ts @@ -14,105 +14,6 @@ vi.mock("./service", () => ({ const auth = authHeader({ role: "platformAdmin" }); -describe("Adding a user to a team", () => { - it("requires authentication", async () => { - await supertest(app) - .put("/team/council/add-member") - .send({ - userEmail: "newbie@council.gov", - role: "teamViewer", - }) - .expect(401); - }); - - it("requires the 'platformAdmin' role", async () => { - await supertest(app) - .put("/team/council/add-member") - .set(authHeader({ role: "teamEditor" })) - .send({ - userEmail: "newbie@council.gov", - role: "teamViewer", - }) - .expect(403); - }); - - it("validates that userId is required", async () => { - await supertest(app) - .put("/team/council/add-member") - .set(auth) - .send({ - role: "teamViewer", - }) - .expect(400) - .then((res) => { - expect(res.body).toHaveProperty("issues"); - expect(res.body).toHaveProperty("name", "ZodError"); - }); - }); - - it("validates that role is required", async () => { - await supertest(app) - .put("/team/council/add-member") - .set(auth) - .send({ - userEmail: "newbie@council.gov", - }) - .expect(400) - .then((res) => { - expect(res.body).toHaveProperty("issues"); - expect(res.body).toHaveProperty("name", "ZodError"); - }); - }); - - it("validates that role must be an accepted value", async () => { - await supertest(app) - .put("/team/council/add-member") - .set(auth) - .send({ - userEmail: "newbie@council.gov", - role: "pirate", - }) - .expect(400) - .then((res) => { - expect(res.body).toHaveProperty("issues"); - expect(res.body).toHaveProperty("name", "ZodError"); - }); - }); - - it("handles an error thrown in the service", async () => { - mockAddMember.mockRejectedValueOnce("Something went wrong in the service"); - - await supertest(app) - .put("/team/council/add-member") - .set(auth) - .send({ - userEmail: "newbie@council.gov", - role: "teamEditor", - }) - .expect(500) - .then((res) => { - expect(mockAddMember).toHaveBeenCalled(); - expect(res.body).toHaveProperty("error"); - expect(res.body.error).toMatch(/Failed to add member/); - }); - }); - - it("can successfully add a team member", async () => { - await supertest(app) - .put("/team/council/add-member") - .set(auth) - .send({ - userEmail: "newbie@council.gov", - role: "teamEditor", - }) - .expect(200) - .then((res) => { - expect(mockAddMember).toHaveBeenCalled(); - expect(res.body).toHaveProperty("message"); - expect(res.body.message).toMatch(/Successfully added user to team/); - }); - }); -}); describe("Removing a user from a team", () => { it("requires authentication", async () => { await supertest(app) diff --git a/api.planx.uk/modules/team/controller.ts b/api.planx.uk/modules/team/controller.ts index 7447410e45..fee1a83faf 100644 --- a/api.planx.uk/modules/team/controller.ts +++ b/api.planx.uk/modules/team/controller.ts @@ -1,7 +1,7 @@ -import * as Service from "./service.js"; import { z } from "zod"; -import { ValidatedRequestHandler } from "../../shared/middleware/validate.js"; import { ServerError } from "../../errors/index.js"; +import { ValidatedRequestHandler } from "../../shared/middleware/validate.js"; +import * as Service from "./service.js"; interface TeamMemberResponse { message: string; @@ -36,23 +36,6 @@ export type RemoveMember = ValidatedRequestHandler< TeamMemberResponse >; -export const addMember: UpsertMember = async (_req, res, next) => { - const { teamSlug } = res.locals.parsedReq.params; - const { userEmail, role } = res.locals.parsedReq.body; - - try { - await Service.addMember({ userEmail, teamSlug, role }); - return res.send({ message: "Successfully added user to team" }); - } catch (error) { - return next( - new ServerError({ - message: `Failed to add member ${userEmail} to team ${teamSlug}. Error: ${error}`, - cause: error, - }), - ); - } -}; - export const changeMemberRole: UpsertMember = async (_req, res, next) => { const { teamSlug } = res.locals.parsedReq.params; const { userEmail, role } = res.locals.parsedReq.body; diff --git a/api.planx.uk/modules/team/docs.yaml b/api.planx.uk/modules/team/docs.yaml index 7f692c12b5..a5cec2183f 100644 --- a/api.planx.uk/modules/team/docs.yaml +++ b/api.planx.uk/modules/team/docs.yaml @@ -23,26 +23,6 @@ components: type: string enum: ["teamViewer", "teamEditor"] paths: - /team/{teamSlug}/add-member: - put: - summary: Add user to team, and assign them a role - description: "Requires authentication via a Cloudflare WARP client - \n\n - Please login at [https://api.editor.planx.uk/team](https://api.editor.planx.uk/team)" - tags: ["team"] - parameters: - - $ref: "#/components/parameters/teamSlug" - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/UpsertMember" - responses: - "200": - $ref: "#/components/responses/SuccessMessage" - "500": - $ref: "#/components/responses/ErrorMessage" /team/{teamSlug}/change-member-role: patch: summary: Change role of an existing team member diff --git a/api.planx.uk/modules/team/routes.ts b/api.planx.uk/modules/team/routes.ts index e9e112edf7..bd6b8e30aa 100644 --- a/api.planx.uk/modules/team/routes.ts +++ b/api.planx.uk/modules/team/routes.ts @@ -6,11 +6,6 @@ import { validate } from "../../shared/middleware/validate.js"; const router = Router(); router.use("/team/", AuthMiddleware.usePlatformAdminAuth); -router.put( - "/team/:teamSlug/add-member", - validate(Controller.upsertMemberSchema), - Controller.addMember, -); router.patch( "/team/:teamSlug/change-member-role", validate(Controller.upsertMemberSchema),