-
Notifications
You must be signed in to change notification settings - Fork 1
Vps 109/add group member from UI #423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rgin216
wants to merge
5
commits into
master
Choose a base branch
from
VPS-109/Add-group-member-from-UI
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6fd3e5
Add group member API endpoint
rgin216 a24a512
Add group member management modal
rgin216 733e7d9
Fix authoring toolbar layout
rgin216 dc8c0f0
Revert "Fix authoring toolbar layout"
rgin216 22738f1
Address group member review feedback
rgin216 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ const groupSchema = new Schema({ | |
| scenarioId: { | ||
| type: String, | ||
| }, | ||
| group: { | ||
| type: String, | ||
| }, | ||
|
Comment on lines
+19
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont quite understand this field and the logic associated with it . what does the "group" of the group actually mean? |
||
| currentFlags: [String], | ||
| stateVariables: [Schema.Types.Mixed], | ||
| stateVersion: { | ||
|
|
@@ -24,6 +27,11 @@ const groupSchema = new Schema({ | |
| }, | ||
| }); | ||
|
|
||
| groupSchema.index( | ||
| { scenarioId: 1, group: 1 }, | ||
| { unique: true, partialFilterExpression: { group: { $exists: true } } } | ||
| ); | ||
|
|
||
| const Group = mongoose.model("Group", groupSchema, "groups"); | ||
|
|
||
| export default Group; | ||
This file contains hidden or 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,195 @@ | ||
| import { | ||
| jest, | ||
| describe, | ||
| beforeAll, | ||
| beforeEach, | ||
| afterEach, | ||
| afterAll, | ||
| it, | ||
| expect, | ||
| } from "@jest/globals"; | ||
|
|
||
| import { MongoMemoryServer } from "mongodb-memory-server"; | ||
| import express from "express"; | ||
| import mongoose from "mongoose"; | ||
| import axios from "axios"; | ||
| import routes from "../../index.js"; | ||
| import Scenario from "../../../db/models/scenario.js"; | ||
| import Group from "../../../db/models/group.js"; | ||
|
|
||
| jest.mock("firebase-admin"); | ||
|
|
||
| describe("Group API tests", () => { | ||
| const HTTP_OK = 200; | ||
| const HTTP_BAD_REQUEST = 400; | ||
|
|
||
| let mongoServer; | ||
| let server; | ||
| let port; | ||
|
|
||
| const scenarioId = new mongoose.mongo.ObjectId("000000000000000000000001"); | ||
|
|
||
| beforeAll(async () => { | ||
| mongoServer = await MongoMemoryServer.create(); | ||
| const uri = mongoServer.getUri(); | ||
|
|
||
| await mongoose.connect(uri); | ||
|
|
||
| const app = express(); | ||
| app.use(express.json()); | ||
| app.use("/", routes); | ||
|
|
||
| server = app.listen(0); | ||
| port = server.address().port; | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await Scenario.create({ | ||
| _id: scenarioId, | ||
| name: "Scenario 1", | ||
| uid: "user1", | ||
| roleList: ["doctor"], | ||
| }); | ||
|
|
||
| await Group.syncIndexes(); | ||
|
|
||
| await Group.create({ | ||
| scenarioId: scenarioId.toString(), | ||
| group: "1", | ||
| users: [ | ||
| { | ||
| email: "alex@example.com", | ||
| name: "Alex", | ||
| role: "Doctor", | ||
| group: "1", | ||
| }, | ||
| ], | ||
| notes: new Map(), | ||
| path: ["scene-a"], | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await mongoose.connection.db.dropDatabase(); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await new Promise((resolve, reject) => { | ||
| server.close((error) => (error ? reject(error) : resolve())); | ||
| server.closeAllConnections?.(); | ||
| }); | ||
| await mongoose.disconnect(); | ||
| await mongoServer.stop(); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| it("adds a member to an existing group without recreating the group", async () => { | ||
| const originalGroup = await Group.findOne({ scenarioId }).lean(); | ||
|
|
||
| const response = await axios.post( | ||
| `http://localhost:${port}/api/group/${scenarioId}/member`, | ||
| { | ||
| email: "sam@example.com", | ||
| name: "Sam", | ||
| role: "Nurse", | ||
| group: "1", | ||
| } | ||
| ); | ||
|
|
||
| expect(response.status).toBe(HTTP_OK); | ||
|
|
||
| const group = await Group.findById(originalGroup._id).lean(); | ||
| expect(group.users).toHaveLength(2); | ||
| expect(group.path).toEqual(["scene-a"]); | ||
| expect(group.users[1]).toMatchObject({ | ||
| email: "sam@example.com", | ||
| name: "Sam", | ||
| role: "Nurse", | ||
| group: "1", | ||
| }); | ||
|
|
||
| const scenario = await Scenario.findById(scenarioId).lean(); | ||
| expect(scenario.roleList).toEqual(["doctor", "nurse"]); | ||
| }); | ||
|
|
||
| it("creates the group when the selected group number does not exist", async () => { | ||
| const response = await axios.post( | ||
| `http://localhost:${port}/api/group/${scenarioId}/member`, | ||
| { | ||
| email: "casey@example.com", | ||
| name: "Casey", | ||
| role: "Observer", | ||
| group: "2", | ||
| } | ||
| ); | ||
|
|
||
| expect(response.status).toBe(HTTP_OK); | ||
|
|
||
| const groups = await Group.find({ scenarioId }).sort({ _id: 1 }).lean(); | ||
| expect(groups).toHaveLength(2); | ||
| const group = groups.find((group) => group.group === "2"); | ||
| expect(group.users).toEqual([ | ||
| expect.objectContaining({ | ||
| email: "casey@example.com", | ||
| name: "Casey", | ||
| role: "Observer", | ||
| group: "2", | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| it("handles concurrent additions to the same new group", async () => { | ||
| await Promise.all([ | ||
| axios.post(`http://localhost:${port}/api/group/${scenarioId}/member`, { | ||
| email: "casey@example.com", | ||
| name: "Casey", | ||
| role: "Observer", | ||
| group: "2", | ||
| }), | ||
| axios.post(`http://localhost:${port}/api/group/${scenarioId}/member`, { | ||
| email: "sam@example.com", | ||
| name: "Sam", | ||
| role: "Nurse", | ||
| group: "2", | ||
| }), | ||
| ]); | ||
|
|
||
| const groups = await Group.find({ scenarioId, group: "2" }).lean(); | ||
| expect(groups).toHaveLength(1); | ||
| expect(groups[0].users).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ email: "casey@example.com" }), | ||
| expect.objectContaining({ email: "sam@example.com" }), | ||
| ]) | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects duplicate emails in the scenario", async () => { | ||
| await expect( | ||
| axios.post(`http://localhost:${port}/api/group/${scenarioId}/member`, { | ||
| email: "alex@example.com", | ||
| name: "Alex 2", | ||
| role: "Nurse", | ||
| group: "1", | ||
| }) | ||
| ).rejects.toMatchObject({ | ||
| response: { | ||
| status: HTTP_BAD_REQUEST, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("rejects duplicate roles in the same group", async () => { | ||
| await expect( | ||
| axios.post(`http://localhost:${port}/api/group/${scenarioId}/member`, { | ||
| email: "sam@example.com", | ||
| name: "Sam", | ||
| role: "doctor", | ||
| group: "1", | ||
| }) | ||
| ).rejects.toMatchObject({ | ||
| response: { | ||
| status: HTTP_BAD_REQUEST, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.