-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[STCOR-787] Always retrieve clientId and tenant values from config.te…
…nantOptions in stripes.config.js (#1487) * Retrieve clientId and tenant values from config.tenantOptions before login * Fix tenant gathering * Remove isSingleTenant param which is redundant * If user object not returned from local storage, then default user from /_self response * Update CHANGELOG.md * Revert PreLoginLanding which uses okapi values * Remove space * Rework flow to immediately set config to okapi for compatibility. * Lint fix * Fix unit test (cherry picked from commit e738a2f)
- Loading branch information
1 parent
b17e9ad
commit 2d712ea
Showing
7 changed files
with
134 additions
and
14 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
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