@@ -4550,6 +4550,80 @@ describe('ReportUtils', () => {
45504550
45514551 expect ( canLeaveChat ( report , reportPolicy ) ) . toBe ( true ) ;
45524552 } ) ;
4553+
4554+ describe ( 'when the report is a money report' , ( ) => {
4555+ it ( 'should return false for the owner of the report' , async ( ) => {
4556+ const report : Report = {
4557+ ...createRandomReport ( 1 ) ,
4558+ chatType : undefined ,
4559+ type : CONST . REPORT . TYPE . IOU ,
4560+ ownerAccountID : currentUserAccountID ,
4561+ } ;
4562+
4563+ await Onyx . set ( ONYXKEYS . SESSION , { email : currentUserEmail , accountID : currentUserAccountID } ) ;
4564+
4565+ const reportPolicy : Policy = {
4566+ ...createRandomPolicy ( 1 ) ,
4567+ role : CONST . POLICY . ROLE . USER ,
4568+ } ;
4569+
4570+ expect ( canLeaveChat ( report , reportPolicy ) ) . toBe ( false ) ;
4571+ } ) ;
4572+
4573+ it ( 'should return false for the manager of the report' , async ( ) => {
4574+ const report : Report = {
4575+ ...createRandomReport ( 1 ) ,
4576+ chatType : undefined ,
4577+ type : CONST . REPORT . TYPE . IOU ,
4578+ managerID : currentUserAccountID ,
4579+ } ;
4580+
4581+ await Onyx . set ( ONYXKEYS . SESSION , { email : currentUserEmail , accountID : currentUserAccountID } ) ;
4582+
4583+ const reportPolicy : Policy = {
4584+ ...createRandomPolicy ( 1 ) ,
4585+ role : CONST . POLICY . ROLE . USER ,
4586+ } ;
4587+
4588+ expect ( canLeaveChat ( report , reportPolicy ) ) . toBe ( false ) ;
4589+ } ) ;
4590+
4591+ it ( 'should return false for the admin of the policy' , async ( ) => {
4592+ const report : Report = {
4593+ ...createRandomReport ( 1 ) ,
4594+ chatType : CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ,
4595+ type : CONST . REPORT . TYPE . EXPENSE ,
4596+ } ;
4597+
4598+ await Onyx . set ( ONYXKEYS . SESSION , { email : currentUserEmail , accountID : currentUserAccountID } ) ;
4599+
4600+ const reportPolicy : Policy = {
4601+ ...createRandomPolicy ( 1 ) ,
4602+ role : CONST . POLICY . ROLE . ADMIN ,
4603+ } ;
4604+
4605+ expect ( canLeaveChat ( report , reportPolicy ) ) . toBe ( false ) ;
4606+ } ) ;
4607+
4608+ it ( 'should return true for the invited user' , async ( ) => {
4609+ const report : Report = {
4610+ ...createRandomReport ( 1 ) ,
4611+ chatType : undefined ,
4612+ type : CONST . REPORT . TYPE . IOU ,
4613+ ownerAccountID : 1 ,
4614+ managerID : 2 ,
4615+ } ;
4616+
4617+ await Onyx . set ( ONYXKEYS . SESSION , { email : currentUserEmail , accountID : currentUserAccountID } ) ;
4618+
4619+ const reportPolicy : Policy = {
4620+ ...createRandomPolicy ( 1 ) ,
4621+ role : CONST . POLICY . ROLE . USER ,
4622+ } ;
4623+
4624+ expect ( canLeaveChat ( report , reportPolicy ) ) . toBe ( true ) ;
4625+ } ) ;
4626+ } ) ;
45534627 } ) ;
45544628
45554629 describe ( 'canJoinChat' , ( ) => {
0 commit comments