-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29922d4
commit 6d07f35
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.test.js
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 |
---|---|---|
@@ -1,12 +1,56 @@ | ||
import queryString from 'query-string'; | ||
|
||
import { renderHook } from '@folio/jest-config-stripes/testing-library/react'; | ||
import { useStripes } from '@folio/stripes/core'; | ||
import { | ||
SEARCH_INDEX_PARAMETER, | ||
SEARCH_PARAMETER, | ||
} from '@folio/stripes-acq-components'; | ||
|
||
import { useBuildQuery } from './useBuildQuery'; | ||
|
||
jest.mock('@folio/stripes/core', () => ({ | ||
...jest.requireActual('@folio/stripes/core'), | ||
useStripes: jest.fn(), | ||
})); | ||
|
||
const stripesStub = { | ||
hasPerm: jest.fn(() => true), | ||
}; | ||
|
||
describe('useBuildQuery', () => { | ||
beforeEach(() => { | ||
stripesStub.hasPerm.mockClear(); | ||
|
||
useStripes | ||
.mockClear() | ||
.mockReturnValue(stripesStub); | ||
}); | ||
|
||
it('should return function, that return query', () => { | ||
const { result } = renderHook(() => useBuildQuery()); | ||
|
||
expect(result.current(queryString.parse('?foo=bar'))).toBe('(foo=="bar") sortby name/sort.ascending'); | ||
}); | ||
|
||
describe('Banking information', () => { | ||
const params = { | ||
[SEARCH_PARAMETER]: 'qwerty', | ||
[SEARCH_INDEX_PARAMETER]: 'name', | ||
}; | ||
|
||
it('should include banking information index in the query if a user has the appropriate permission', () => { | ||
const { result } = renderHook(() => useBuildQuery()); | ||
|
||
expect(result.current(params)).toEqual(expect.stringContaining('bankingInformation.bankAccountNumber="qwerty*"')); | ||
}); | ||
|
||
it('should NOT include banking information index in the query if a user does not have the appropriate permission', async () => { | ||
stripesStub.hasPerm.mockReturnValue(false); | ||
|
||
const { result } = renderHook(() => useBuildQuery()); | ||
|
||
expect(result.current(params)).toEqual(expect.not.stringContaining('bankingInformation.bankAccountNumber="qwerty*"')); | ||
}); | ||
}); | ||
}); |