-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(authorize): the authorize component was using the wrong axi struct
The Authorize Component calls the axiUserPermissiosn Api but expects a structure of the type sdk/permissions api returns.
- Loading branch information
1 parent
4766061
commit acb90b1
Showing
4 changed files
with
88 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,109 @@ | ||
import React from 'react'; | ||
import { render, cleanup } from 'react-testing-library'; | ||
import { render, cleanup, waitForElement } from 'react-testing-library'; | ||
import { avUserPermissionsApi } from '@availity/api-axios'; | ||
import Authorize from '..'; | ||
|
||
afterEach(cleanup); | ||
jest.mock('@availity/api-axios'); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
|
||
jest.clearAllMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
avUserPermissionsApi.getPermissions.mockResolvedValue([ | ||
{ | ||
id: '1234', | ||
organizationIds: ['1111'] | ||
}, | ||
]); | ||
}); | ||
|
||
describe('Authorize', () => { | ||
test('should render', () => { | ||
const { container } = render(<Authorize permissions="1234" loader />); | ||
test('should render authorized content', async () => { | ||
const { getByText } = render( | ||
<Authorize permissions="1234" loader> | ||
You have permission to see this | ||
</Authorize> | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
await waitForElement(() => getByText('You have permission to see this')); | ||
}); | ||
|
||
test('should render with single permission', () => { | ||
const { container } = render( | ||
test('should render authorized content', async () => { | ||
const { getByText } = render( | ||
<Authorize | ||
permissions="1234" | ||
permissions="12345" | ||
unauthorized="You do not have permission to see this" | ||
/> | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
await waitForElement(() => | ||
getByText('You do not have permission to see this') | ||
); | ||
}); | ||
|
||
test('should render with array of permissions', () => { | ||
const { container } = render( | ||
test('should render authorized with array of permissions', async () => { | ||
const { getByText } = render( | ||
<Authorize | ||
permissions={['1234', 2345, [3456, '4567']]} | ||
unauthorized="You do not have permission to see this" | ||
/> | ||
> | ||
You have permission to see this | ||
</Authorize> | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
await waitForElement(() => getByText('You have permission to see this')); | ||
}); | ||
|
||
test('should render negate permissions', () => { | ||
const { container } = render( | ||
test('should render negate permissions', async () => { | ||
const { getByText } = render( | ||
<Authorize | ||
permissions="1234" | ||
negate | ||
unauthorized="You do not have permission to see this" | ||
> | ||
You can see this | ||
You have permission to see this | ||
</Authorize> | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
await waitForElement(() => | ||
getByText('You do not have permission to see this') | ||
); | ||
}); | ||
|
||
test('should render authorized with correct organizationId', async () => { | ||
const { getByText } = render( | ||
<Authorize | ||
permissions="1234" | ||
organizationId="1111" | ||
negate | ||
unauthorized="You do not have permission to see this" | ||
> | ||
You have permission to see this | ||
</Authorize> | ||
); | ||
|
||
await waitForElement(() => | ||
getByText('You have permission to see this') | ||
); | ||
}); | ||
|
||
test('should render unauthorized with incorrect organizationId', async () => { | ||
const { getByText } = render( | ||
<Authorize | ||
permissions="1234" | ||
organizationId="1112" | ||
negate | ||
unauthorized="You do not have permission to see this" | ||
> | ||
You have permission to see this | ||
</Authorize> | ||
); | ||
|
||
await waitForElement(() => | ||
getByText('You do not have permission to see this') | ||
); | ||
}); | ||
}); |
56 changes: 0 additions & 56 deletions
56
packages/authorize/tests/__snapshots__/Authorize.test.js.snap
This file was deleted.
Oops, something went wrong.