@@ -28,14 +28,32 @@ const pinMessage = ({ msgId }: { msgId: IMessage['_id'] }) => {
2828describe ( '[Chat]' , ( ) => {
2929 let testChannel : IRoom ;
3030 let message : { _id : IMessage [ '_id' ] } ;
31+ let protectedChannel : IRoom ;
3132
3233 before ( ( done ) => getCredentials ( done ) ) ;
3334
3435 before ( async ( ) => {
3536 testChannel = ( await createRoom ( { type : 'c' , name : `chat.api-test-${ Date . now ( ) } ` } ) ) . body . channel ;
37+ protectedChannel = ( await createRoom ( { type : 'c' , name : `chat.api-protected-test-${ Date . now ( ) } ` } ) ) . body . channel ;
38+
39+ await request
40+ . post ( api ( 'rooms.saveRoomSettings' ) )
41+ . set ( credentials )
42+ . send ( {
43+ rid : protectedChannel . _id ,
44+ joinCode : 'super-secret-password' ,
45+ } )
46+ . expect ( 'Content-Type' , 'application/json' )
47+ . expect ( 200 )
48+ . expect ( ( res ) => {
49+ expect ( res . body ) . to . have . property ( 'success' , true ) ;
50+ } ) ;
3651 } ) ;
3752
38- after ( ( ) => deleteRoom ( { type : 'c' , roomId : testChannel . _id } ) ) ;
53+ after ( async ( ) => {
54+ await deleteRoom ( { type : 'c' , roomId : testChannel . _id } ) ;
55+ await deleteRoom ( { type : 'c' , roomId : protectedChannel . _id } ) ;
56+ } ) ;
3957
4058 describe ( '/chat.postMessage' , ( ) => {
4159 it ( 'should throw an error when at least one of required parameters(channel, roomId) is not sent' , ( done ) => {
@@ -586,6 +604,34 @@ describe('[Chat]', () => {
586604 . end ( done ) ;
587605 } ) ;
588606
607+ it ( 'should allow forwarding a message into the same password protected room' , async ( ) => {
608+ const postResponse = await request
609+ . post ( api ( 'chat.postMessage' ) )
610+ . set ( credentials )
611+ . send ( {
612+ roomId : [ protectedChannel . _id ] ,
613+ text : 'Message to be forwarded' ,
614+ } )
615+ . expect ( 'Content-Type' , 'application/json' )
616+ . expect ( 200 ) ;
617+
618+ expect ( postResponse . body ) . to . have . property ( 'success' , true ) ;
619+ const originalMessageId = postResponse . body . message . _id as IMessage [ '_id' ] ;
620+
621+ const forwardResponse = await request
622+ . post ( api ( 'chat.postMessage' ) )
623+ . set ( credentials )
624+ . send ( {
625+ roomId : [ protectedChannel . _id ] ,
626+ text : `[](http://localhost:3000/channel/${ protectedChannel . name } ?msg=${ originalMessageId } ` ,
627+ } )
628+ . expect ( 'Content-Type' , 'application/json' )
629+ . expect ( 200 ) ;
630+
631+ expect ( forwardResponse . body ) . to . have . property ( 'success' , true ) ;
632+ expect ( forwardResponse . body ) . to . have . nested . property ( 'message.rid' , protectedChannel . _id ) ;
633+ } ) ;
634+
589635 it ( 'should return statusCode 200 when postMessage successfully' , ( done ) => {
590636 void request
591637 . post ( api ( 'chat.postMessage' ) )
0 commit comments