@@ -22,6 +22,9 @@ describe('setUserActiveStatus', () => {
2222 setDmReadOnlyByUserId : sandbox . stub ( ) ,
2323 getDirectConversationsByUserId : sandbox . stub ( ) ,
2424 } ,
25+ Subscriptions : {
26+ setArchivedForDMsWithUsername : sandbox . stub ( ) ,
27+ } ,
2528 check : sandbox . stub ( ) ,
2629 callbacks : {
2730 run : sandbox . stub ( ) ,
@@ -32,6 +35,7 @@ describe('setUserActiveStatus', () => {
3235 notifyOnUserChange : sandbox . stub ( ) ,
3336 notifyOnRoomChangedByUserDM : sandbox . stub ( ) ,
3437 notifyOnRoomChangedById : sandbox . stub ( ) ,
38+ notifyOnSubscriptionChangedByNameAndRoomType : sandbox . stub ( ) ,
3539 getSubscribedRoomsForUserWithDetails : sandbox . stub ( ) ,
3640 shouldRemoveOrChangeOwner : sandbox . stub ( ) ,
3741 getUserSingleOwnedRooms : sandbox . stub ( ) ,
@@ -56,7 +60,7 @@ describe('setUserActiveStatus', () => {
5660 'meteor/meteor' : { Meteor : { Error } } ,
5761 'meteor/accounts-base' : { Accounts : stubs . Accounts } ,
5862 '@rocket.chat/core-typings' : { isUserFederated : stubs . isUserFederated , isDirectMessageRoom : sinon . stub ( ) } ,
59- '@rocket.chat/models' : { Users : stubs . Users , Rooms : stubs . Rooms } ,
63+ '@rocket.chat/models' : { Users : stubs . Users , Rooms : stubs . Rooms , Subscriptions : stubs . Subscriptions } ,
6064 './closeOmnichannelConversations' : { closeOmnichannelConversations : stubs . closeOmnichannelConversations } ,
6165 './getRoomsWithSingleOwner' : {
6266 shouldRemoveOrChangeOwner : stubs . shouldRemoveOrChangeOwner ,
@@ -71,6 +75,7 @@ describe('setUserActiveStatus', () => {
7175 notifyOnRoomChangedById : stubs . notifyOnRoomChangedById ,
7276 notifyOnRoomChangedByUserDM : stubs . notifyOnRoomChangedByUserDM ,
7377 notifyOnUserChange : stubs . notifyOnUserChange ,
78+ notifyOnSubscriptionChangedByNameAndRoomType : stubs . notifyOnSubscriptionChangedByNameAndRoomType ,
7479 } ,
7580 } ) ;
7681
@@ -91,9 +96,11 @@ describe('setUserActiveStatus', () => {
9196 stubs . settings . get . returns ( false ) ;
9297 stubs . Rooms . setDmReadOnlyByUserId . resolves ( { modifiedCount : 0 } ) ;
9398 stubs . Rooms . getDirectConversationsByUserId . returns ( { toArray : sinon . stub ( ) . resolves ( [ ] ) } ) ;
99+ stubs . Subscriptions . setArchivedForDMsWithUsername . resolves ( { modifiedCount : 0 } ) ;
94100 stubs . notifyOnRoomChangedById . returns ( undefined ) ;
95101 stubs . notifyOnUserChange . returns ( undefined ) ;
96102 stubs . notifyOnRoomChangedByUserDM . returns ( undefined ) ;
103+ stubs . notifyOnSubscriptionChangedByNameAndRoomType . returns ( undefined ) ;
97104 } ) ;
98105
99106 afterEach ( ( ) => {
@@ -102,12 +109,16 @@ describe('setUserActiveStatus', () => {
102109
103110 describe ( 'Successful status changes' , ( ) => {
104111 it ( 'should deactivate a user successfully' , async ( ) => {
112+ stubs . Subscriptions . setArchivedForDMsWithUsername . resolves ( { modifiedCount : 1 } ) ;
113+
105114 const result = await setUserActiveStatus ( userId , false ) ;
106115
107116 expect ( result ) . to . be . true ;
108117 expect ( stubs . Users . setUserActive . calledWith ( userId , false ) ) . to . be . true ;
109118 expect ( stubs . Users . unsetLoginTokens . calledWith ( userId ) ) . to . be . true ;
110119 expect ( stubs . Rooms . setDmReadOnlyByUserId . calledWith ( userId , undefined , true , false ) ) . to . be . true ;
120+ expect ( stubs . Subscriptions . setArchivedForDMsWithUsername . calledWith ( username , true ) ) . to . be . true ;
121+ expect ( stubs . notifyOnSubscriptionChangedByNameAndRoomType . calledWith ( { t : 'd' , name : username } ) ) . to . be . true ;
111122 expect ( stubs . callbacks . run . calledWith ( 'afterDeactivateUser' , sinon . match ( { _id : userId } ) ) ) . to . be . true ;
112123 expect (
113124 stubs . notifyOnUserChange . calledWith (
@@ -125,6 +136,7 @@ describe('setUserActiveStatus', () => {
125136 expect ( result ) . to . be . true ;
126137 expect ( stubs . callbacks . run . calledWith ( 'beforeActivateUser' , sinon . match ( { _id : userId } ) ) ) . to . be . true ;
127138 expect ( stubs . Users . setUserActive . calledWith ( userId , true ) ) . to . be . true ;
139+ expect ( stubs . Subscriptions . setArchivedForDMsWithUsername . calledWith ( username , false ) ) . to . be . true ;
128140 expect ( stubs . callbacks . run . calledWith ( 'afterActivateUser' , sinon . match ( { _id : userId } ) ) ) . to . be . true ;
129141 expect ( stubs . Users . unsetReason . calledWith ( userId ) ) . to . be . true ;
130142 expect ( stubs . notifyOnUserChange . calledWith ( sinon . match ( { clientAction : 'updated' , id : userId , diff : { active : true } } ) ) ) . to . be . true ;
0 commit comments