@@ -390,6 +390,76 @@ describe('/therapeutic-targets', () => {
390390 . type ( 'json' )
391391 . expect ( HTTP_STATUS . BAD_REQUEST ) ;
392392 } , LONGER_TIMEOUT ) ;
393+
394+ describe ( 'rank update and report signatures' , ( ) => {
395+ let signature ;
396+ let user ;
397+ let originalState ;
398+
399+ beforeEach ( async ( ) => {
400+ user = await db . models . user . findOne ( { where : { username} } ) ;
401+ signature = await db . models . signatures . create ( {
402+ reportId : report . id ,
403+ authorId : user . id ,
404+ authorSignedAt : new Date ( ) ,
405+ reviewerId : user . id ,
406+ reviewerSignedAt : new Date ( ) ,
407+ creatorId : user . id ,
408+ creatorSignedAt : new Date ( ) ,
409+ } ) ;
410+ // state is excluded from signature removal, so setting it
411+ // here does not wipe the signature we just created
412+ ( { state : originalState } = await db . models . report . findOne ( {
413+ where : { id : report . id } ,
414+ } ) ) ;
415+ await db . models . report . update (
416+ { state : 'reviewed' } ,
417+ { where : { id : report . id } , hooks : false } ,
418+ ) ;
419+ } ) ;
420+
421+ afterEach ( async ( ) => {
422+ if ( signature ) {
423+ await db . models . signatures . destroy ( {
424+ where : { ident : signature . ident } ,
425+ force : true ,
426+ } ) ;
427+ }
428+ // restore the original state - report.state is allowNull: false
429+ await db . models . report . update (
430+ { state : originalState } ,
431+ { where : { id : report . id } , hooks : false } ,
432+ ) ;
433+ } ) ;
434+
435+ test ( 'reorder revokes author + reviewer signatures, keeps creator' , async ( ) => {
436+ await request
437+ . put ( `/api/reports/${ report . ident } /therapeutic-targets` )
438+ . auth ( username , password )
439+ . send ( [
440+ { ident : originalGene . ident , rank : newTarget . rank } ,
441+ { ident : newTarget . ident , rank : originalGene . rank } ,
442+ ] )
443+ . type ( 'json' )
444+ . expect ( HTTP_STATUS . OK ) ;
445+
446+ const updatedSignature = await db . models . signatures . findOne ( {
447+ where : { reportId : report . id } ,
448+ } ) ;
449+ expect ( updatedSignature . authorId ) . toBe ( null ) ;
450+ expect ( updatedSignature . authorSignedAt ) . toBe ( null ) ;
451+ expect ( updatedSignature . reviewerId ) . toBe ( null ) ;
452+ expect ( updatedSignature . reviewerSignedAt ) . toBe ( null ) ;
453+ // creator signature is intentionally preserved
454+ expect ( updatedSignature . creatorId ) . toBe ( user . id ) ;
455+ expect ( updatedSignature . creatorSignedAt ) . not . toBe ( null ) ;
456+
457+ const updatedReport = await db . models . report . findOne ( {
458+ where : { id : report . id } ,
459+ } ) ;
460+ expect ( updatedReport . state ) . toBe ( 'ready' ) ;
461+ } , LONGER_TIMEOUT ) ;
462+ } ) ;
393463 } ) ;
394464
395465 test . todo ( 'Bad request on update and set gene to null' ) ;
0 commit comments