-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for useUserTenantPermissions
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { renderHook } from '@folio/jest-config-stripes/testing-library/react'; | ||
import { useStripes } from '../StripesContext'; | ||
import useUserSelfTenantPermissions from './useUserSelfTenantPermissions'; | ||
import useUserTenantPermissionNames from './useUserTenantPermissionNames'; | ||
import useUserTenantPermissions from './useUserTenantPermissions'; | ||
|
||
jest.mock('../StripesContext'); | ||
jest.mock('./useUserSelfTenantPermissions'); | ||
jest.mock('./useUserTenantPermissionNames'); | ||
|
||
describe('useUserTenantPermissions', () => { | ||
const tenantId = 'tenant-id'; | ||
const options = {}; | ||
|
||
beforeEach(() => { | ||
useStripes.mockReturnValue({ | ||
hasInterface: jest.fn() | ||
}); | ||
}); | ||
|
||
it('should return _self permissions data when "roles" interface is present', () => { | ||
useStripes().hasInterface.mockReturnValue(true); | ||
|
||
useUserSelfTenantPermissions.mockReturnValue({ | ||
isFetching: true, | ||
isLoading: true, | ||
userPermissions: ['self'], | ||
totalRecords: 1 | ||
}); | ||
|
||
useUserTenantPermissionNames.mockReturnValue({ | ||
isFetching: false, | ||
isLoading: false, | ||
userPermissions: ['permission name'], | ||
totalRecords: 1 | ||
}); | ||
|
||
const { result } = renderHook(() => useUserTenantPermissions({ tenantId }, options)); | ||
|
||
expect(result.current).toStrictEqual({ | ||
isFetching: true, | ||
isLoading: true, | ||
userPermissions: ['self'], | ||
totalRecords: 1 | ||
}); | ||
}); | ||
|
||
it('should return tenant permissions data when "roles" interface is NOT present', () => { | ||
useStripes().hasInterface.mockReturnValue(false); | ||
|
||
useUserSelfTenantPermissions.mockReturnValue({ | ||
isFetching: true, | ||
isLoading: true, | ||
userPermissions: ['self'], | ||
totalRecords: 1 | ||
}); | ||
|
||
useUserTenantPermissionNames.mockReturnValue({ | ||
isFetching: false, | ||
isLoading: false, | ||
userPermissions: ['permission name'], | ||
totalRecords: 1 | ||
}); | ||
|
||
const { result } = renderHook(() => useUserTenantPermissions({ tenantId }, options)); | ||
|
||
expect(result.current).toStrictEqual({ | ||
isFetching: false, | ||
isLoading: false, | ||
userPermissions: ['permission name'], | ||
totalRecords: 1 | ||
}); | ||
}); | ||
}); |