From 1e7fd696d71b5624ce7f8bec0158b21e60cf06ec Mon Sep 17 00:00:00 2001 From: lambeb <141648830+lambeb@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:33:02 +0100 Subject: [PATCH 1/3] Removed enumeration of ValidUserRoles. These are not retrieved from the server using getRoleList API Call Fixed tests to not use enumeration any longer Updated snapshot --- src/Interfaces/index.ts | 14 ---------- .../UserProfileEdits/ChangeRole.test.tsx | 27 ++++++++++--------- .../users/UserProfileEdits/ChangeRole.tsx | 6 ++--- .../__snapshots__/ChangeRole.test.tsx.snap | 9 +++++-- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/Interfaces/index.ts b/src/Interfaces/index.ts index ba133b8..d174fe1 100644 --- a/src/Interfaces/index.ts +++ b/src/Interfaces/index.ts @@ -49,17 +49,3 @@ export interface BreadcrumbItem { export interface BreadcrumbProps { BreadcrumbList: BreadcrumbItem[] } - -export enum ValidUserRoles { - DST = "DST", - BDSS = "BDSS", - IPSManager = "IPS Manager", - IPSFieldInterviewer = "IPS Field Interviewer", - Editor = "Editor", - EditorManager = "Editor Manager", - TOAppointments = "TO Appointments", - TOManager = "TO Manager", - TOInterviewer = "TO Interviewer", - SEL = "SEL", - WelshSpeaker = "Welsh Speaker", -} \ No newline at end of file diff --git a/src/pages/users/UserProfileEdits/ChangeRole.test.tsx b/src/pages/users/UserProfileEdits/ChangeRole.test.tsx index f2248cc..7f681f8 100644 --- a/src/pages/users/UserProfileEdits/ChangeRole.test.tsx +++ b/src/pages/users/UserProfileEdits/ChangeRole.test.tsx @@ -8,8 +8,8 @@ import "@testing-library/jest-dom"; import ChangeRole from "./ChangeRole"; import { MemoryRouter, useParams } from "react-router-dom"; import { getAllRoles, patchUserRolesAndPermissions } from "../../../api/http"; -import { ValidUserRoles } from "../../../Interfaces"; import userEvent from "@testing-library/user-event"; +import { UserRole } from "blaise-api-node-client"; jest.mock("react-router-dom", () => ({ // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -27,17 +27,18 @@ jest.mock("../../../api/http", () => ({ })); const mockRoles = [ - { name: ValidUserRoles.DST, description: "DST User" }, - { name: ValidUserRoles.BDSS, description: "BDSS User" }, - { name: ValidUserRoles.IPSFieldInterviewer, description: "IPS Field Interviewer User" }, - { name: ValidUserRoles.IPSManager, description: "IPS Manager User" }, - { name: ValidUserRoles.Editor, description: "Editor User" }, - { name: ValidUserRoles.EditorManager, description: "Editor Manager User" }, - { name: ValidUserRoles.TOAppointments, description: "TO Appointments User" }, - { name: ValidUserRoles.TOManager, description: "TO Manager User" }, - { name: ValidUserRoles.TOInterviewer, description: "TO Interviewer User" }, - { name: ValidUserRoles.SEL, description: "SEL User" }, - { name: ValidUserRoles.WelshSpeaker, description: "Welsh Speaker User" } + { name: "DST", description: "DST User" }, + { name: "BDSS", description: "BDSS User" }, + { name: "IPS Manager", description: "IPS Field Interviewer User" }, + { name: "IPS Field Interviewer", description: "IPS Manager User" }, + { name: "IPS Researcher", description: "IPS Researcher User" }, + { name: "Editor", description: "Editor User" }, + { name: "Editor Manager", description: "Editor Manager User" }, + { name: "TO Appointments", description: "TO Appointments User" }, + { name: "TO Manager", description: "TO Manager User" }, + { name: "TO Interviewer", description: "TO Interviewer User" }, + { name: "SEL", description: "SEL User" }, + { name: "Welsh Speaker", description: "Welsh Speaker User" } ]; const mockUserDetails = { @@ -136,4 +137,4 @@ describe("ChangeRole Component (with state management)", () => { expect(await findByText(/Failed to fetch roles list, please try again/i)).toBeVisible(); }); -}); \ No newline at end of file +}); diff --git a/src/pages/users/UserProfileEdits/ChangeRole.tsx b/src/pages/users/UserProfileEdits/ChangeRole.tsx index 193b774..cb41ea8 100644 --- a/src/pages/users/UserProfileEdits/ChangeRole.tsx +++ b/src/pages/users/UserProfileEdits/ChangeRole.tsx @@ -3,7 +3,7 @@ import { ONSButton, ONSErrorPanel, ONSLoadingPanel, ONSPanel } from "blaise-desi import { ChangeEvent, ReactElement, useEffect, useState } from "react"; import { Navigate, useLocation, useParams } from "react-router-dom"; import Breadcrumbs from "../../../Components/Breadcrumbs"; -import { BreadcrumbItem, ValidUserRoles } from "../../../Interfaces"; +import { BreadcrumbItem } from "../../../Interfaces"; import { RedirectWithData, UserRouteParams } from "../../../Interfaces/usersPage"; import { getAllRoles, patchUserRolesAndPermissions } from "../../../api/http"; import { UserRole } from "blaise-api-node-client"; @@ -47,7 +47,7 @@ export default function ChangeRole(): ReactElement { return; } - if (Object.values(ValidUserRoles).includes(role as ValidUserRoles)) { + if (roleList.some((userRole) => userRole.name === role)) { const res = await patchUserRolesAndPermissions(viewedUsername, role); setRedirectWithData({ redirect: true, visible: true, message: res?.message || "", statusType: res?.status === 500 ? "error" : "success" }); } else { @@ -117,4 +117,4 @@ export default function ChangeRole(): ReactElement { } ); -} \ No newline at end of file +} diff --git a/src/pages/users/UserProfileEdits/__snapshots__/ChangeRole.test.tsx.snap b/src/pages/users/UserProfileEdits/__snapshots__/ChangeRole.test.tsx.snap index 92f5bcd..a8cdb2e 100644 --- a/src/pages/users/UserProfileEdits/__snapshots__/ChangeRole.test.tsx.snap +++ b/src/pages/users/UserProfileEdits/__snapshots__/ChangeRole.test.tsx.snap @@ -124,15 +124,20 @@ exports[`ChangeRole Component (with state management) matches the snapshot 1`] = > BDSS +