@@ -14,6 +14,14 @@ import {createRandomReport} from '../utils/collections/reports';
1414import { translateLocal } from '../utils/TestHelper' ;
1515import waitForBatchedUpdates from '../utils/waitForBatchedUpdates' ;
1616
17+ // Mock PolicyUtils so getPolicy and isPolicyAdmin are controllable in tests. ModifiedExpenseMessage
18+ // uses named imports from this module; spies alone do not affect those references, so we need a module mock.
19+ jest . mock ( '@libs/PolicyUtils' , ( ) => ( {
20+ ...jest . requireActual < typeof PolicyUtils > ( '@libs/PolicyUtils' ) ,
21+ getPolicy : jest . fn ( ) ,
22+ isPolicyAdmin : jest . fn ( ) ,
23+ } ) ) ;
24+
1725const MOVED_TO_REPORT_ID = '1' ;
1826const MOVED_FROM_REPORT_ID = '2' ;
1927
@@ -821,9 +829,12 @@ describe('ModifiedExpenseMessage', () => {
821829 } ) ;
822830
823831 beforeEach ( ( ) => {
824- // Default: current user is workspace admin, so link points to workspace rules
825- jest . spyOn ( PolicyUtils , 'getPolicy' ) . mockReturnValue ( { id : policyRulesPolicyId } as Policy ) ;
826- jest . spyOn ( PolicyUtils , 'isPolicyAdmin' ) . mockReturnValue ( true ) ;
832+ // Default: current user has policy rule access (admin + rules enabled), so link points to workspace rules
833+ ( PolicyUtils . getPolicy as jest . Mock ) . mockReturnValue ( {
834+ id : policyRulesPolicyId ,
835+ areRulesEnabled : true ,
836+ } as Policy ) ;
837+ ( PolicyUtils . isPolicyAdmin as jest . Mock ) . mockReturnValue ( true ) ;
827838 } ) ;
828839
829840 it ( 'returns the correct text message with multiple overrides' , ( ) => {
@@ -934,7 +945,7 @@ describe('ModifiedExpenseMessage', () => {
934945 } ) ;
935946
936947 it ( 'returns the correct text message with help link for non-admin' , ( ) => {
937- jest . spyOn ( PolicyUtils , ' isPolicyAdmin' ) . mockReturnValue ( false ) ;
948+ ( PolicyUtils . isPolicyAdmin as jest . Mock ) . mockReturnValue ( false ) ;
938949
939950 const reportAction = {
940951 ...createRandomReportAction ( 1 ) ,
0 commit comments