@@ -521,4 +521,116 @@ describe('[Commands]', () => {
521521 } ) ;
522522 } ) ;
523523 } ) ;
524+ describe ( 'Command "kick"' , function ( ) {
525+ let directMessageRoom : IRoom ;
526+ let user1 : TestUser < IUser > ;
527+ let user1Credentials : Credentials ;
528+ this . beforeAll ( async ( ) => {
529+ user1 = await createUser ( ) ;
530+
531+ [ user1Credentials ] = await Promise . all ( [ login ( user1 . username , password ) ] ) ;
532+ } ) ;
533+
534+ this . beforeAll ( async ( ) => {
535+ const [ response1 ] = await Promise . all ( [
536+ createRoom ( { type : 'd' , name : `room1-${ Date . now ( ) } .${ Random . id ( ) } ` , username : user1 . username } ) ,
537+ ] ) ;
538+ directMessageRoom = response1 . body . room ;
539+ } ) ;
540+
541+ this . afterAll ( async ( ) => {
542+ await Promise . all ( [ deleteRoom ( { type : 'd' , roomId : directMessageRoom . _id } ) ] ) ;
543+ await Promise . all ( [ deleteUser ( user1 ) ] ) ;
544+ } ) ;
545+
546+ it ( 'should fail when trying to kick a user from a direct message room' , ( done ) => {
547+ void request
548+ . post ( api ( 'commands.run' ) )
549+ . set ( user1Credentials )
550+ . send ( { command : 'kick' , roomId : directMessageRoom . _id , params : user1 . username } )
551+ . expect ( 400 )
552+ . expect ( ( res ) => {
553+ expect ( res . body ) . to . have . property ( 'success' , false ) ;
554+ expect ( res . body ) . to . have . property ( 'error' ) . that . is . a ( 'string' ) ;
555+ } )
556+ . end ( done ) ;
557+ } ) ;
558+ } ) ;
559+ describe ( 'Command "leave"' , function ( ) {
560+ let directMessageRoom : IRoom ;
561+ let user1 : TestUser < IUser > ;
562+ let user2 : TestUser < IUser > ;
563+ let user1Credentials : Credentials ;
564+ this . beforeAll ( async ( ) => {
565+ user1 = await createUser ( ) ;
566+ user2 = await createUser ( ) ;
567+
568+ [ user1Credentials ] = await Promise . all ( [ login ( user1 . username , password ) ] ) ;
569+ } ) ;
570+
571+ this . beforeAll ( async ( ) => {
572+ const [ response1 ] = await Promise . all ( [
573+ createRoom ( { type : 'd' , name : `room1-${ Date . now ( ) } .${ Random . id ( ) } ` , username : user1 . username } ) ,
574+ ] ) ;
575+ directMessageRoom = response1 . body . room ;
576+ } ) ;
577+
578+ this . afterAll ( async ( ) => {
579+ await Promise . all ( [ deleteRoom ( { type : 'd' , roomId : directMessageRoom . _id } ) ] ) ;
580+ await Promise . all ( [ deleteUser ( user1 ) , deleteUser ( user2 ) ] ) ;
581+ } ) ;
582+
583+ it ( 'should fail when trying to leave a direct message room' , ( done ) => {
584+ void request
585+ . post ( api ( 'commands.run' ) )
586+ . set ( user1Credentials )
587+ . send ( { command : 'leave' , roomId : directMessageRoom . _id } )
588+ . expect ( 400 )
589+ . expect ( ( res ) => {
590+ expect ( res . body ) . to . have . property ( 'success' , false ) ;
591+ expect ( res . body ) . to . have . property ( 'error' ) . that . is . a ( 'string' ) ;
592+ } )
593+ . end ( done ) ;
594+ } ) ;
595+ } ) ;
596+
597+ // TODO: invite never fails
598+ describe . skip ( 'Command "invite"' , function ( ) {
599+ let directMessageRoom : IRoom ;
600+ let user1 : TestUser < IUser > ;
601+ let user2 : TestUser < IUser > ;
602+ let user1Credentials : Credentials ;
603+ this . beforeAll ( async ( ) => {
604+ user1 = await createUser ( ) ;
605+ user2 = await createUser ( ) ;
606+
607+ [ user1Credentials ] = await Promise . all ( [ login ( user1 . username , password ) ] ) ;
608+ } ) ;
609+
610+ this . beforeAll ( async ( ) => {
611+ const [ response1 ] = await Promise . all ( [
612+ createRoom ( { type : 'd' , name : `room1-${ Date . now ( ) } .${ Random . id ( ) } ` , username : user1 . username } ) ,
613+ ] ) ;
614+ directMessageRoom = response1 . body . room ;
615+ } ) ;
616+
617+ this . afterAll ( async ( ) => {
618+ await Promise . all ( [ deleteRoom ( { type : 'd' , roomId : directMessageRoom . _id } ) ] ) ;
619+ await Promise . all ( [ deleteUser ( user1 ) , deleteUser ( user2 ) ] ) ;
620+ } ) ;
621+
622+ it ( 'should fail when trying to invite a user to a direct message room' , ( done ) => {
623+ void request
624+ . post ( api ( 'commands.run' ) )
625+ . set ( user1Credentials )
626+ . send ( { command : 'invite' , roomId : directMessageRoom . _id , params : 'g1' } )
627+ . expect ( 403 )
628+ . expect ( ( res ) => {
629+ expect ( res . body ) . to . have . property ( 'success' , false ) ;
630+ expect ( res . body ) . to . have . property ( 'error' ) . that . is . a ( 'string' ) ;
631+ expect ( res . body . error ) . to . equal ( 'unauthorized' ) ;
632+ } )
633+ . end ( done ) ;
634+ } ) ;
635+ } ) ;
524636} ) ;
0 commit comments