generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 97
Create routes and methods for updating User and Project 'ManagedBy' fields #1988
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
Merged
jng34
merged 10 commits into
hackforla:development
from
jng34:updateManagedFieldsUserAndProj
Sep 23, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
602ee55
first commit
jng34 248a76d
create new routes and controller methods to update user & proj manage…
jng34 642adf6
add unit testing for functions
jng34 5567531
Merge branch 'development' into updateManagedFieldsUserAndProj
jng34 bf6d38a
add and update unit testing for user router
jng34 ae699d1
remove duplicate test and update projectController fn
jng34 51e7cc5
Merge branch 'development' into updateManagedFieldsUserAndProj
jng34 f4bef46
Merge branch 'development' into updateManagedFieldsUserAndProj
JackHaeg 432ed7e
remove comment from userapiservice
jng34 ba43a33
Merge remote-tracking branch 'refs/remotes/origin/updateManagedFields…
jng34 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
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 |
|---|---|---|
|
|
@@ -158,7 +158,7 @@ describe('Unit testing for Projects router', () => { | |
|
|
||
| // Tests | ||
| expect(ProjectController.create).toHaveBeenCalledWith( | ||
| expect.objectContaining({ body: newProject }), // Check if newProject in body is parsed | ||
| expect.objectContaining({ body: newProject }), // Check if newProject in body is parsed | ||
| expect.anything(), // Mock response | ||
| expect.anything(), // Mock next | ||
| ); | ||
|
|
@@ -234,7 +234,7 @@ describe('Unit testing for Projects router', () => { | |
| }); | ||
|
|
||
| const updatedProject = { | ||
| id: '1', | ||
| id: 'projectId1', | ||
| name: 'updated project1', | ||
| description: 'updated testing', | ||
| githubIdentifier: 'gitHubTest3', | ||
|
|
@@ -251,7 +251,7 @@ describe('Unit testing for Projects router', () => { | |
| lookingDescription: 'n/a', | ||
| recruitingCategories: ['n/a'], | ||
| partners: ['n/a'], | ||
| managedByUsers: ['n/a'], | ||
| managedByUsers: ['userId1'], | ||
| }; | ||
|
|
||
| const ProjectId = updatedProject.id; | ||
|
|
@@ -274,7 +274,7 @@ describe('Unit testing for Projects router', () => { | |
|
|
||
| // Tests | ||
| expect(ProjectController.update).toHaveBeenCalledWith( | ||
| expect.objectContaining({ params: { ProjectId }}), // Check if ProjectId is parsed from params | ||
| expect.objectContaining({ params: { ProjectId } }), // Check if ProjectId is parsed from params | ||
| expect.anything(), // Mock response | ||
| expect.anything(), // Mock next | ||
| ); | ||
|
|
@@ -284,5 +284,85 @@ describe('Unit testing for Projects router', () => { | |
| // Marks completion of tests | ||
| done(); | ||
| }); | ||
|
|
||
| const updatedUser = { | ||
| id: 'userId1', | ||
| name: 'Updated User', | ||
| email: '[email protected]', | ||
| managedProjects: ['projectId1'], | ||
| }; | ||
|
|
||
| const userId = updatedUser.id; | ||
|
|
||
| it("should add to the project's managedByUsers and the user's managedProjects fields with PATCH /api/projects/:ProjectId", async (done) => { | ||
| // Mock ProjectController.updateManagedByUsers method when this route is called | ||
| ProjectController.updateManagedByUsers.mockImplementationOnce((req, res) => { | ||
| res.status(200).send({ project: updatedProject, user: updatedUser }); | ||
| }); | ||
|
|
||
| // Mock PUT API call | ||
| const response = await request | ||
| .patch(`/api/projects/${ProjectId}`) | ||
| .send({ action: 'add', userId }); | ||
|
|
||
| // Middlware assertions | ||
| expect(mockVerifyCookie).toHaveBeenCalledWith( | ||
| expect.any(Object), | ||
| expect.any(Object), | ||
| expect.any(Function), | ||
| ); | ||
|
|
||
| // Tests | ||
| expect(ProjectController.updateManagedByUsers).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| params: { ProjectId }, | ||
| body: { action: 'add', userId }, | ||
| }), // Check if ProjectId is parsed from params | ||
| expect.anything(), // Mock response | ||
| expect.anything(), // Mock next | ||
| ); | ||
| expect(response.status).toBe(200); | ||
| expect(response.body).toEqual({ project: updatedProject, user: updatedUser }); | ||
|
|
||
| // Marks completion of tests | ||
| done(); | ||
| }); | ||
|
|
||
| it("should remove user from the project's managedByUsers and remove project from the user's managedProjects fields with PATCH /api/projects/:ProjectId", async (done) => { | ||
| updatedProject.managedByUsers = []; | ||
| updatedUser.managedProjects = []; | ||
|
|
||
| // Mock ProjectController.updateManagedByUsers method when this route is called | ||
| ProjectController.updateManagedByUsers.mockImplementationOnce((req, res) => { | ||
| res.status(200).send({ project: updatedProject, user: updatedUser }); | ||
| }); | ||
|
|
||
| // Mock PUT API call | ||
| const response = await request | ||
| .patch(`/api/projects/${ProjectId}`) | ||
| .send({ action: 'remove', userId }); | ||
|
|
||
| // Middlware assertions | ||
| expect(mockVerifyCookie).toHaveBeenCalledWith( | ||
| expect.any(Object), | ||
| expect.any(Object), | ||
| expect.any(Function), | ||
| ); | ||
|
|
||
| // Tests | ||
| expect(ProjectController.updateManagedByUsers).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| params: { ProjectId }, | ||
| body: { action: 'remove', userId }, | ||
| }), // Check if ProjectId is parsed from params | ||
| expect.anything(), // Mock response | ||
| expect.anything(), // Mock next | ||
| ); | ||
| expect(response.status).toBe(200); | ||
| expect(response.body).toEqual({ project: updatedProject, user: updatedUser }); | ||
|
|
||
| // Marks completion of tests | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
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.