44import { AppContext } from '@edx/frontend-platform/react' ;
55import userEvent from '@testing-library/user-event' ;
66import { MemoryRouter , Route , Routes } from 'react-router-dom' ;
7- import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth ' ;
7+ import { mockHttpClient , mockAppContext } from '@src/setupTest ' ;
88import { IntlProvider } from '@edx/frontend-platform/i18n' ;
99import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
1010import { ToastManagerProvider } from '@src/components/ToastManager/ToastManagerContext' ;
@@ -76,24 +76,6 @@ const renderWithRouter = (route = '/audit/johndoe') => {
7676 } ,
7777 } ) ;
7878
79- const mockAppContext = {
80- authenticatedUser : {
81- username : 'testuser' ,
82- email : 'testuser@example.com' ,
83- userId : 1 ,
84- } ,
85- config : {
86- LMS_BASE_URL : 'http://localhost:18000' ,
87- STUDIO_BASE_URL : 'http://localhost:18010' ,
88- AUTHZ_MICROFRONTEND_URL : 'http://localhost:18012' ,
89- ACCESS_TOKEN_COOKIE_NAME : 'edx-jwt-cookie-header-payload' ,
90- BASE_URL : 'http://localhost:18012' ,
91- ENVIRONMENT : 'test' ,
92- LANGUAGE_PREFERENCE_COOKIE_NAME : 'openedx-language-preference' ,
93- ...process . env ,
94- } ,
95- } ;
96-
9779 return render (
9880 < AppContext . Provider value = { mockAppContext } >
9981 < QueryClientProvider client = { queryClient } >
@@ -116,7 +98,7 @@ describe('AuditUserPage', () => {
11698 beforeEach ( ( ) => {
11799 jest . clearAllMocks ( ) ;
118100 // Set up default mock behavior for useRevokeUserRoles
119- mockRevokeUserRoles . mockImplementation ( ( variables , { onSuccess } ) => {
101+ mockRevokeUserRoles . mockImplementation ( ( _variables , { onSuccess } ) => {
120102 // Simulate successful deletion by default
121103 onSuccess ( { errors : [ ] , completed : [ 'role1' ] } ) ;
122104 } ) ;
@@ -154,7 +136,7 @@ describe('AuditUserPage', () => {
154136 } ) ;
155137
156138 it ( 'navigates to home if user is not found' , async ( ) => {
157- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
139+ mockHttpClient ( ) . mockReturnValue ( {
158140 get : jest
159141 . fn ( )
160142 . mockResolvedValueOnce ( { data : null } )
@@ -169,7 +151,7 @@ describe('AuditUserPage', () => {
169151 } ) ;
170152
171153 it ( 'allows user to interact with Assign Role button' , async ( ) => {
172- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
154+ mockHttpClient ( ) . mockReturnValue ( {
173155 get : jest
174156 . fn ( )
175157 . mockResolvedValueOnce ( { data : mockUser } )
@@ -215,7 +197,7 @@ describe('AuditUserPage', () => {
215197 } ) ;
216198
217199 it ( 'renders correct table headers' , async ( ) => {
218- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
200+ mockHttpClient ( ) . mockReturnValue ( {
219201 get : jest
220202 . fn ( )
221203 . mockResolvedValueOnce ( { data : mockUser } )
@@ -294,7 +276,7 @@ describe('AuditUserPage', () => {
294276 } ) ;
295277
296278 it ( 'renders the breadcrumb navigation with home link' , async ( ) => {
297- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
279+ mockHttpClient ( ) . mockReturnValue ( {
298280 get : jest
299281 . fn ( )
300282 . mockResolvedValueOnce ( { data : mockUser } )
@@ -310,7 +292,7 @@ describe('AuditUserPage', () => {
310292 } ) ;
311293
312294 it ( 'opens and closes the ConfirmDeletionModal when delete is clicked and cancel is pressed' , async ( ) => {
313- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
295+ mockHttpClient ( ) . mockReturnValue ( {
314296 get : jest
315297 . fn ( )
316298 . mockResolvedValueOnce ( { data : mockUser } )
@@ -342,7 +324,7 @@ describe('AuditUserPage', () => {
342324 } ) ;
343325
344326 it ( 'calls onSave when confirming deletion in ConfirmDeletionModal' , async ( ) => {
345- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
327+ mockHttpClient ( ) . mockReturnValue ( {
346328 get : jest
347329 . fn ( )
348330 . mockResolvedValueOnce ( { data : mockUser } )
@@ -389,7 +371,7 @@ describe('AuditUserPage', () => {
389371 } ) ;
390372 } ) ;
391373
392- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
374+ mockHttpClient ( ) . mockReturnValue ( {
393375 get : jest
394376 . fn ( )
395377 . mockResolvedValueOnce ( { data : mockUser } )
@@ -424,12 +406,12 @@ describe('AuditUserPage', () => {
424406
425407 it ( 'shows error toast with retry when role revocation fails' , async ( ) => {
426408 // Override mock for this specific test case
427- mockRevokeUserRoles . mockImplementation ( ( variables , { onError } ) => {
409+ mockRevokeUserRoles . mockImplementation ( ( _variables , { onError } ) => {
428410 // Call onError immediately to simulate failure
429411 onError ( new Error ( 'Network error' ) ) ;
430412 } ) ;
431413
432- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
414+ mockHttpClient ( ) . mockReturnValue ( {
433415 get : jest
434416 . fn ( )
435417 . mockResolvedValueOnce ( { data : mockUser } )
@@ -464,7 +446,7 @@ describe('AuditUserPage', () => {
464446 } ) ;
465447
466448 it ( 'shows the extra warning when rolesCount is 1' , async ( ) => {
467- ( getAuthenticatedHttpClient as jest . Mock ) . mockReturnValue ( {
449+ mockHttpClient ( ) . mockReturnValue ( {
468450 get : jest
469451 . fn ( )
470452 . mockResolvedValueOnce ( { data : mockUser } )
0 commit comments