@@ -335,6 +335,104 @@ describe('challenge phase service unit tests', () => {
335335 }
336336 throw new Error ( 'should not reach here' )
337337 } )
338+
339+ it ( 'partially update challenge phase - cannot open phase when predecessor is not closed' , async ( ) => {
340+ await prisma . challengePhase . update ( {
341+ where : { id : data . challengePhase1Id } ,
342+ data : { isOpen : true }
343+ } )
344+
345+ try {
346+ await service . partiallyUpdateChallengePhase ( authUser , data . challenge . id , data . challengePhase2Id , { isOpen : true } )
347+ } catch ( e ) {
348+ should . equal (
349+ e . message ,
350+ 'Cannot open phase because predecessor phase must be closed with both actualStartDate and actualEndDate set'
351+ )
352+ return
353+ }
354+ throw new Error ( 'should not reach here' )
355+ } )
356+
357+ it ( 'partially update challenge phase - cannot open phase when predecessor has no actualEndDate' , async ( ) => {
358+ const startDate = new Date ( '2025-01-01T00:00:00.000Z' )
359+ await prisma . challengePhase . update ( {
360+ where : { id : data . challengePhase1Id } ,
361+ data : {
362+ isOpen : false ,
363+ actualStartDate : startDate ,
364+ actualEndDate : null
365+ }
366+ } )
367+
368+ try {
369+ await service . partiallyUpdateChallengePhase ( authUser , data . challenge . id , data . challengePhase2Id , { isOpen : true } )
370+ } catch ( e ) {
371+ should . equal (
372+ e . message ,
373+ 'Cannot open phase because predecessor phase must be closed with both actualStartDate and actualEndDate set'
374+ )
375+ return
376+ }
377+ throw new Error ( 'should not reach here' )
378+ } )
379+
380+ it ( 'partially update challenge phase - cannot open phase when predecessor has no actualStartDate' , async ( ) => {
381+ const endDate = new Date ( '2025-01-02T00:00:00.000Z' )
382+ await prisma . challengePhase . update ( {
383+ where : { id : data . challengePhase1Id } ,
384+ data : {
385+ isOpen : false ,
386+ actualStartDate : null ,
387+ actualEndDate : endDate
388+ }
389+ } )
390+
391+ try {
392+ await service . partiallyUpdateChallengePhase ( authUser , data . challenge . id , data . challengePhase2Id , { isOpen : true } )
393+ } catch ( e ) {
394+ should . equal (
395+ e . message ,
396+ 'Cannot open phase because predecessor phase must be closed with both actualStartDate and actualEndDate set'
397+ )
398+ return
399+ }
400+ throw new Error ( 'should not reach here' )
401+ } )
402+
403+ it ( 'partially update challenge phase - can open phase when predecessor is properly closed' , async ( ) => {
404+ const startDate = new Date ( '2025-02-01T00:00:00.000Z' )
405+ const endDate = new Date ( '2025-02-02T00:00:00.000Z' )
406+ await prisma . challengePhase . update ( {
407+ where : { id : data . challengePhase1Id } ,
408+ data : {
409+ isOpen : false ,
410+ actualStartDate : startDate ,
411+ actualEndDate : endDate
412+ }
413+ } )
414+ await prisma . challengePhase . update ( {
415+ where : { id : data . challengePhase2Id } ,
416+ data : { isOpen : false }
417+ } )
418+
419+ const challengePhase = await service . partiallyUpdateChallengePhase ( authUser , data . challenge . id , data . challengePhase2Id , { isOpen : true } )
420+ should . equal ( challengePhase . isOpen , true )
421+ } )
422+
423+ it ( 'partially update challenge phase - can open phase without predecessor' , async ( ) => {
424+ await prisma . challengePhase . update ( {
425+ where : { id : data . challengePhase1Id } ,
426+ data : {
427+ isOpen : false ,
428+ actualStartDate : null ,
429+ actualEndDate : null
430+ }
431+ } )
432+
433+ const challengePhase = await service . partiallyUpdateChallengePhase ( authUser , data . challenge . id , data . challengePhase1Id , { isOpen : true } )
434+ should . equal ( challengePhase . isOpen , true )
435+ } )
338436 } )
339437
340438 describe ( 'delete challenge phase tests' , ( ) => {
0 commit comments