-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding a new user in the demo team automatically asigns the `de…
…moUser` role
- Loading branch information
1 parent
18ac5a9
commit 4332d5f
Showing
8 changed files
with
91 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ import { | |
optimisticallyUpdateExistingMember, | ||
} from "./lib/optimisticallyUpdateMembersTable"; | ||
|
||
export const DEMO_TEAM_ID = 32; | ||
|
||
export const EditorUpsertModal = ({ | ||
setShowModal, | ||
showModal, | ||
|
@@ -34,6 +36,8 @@ export const EditorUpsertModal = ({ | |
}: EditorModalProps) => { | ||
const [showUserAlreadyExistsError, setShowUserAlreadyExistsError] = | ||
useState<boolean>(false); | ||
const [ teamId, teamSlug ] = useStore(state => [state.teamId, state.teamSlug]) | ||
Check failure on line 39 in editor.planx.uk/src/pages/FlowEditor/components/Team/components/EditorUpsertModal.tsx GitHub Actions / Run React Testssrc/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.test.tsx > when the addNewEditor modal is rendered > should not have any accessibility issues
|
||
const isDemoTeam = teamId === DEMO_TEAM_ID; | ||
|
||
const toast = useToast(); | ||
|
||
|
@@ -56,15 +60,11 @@ export const EditorUpsertModal = ({ | |
}; | ||
|
||
const handleSubmitToAddNewUser = async () => { | ||
const { teamId, teamSlug } = useStore.getState(); | ||
|
||
const createUserResult = await createAndAddUserToTeam( | ||
formik.values.email, | ||
formik.values.firstName, | ||
formik.values.lastName, | ||
const createUserResult = await createAndAddUserToTeam({ | ||
newUser: formik.values, | ||
teamId, | ||
teamSlug, | ||
).catch((err) => { | ||
}).catch((err) => { | ||
if (isUserAlreadyExistsError(err.message)) { | ||
setShowUserAlreadyExistsError(true); | ||
} | ||
|
@@ -114,6 +114,8 @@ export const EditorUpsertModal = ({ | |
firstName: initialValues?.firstName || "", | ||
lastName: initialValues?.lastName || "", | ||
email: initialValues?.email || "", | ||
// Users within the Demo team are granted a role with a restricted permission set | ||
role: isDemoTeam ? "demoUser" : "teamEditor", | ||
}, | ||
validationSchema: upsertEditorSchema, | ||
onSubmit: handleSubmit, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
....uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.demoTeam.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { waitFor, within } from "@testing-library/react"; | ||
import { useStore } from "pages/FlowEditor/lib/store"; | ||
import { vi } from "vitest"; | ||
|
||
import { DEMO_TEAM_ID } from "../components/EditorUpsertModal"; | ||
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen"; | ||
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor"; | ||
import { mockTeamMembersData } from "./mocks/mockTeamMembersData"; | ||
import { mockPlatformAdminUser } from "./mocks/mockUsers"; | ||
|
||
const { setState, getState } = useStore; | ||
|
||
vi.mock( | ||
"pages/FlowEditor/components/Team/queries/createAndAddUserToTeam.tsx", | ||
async () => ({ | ||
createAndAddUserToTeam: vi.fn().mockResolvedValue({ | ||
id: 1, | ||
__typename: "users", | ||
}), | ||
}) | ||
); | ||
|
||
describe("adding a new user to the Demo team", () => { | ||
beforeEach(async () => { | ||
setState({ | ||
user: mockPlatformAdminUser, | ||
teamMembers: mockTeamMembersData, | ||
teamId: DEMO_TEAM_ID, | ||
}); | ||
}); | ||
|
||
it("assigns the `demoUser` role automatically", async () => { | ||
let currentUsers = getState().teamMembers | ||
expect(currentUsers).toHaveLength(3); | ||
|
||
const { user, getByTestId } = await setupTeamMembersScreen(); | ||
await userTriesToAddNewEditor(user); | ||
|
||
const membersTable = getByTestId("members-table-add-editor"); | ||
|
||
await waitFor(() => { | ||
expect( | ||
within(membersTable).getByText(/Mickey Mouse/), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
currentUsers = getState().teamMembers | ||
expect(currentUsers).toHaveLength(4); | ||
|
||
// Role correctly assigned to user | ||
const newUser = getState().teamMembers[3]; | ||
expect(newUser.role).toBe("demoUser"); | ||
|
||
// Use role tag displayed in table | ||
expect(within(membersTable).getByText("demoUser")).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters