Skip to content

Commit 51df3b5

Browse files
committed
Update test
1 parent c6e4b34 commit 51df3b5

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

tests/unit/ModifiedExpenseMessageTest.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import {createRandomReport} from '../utils/collections/reports';
1414
import {translateLocal} from '../utils/TestHelper';
1515
import 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+
1725
const MOVED_TO_REPORT_ID = '1';
1826
const 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

Comments
 (0)