@@ -158,7 +158,7 @@ describe('Unit testing for Projects router', () => {
158158
159159 // Tests
160160 expect ( ProjectController . create ) . toHaveBeenCalledWith (
161- expect . objectContaining ( { body : newProject } ) , // Check if newProject in body is parsed
161+ expect . objectContaining ( { body : newProject } ) , // Check if newProject in body is parsed
162162 expect . anything ( ) , // Mock response
163163 expect . anything ( ) , // Mock next
164164 ) ;
@@ -234,7 +234,7 @@ describe('Unit testing for Projects router', () => {
234234 } ) ;
235235
236236 const updatedProject = {
237- id : '1 ' ,
237+ id : 'projectId1 ' ,
238238 name : 'updated project1' ,
239239 description : 'updated testing' ,
240240 githubIdentifier : 'gitHubTest3' ,
@@ -251,7 +251,7 @@ describe('Unit testing for Projects router', () => {
251251 lookingDescription : 'n/a' ,
252252 recruitingCategories : [ 'n/a' ] ,
253253 partners : [ 'n/a' ] ,
254- managedByUsers : [ 'n/a ' ] ,
254+ managedByUsers : [ 'userId1 ' ] ,
255255 } ;
256256
257257 const ProjectId = updatedProject . id ;
@@ -274,7 +274,7 @@ describe('Unit testing for Projects router', () => {
274274
275275 // Tests
276276 expect ( ProjectController . update ) . toHaveBeenCalledWith (
277- expect . objectContaining ( { params : { ProjectId } } ) , // Check if ProjectId is parsed from params
277+ expect . objectContaining ( { params : { ProjectId } } ) , // Check if ProjectId is parsed from params
278278 expect . anything ( ) , // Mock response
279279 expect . anything ( ) , // Mock next
280280 ) ;
@@ -284,5 +284,85 @@ describe('Unit testing for Projects router', () => {
284284 // Marks completion of tests
285285 done ( ) ;
286286 } ) ;
287+
288+ const updatedUser = {
289+ id : 'userId1' ,
290+ name : 'Updated User' ,
291+ email : 'mockuser@example.com' ,
292+ managedProjects : [ 'projectId1' ] ,
293+ } ;
294+
295+ const userId = updatedUser . id ;
296+
297+ it ( "should add to the project's managedByUsers and the user's managedProjects fields with PATCH /api/projects/:ProjectId" , async ( done ) => {
298+ // Mock ProjectController.updateManagedByUsers method when this route is called
299+ ProjectController . updateManagedByUsers . mockImplementationOnce ( ( req , res ) => {
300+ res . status ( 200 ) . send ( { project : updatedProject , user : updatedUser } ) ;
301+ } ) ;
302+
303+ // Mock PUT API call
304+ const response = await request
305+ . patch ( `/api/projects/${ ProjectId } ` )
306+ . send ( { action : 'add' , userId } ) ;
307+
308+ // Middlware assertions
309+ expect ( mockVerifyCookie ) . toHaveBeenCalledWith (
310+ expect . any ( Object ) ,
311+ expect . any ( Object ) ,
312+ expect . any ( Function ) ,
313+ ) ;
314+
315+ // Tests
316+ expect ( ProjectController . updateManagedByUsers ) . toHaveBeenCalledWith (
317+ expect . objectContaining ( {
318+ params : { ProjectId } ,
319+ body : { action : 'add' , userId } ,
320+ } ) , // Check if ProjectId is parsed from params
321+ expect . anything ( ) , // Mock response
322+ expect . anything ( ) , // Mock next
323+ ) ;
324+ expect ( response . status ) . toBe ( 200 ) ;
325+ expect ( response . body ) . toEqual ( { project : updatedProject , user : updatedUser } ) ;
326+
327+ // Marks completion of tests
328+ done ( ) ;
329+ } ) ;
330+
331+ 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 ) => {
332+ updatedProject . managedByUsers = [ ] ;
333+ updatedUser . managedProjects = [ ] ;
334+
335+ // Mock ProjectController.updateManagedByUsers method when this route is called
336+ ProjectController . updateManagedByUsers . mockImplementationOnce ( ( req , res ) => {
337+ res . status ( 200 ) . send ( { project : updatedProject , user : updatedUser } ) ;
338+ } ) ;
339+
340+ // Mock PUT API call
341+ const response = await request
342+ . patch ( `/api/projects/${ ProjectId } ` )
343+ . send ( { action : 'remove' , userId } ) ;
344+
345+ // Middlware assertions
346+ expect ( mockVerifyCookie ) . toHaveBeenCalledWith (
347+ expect . any ( Object ) ,
348+ expect . any ( Object ) ,
349+ expect . any ( Function ) ,
350+ ) ;
351+
352+ // Tests
353+ expect ( ProjectController . updateManagedByUsers ) . toHaveBeenCalledWith (
354+ expect . objectContaining ( {
355+ params : { ProjectId } ,
356+ body : { action : 'remove' , userId } ,
357+ } ) , // Check if ProjectId is parsed from params
358+ expect . anything ( ) , // Mock response
359+ expect . anything ( ) , // Mock next
360+ ) ;
361+ expect ( response . status ) . toBe ( 200 ) ;
362+ expect ( response . body ) . toEqual ( { project : updatedProject , user : updatedUser } ) ;
363+
364+ // Marks completion of tests
365+ done ( ) ;
366+ } ) ;
287367 } ) ;
288368} ) ;
0 commit comments