Skip to content

Commit

Permalink
add tests for useUserTenantPermissions
Browse files Browse the repository at this point in the history
  • Loading branch information
aidynoJ committed Jul 9, 2024
1 parent 9d07a1e commit 4d5a9a0
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/hooks/useUserTenantPermissions.test.js
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
});
});
});

0 comments on commit 4d5a9a0

Please sign in to comment.