-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[STCOR-787] Always retrieve clientId and tenant values from config.tenantOptions in stripes.config.js #1487
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
03717a8
Retrieve clientId and tenant values from config.tenantOptions before …
ryandberger 4e6ffaa
Fix tenant gathering
ryandberger 03d2fe4
Remove isSingleTenant param which is redundant
ryandberger 08a06eb
Merge branch 'keycloak-ramsons' into STCOR-787
ryandberger 6697a8e
If user object not returned from local storage, then default user fro…
ryandberger c35d977
Update CHANGELOG.md
ryandberger b52a248
Revert PreLoginLanding which uses okapi values
ryandberger 420c16e
Merge branch 'STCOR-787' of https://github.com/folio-org/stripes-core…
ryandberger e5c73eb
Remove space
ryandberger 1b1a71b
Rework flow to immediately set config to okapi for compatibility.
ryandberger d2f03a0
Lint fix
ryandberger 9ce0d04
Fix unit test
ryandberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { render, screen, waitFor } from '@folio/jest-config-stripes/testing-library/react'; | ||
|
||
import OIDCLanding from './OIDCLanding'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
useLocation: () => ({ | ||
search: 'session_state=dead-beef&code=c0ffee' | ||
}), | ||
Redirect: () => <>Redirect</>, | ||
})); | ||
|
||
jest.mock('react-redux', () => ({ | ||
useStore: () => { }, | ||
})); | ||
|
||
jest.mock('../StripesContext', () => ({ | ||
useStripes: () => ({ | ||
okapi: { url: 'https://whaterver' }, | ||
config: { tenantOptions: { diku: { name: 'diku', clientId: 'diku-application' } } }, | ||
}), | ||
})); | ||
|
||
// jest.mock('../loginServices'); | ||
|
||
|
||
const mockSetTokenExpiry = jest.fn(); | ||
const mockRequestUserWithPerms = jest.fn(); | ||
const mockFoo = jest.fn(); | ||
jest.mock('../loginServices', () => ({ | ||
setTokenExpiry: () => mockSetTokenExpiry(), | ||
requestUserWithPerms: () => mockRequestUserWithPerms(), | ||
foo: () => mockFoo(), | ||
})); | ||
|
||
|
||
// fetch success: resolve promise with ok == true and $data in json() | ||
const mockFetchSuccess = (data) => { | ||
global.fetch = jest.fn().mockImplementation(() => ( | ||
Promise.resolve({ | ||
ok: true, | ||
json: () => Promise.resolve(data), | ||
headers: new Map(), | ||
}) | ||
)); | ||
}; | ||
|
||
// fetch failure: resolve promise with ok == false and $error in json() | ||
const mockFetchError = (error) => { | ||
global.fetch = jest.fn().mockImplementation(() => ( | ||
Promise.resolve({ | ||
ok: false, | ||
json: () => Promise.resolve(error), | ||
headers: new Map(), | ||
}) | ||
)); | ||
}; | ||
|
||
// restore default fetch impl | ||
const mockFetchCleanUp = () => { | ||
global.fetch.mockClear(); | ||
delete global.fetch; | ||
}; | ||
|
||
describe('OIDCLanding', () => { | ||
it('calls requestUserWithPerms, setTokenExpiry on success', async () => { | ||
mockFetchSuccess({ | ||
accessTokenExpiration: '2024-05-23T09:47:17.000-04:00', | ||
refreshTokenExpiration: '2024-05-23T10:07:17.000-04:00', | ||
}); | ||
|
||
await render(<OIDCLanding />); | ||
screen.getByText('Loading'); | ||
await waitFor(() => expect(mockSetTokenExpiry).toHaveBeenCalledTimes(1)); | ||
await waitFor(() => expect(mockRequestUserWithPerms).toHaveBeenCalledTimes(1)); | ||
mockFetchCleanUp(); | ||
}); | ||
|
||
it('displays an error on failure', async () => { | ||
mockFetchError('barf'); | ||
|
||
await render(<OIDCLanding />); | ||
await screen.findByText('errors.saml.missingToken'); | ||
mockFetchCleanUp(); | ||
}); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I've seen this too but not been able to figure out how things get into this state. It is mitigated in the community builds in #1466.