-
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.
UIORGS-392 Search organization on bank account number (#585)
* UIORGS-392 Search organization on bank account number * add tests * fix lint issue * comment
- Loading branch information
1 parent
9928d2e
commit cf2c36c
Showing
5 changed files
with
58 additions
and
7 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
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
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
48 changes: 46 additions & 2 deletions
48
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'); | ||
expect(result.current({ | ||
[SEARCH_PARAMETER]: 'bar', | ||
[SEARCH_INDEX_PARAMETER]: 'foo', | ||
})).toBe('(((foo=bar*))) sortby name/sort.ascending'); | ||
}); | ||
|
||
describe('Banking information', () => { | ||
const params = { | ||
[SEARCH_PARAMETER]: 'qwerty', | ||
}; | ||
|
||
it('should include banking information index in the query if a user has the appropriate permission', () => { | ||
const { result } = renderHook(() => useBuildQuery()); | ||
|
||
expect(result.current(params)).toContain('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)).not.toContain('bankingInformation.bankAccountNumber="qwerty*"'); | ||
}); | ||
}); | ||
}); |
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