Skip to content

Commit

Permalink
Fix unit tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandberger committed Jun 14, 2024
1 parent 2c2e7a2 commit 0e79df5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/Root/FFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
});
};
Expand Down
15 changes: 10 additions & 5 deletions src/components/Root/token-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/SSOLanding/useSSOSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/components/SSOLanding/useSSOSession.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Check failure on line 59 in src/components/SSOLanding/useSSOSession.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Trailing spaces not allowed
})
});

requestUserWithPerms.mockReturnValue(Promise.resolve());
});
Expand Down

0 comments on commit 0e79df5

Please sign in to comment.