@@ -4,7 +4,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
44import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
55import {
66 useLibrary , usePermissionsByRole , useTeamMembers , useAssignTeamMembersRole , useRevokeUserRoles ,
7- useUpdateLibrary ,
87} from './hooks' ;
98
109jest . mock ( '@edx/frontend-platform/auth' , ( ) => ( {
@@ -341,80 +340,3 @@ describe('useRevokeUserRoles', () => {
341340 expect ( calledUrl . searchParams . get ( 'scope' ) ) . toBe ( revokeRoleData . scope ) ;
342341 } ) ;
343342} ) ;
344-
345- describe ( 'useUpdateLibrary' , ( ) => {
346- const queryKeyTest = [ 'org.openedx.frontend.app.adminConsole' , 'authz' , 'library' , 'lib:123' ] ;
347-
348- beforeEach ( ( ) => {
349- jest . clearAllMocks ( ) ;
350- } ) ;
351-
352- it ( 'calls updateLibrary with correct params and updates cache' , async ( ) => {
353- const mockData = { id : 'lib:123' , title : 'Library Test' } ;
354- getAuthenticatedHttpClient . mockReturnValue ( {
355- patch : jest . fn ( ) . mockResolvedValue ( { data : mockData } ) ,
356- } ) ;
357- const { result } = renderHook ( ( ) => useUpdateLibrary ( ) , { wrapper : createWrapper ( ) } ) ;
358-
359- await act ( async ( ) => {
360- await result . current . mutateAsync ( {
361- libraryId : 'lib:123' ,
362- updatedData : { title : 'Library Test' } ,
363- } ) ;
364- } ) ;
365-
366- expect ( getAuthenticatedHttpClient ) . toHaveBeenCalled ( ) ;
367- } ) ;
368-
369- it ( 'sets query data on success' , async ( ) => {
370- const mockData = { id : 'lib:123' , title : 'Updated Library' } ;
371- getAuthenticatedHttpClient . mockReturnValue ( {
372- patch : jest . fn ( ) . mockResolvedValue ( { data : mockData } ) ,
373- } ) ;
374-
375- const queryClient = new QueryClient ( ) ;
376- const wrapper = ( { children } : { children : ReactNode } ) => (
377- < QueryClientProvider client = { queryClient } > { children } </ QueryClientProvider >
378- ) ;
379-
380- const { result } = renderHook ( ( ) => useUpdateLibrary ( ) , { wrapper } ) ;
381-
382- await act ( async ( ) => {
383- await result . current . mutateAsync ( {
384- libraryId : 'lib:123' ,
385- updatedData : { title : 'Updated Library' } ,
386- } ) ;
387- } ) ;
388-
389- // verify cache updated with the returned data
390- expect ( queryClient . getQueryData ( queryKeyTest ) ) . toEqual ( mockData ) ;
391- expect ( getAuthenticatedHttpClient ) . toHaveBeenCalled ( ) ;
392- } ) ;
393-
394- it ( 'invalidates query on settled' , async ( ) => {
395- const mockData = { id : 'lib:123' , title : 'Final Title' } ;
396- getAuthenticatedHttpClient . mockReturnValue ( {
397- patch : jest . fn ( ) . mockResolvedValue ( { data : mockData } ) ,
398- } ) ;
399- const queryClient = new QueryClient ( ) ;
400- const invalidateSpy = jest . spyOn ( queryClient , 'invalidateQueries' ) ;
401-
402- const wrapper = ( { children } : { children : ReactNode } ) => (
403- < QueryClientProvider client = { queryClient } > { children } </ QueryClientProvider >
404- ) ;
405-
406- const { result } = renderHook ( ( ) => useUpdateLibrary ( ) , { wrapper } ) ;
407-
408- await act ( async ( ) => {
409- await result . current . mutateAsync ( {
410- libraryId : 'lib:123' ,
411- updatedData : { title : 'Final Title' } ,
412- } ) ;
413- } ) ;
414-
415- expect ( invalidateSpy ) . toHaveBeenCalledWith ( {
416- queryKey : queryKeyTest ,
417- } ) ;
418- expect ( getAuthenticatedHttpClient ) . toHaveBeenCalled ( ) ;
419- } ) ;
420- } ) ;
0 commit comments