From 0e79df53df5b263aae4c0ec21c00a74cd02a1dfd Mon Sep 17 00:00:00 2001 From: Ryan Berger Date: Fri, 14 Jun 2024 13:52:01 -0400 Subject: [PATCH] Fix unit tests and lint --- src/components/Root/FFetch.js | 4 ++-- src/components/Root/token-util.test.js | 15 ++++++++++----- src/components/SSOLanding/useSSOSession.js | 7 +++---- src/components/SSOLanding/useSSOSession.test.js | 9 ++++++++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/components/Root/FFetch.js b/src/components/Root/FFetch.js index b451b0cba..49adfc152 100644 --- a/src/components/Root/FFetch.js +++ b/src/components/Root/FFetch.js @@ -112,8 +112,8 @@ export class FFetch { rotationP.then((rotationInterval) => { this.logger.log('rtr', `rotation fired from rotateCallback; next callback in ${ms(rotationInterval)}`); this.store.dispatch(setRtrTimeout(setTimeout(() => { - const { okapi } = this.store.getState(); - rtr(this.nativeFetch, this.logger, this.rotateCallback, okapi); + const okapiStore = this.store.getState().okapi; + rtr(this.nativeFetch, this.logger, this.rotateCallback, okapiStore); }, rotationInterval))); }); }; diff --git a/src/components/Root/token-util.test.js b/src/components/Root/token-util.test.js index 4463ec97a..0ed8cc7fc 100644 --- a/src/components/Root/token-util.test.js +++ b/src/components/Root/token-util.test.js @@ -13,6 +13,11 @@ import { } from './token-util'; import { RTR_SUCCESS_EVENT } from './constants'; +const okapi = { + tenant: 'diku', + url: 'http://test' +}; + describe('isFolioApiRequest', () => { it('accepts requests whose origin matches okapi\'s', () => { const oUrl = 'https://millicent-sounds-kinda-like-malificent.edu'; @@ -126,7 +131,7 @@ describe('rtr', () => { let ex = null; // const callback = () => { console.log('HOLA!!!')}; // jest.fn(); try { - await rtr(fetchfx, logger, callback); + await rtr(fetchfx, logger, callback, okapi); expect(callback).toHaveBeenCalled(); } catch (e) { ex = e; @@ -168,7 +173,7 @@ describe('rtr', () => { let ex = null; try { - await rtr(nativeFetch, logger, jest.fn()); + await rtr(nativeFetch, logger, jest.fn(), okapi); } catch (e) { ex = e; } @@ -202,7 +207,7 @@ describe('rtr', () => { let ex = null; try { - await rtr(nativeFetch, logger, jest.fn()); + await rtr(nativeFetch, logger, jest.fn(), okapi); } catch (e) { ex = e; } @@ -232,7 +237,7 @@ describe('rtr', () => { let ex = null; try { - await rtr(nativeFetch, logger, jest.fn()); + await rtr(nativeFetch, logger, jest.fn(), okapi); } catch (e) { ex = e; } @@ -262,7 +267,7 @@ describe('rtr', () => { let ex = null; try { - await rtr(nativeFetch, logger, jest.fn()); + await rtr(nativeFetch, logger, jest.fn(), okapi); } catch (e) { ex = e; } diff --git a/src/components/SSOLanding/useSSOSession.js b/src/components/SSOLanding/useSSOSession.js index ce9383154..8e71b01c4 100644 --- a/src/components/SSOLanding/useSSOSession.js +++ b/src/components/SSOLanding/useSSOSession.js @@ -4,7 +4,7 @@ import { useLocation } from 'react-router-dom'; import { useCookies } from 'react-cookie'; import queryString from 'query-string'; -import { config } from 'stripes-config'; +import { config, okapi } from 'stripes-config'; import { defaultErrors } from '../../constants'; import { setAuthError } from '../../okapiActions'; @@ -23,8 +23,7 @@ const getToken = (cookies, params) => { return cookies?.ssoToken || params?.ssoToken; }; -const getTenant = (params, token) => { - const store = useStore(); +const getTenant = (params, token, store) => { const tenant = config.useSecureTokens ? params?.tenantId : parseJWT(token)?.tenant; @@ -43,7 +42,7 @@ const useSSOSession = () => { const params = getParams(location); const token = getToken(cookies, params); - const tenant = getTenant(params, token); + const tenant = getTenant(params, token, store); useEffect(() => { requestUserWithPerms(okapi.url, store, tenant, token) diff --git a/src/components/SSOLanding/useSSOSession.test.js b/src/components/SSOLanding/useSSOSession.test.js index 2a0e4cd0c..5216279af 100644 --- a/src/components/SSOLanding/useSSOSession.test.js +++ b/src/components/SSOLanding/useSSOSession.test.js @@ -51,7 +51,14 @@ describe('SSOLanding', () => { useLocation.mockReturnValue({ search: '' }); useCookies.mockReturnValue([]); - useStore.mockReturnValue({ getState: jest.fn() }); + useStore.mockReturnValue({ + getState: jest.fn().mockReturnValue({ + okapi: { + url: 'okapiUrl', + tenant: 'okapiTenant' + } + }) + }); requestUserWithPerms.mockReturnValue(Promise.resolve()); });