Skip to content

Commit

Permalink
additional test corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
zburke committed Sep 13, 2024
1 parent 2106d9c commit e08f5de
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/components/SessionEventContainer/SessionEventContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import SessionEventContainer, {
thisWindowRtrError,
thisWindowRtrIstTimeout,
} from './SessionEventContainer';
import { SESSION_NAME } from '../../loginServices';
import {
logout,
setUnauthorizedPathToSession,
SESSION_NAME
} from '../../loginServices';
import { RTR_TIMEOUT_EVENT } from '../Root/constants';

import { toggleRtrModal } from '../../okapiActions';
Expand Down Expand Up @@ -69,8 +73,16 @@ describe('SessionEventContainer', () => {
describe('SessionEventContainer event listeners', () => {
it('thisWindowRtrError', async () => {
const history = { push: jest.fn() };
const logoutMock = logout;
logoutMock.mockReturnValue(Promise.resolve());

thisWindowRtrError(null, { okapi: { url: 'http' } }, history);
const setUnauthorizedPathToSessionMock = setUnauthorizedPathToSession;
setUnauthorizedPathToSessionMock.mockReturnValue(null);

await thisWindowRtrError(null, { okapi: { url: 'http' } }, history);

expect(logout).toHaveBeenCalled();
expect(setUnauthorizedPathToSession).toHaveBeenCalled();
expect(history.push).toHaveBeenCalledWith('/logout-timeout');
});

Expand All @@ -87,7 +99,12 @@ describe('SessionEventContainer event listeners', () => {

const history = { push: jest.fn() };

thisWindowRtrIstTimeout(null, s, history);
const setUnauthorizedPathToSessionMock = setUnauthorizedPathToSession;
setUnauthorizedPathToSessionMock.mockReturnValue(null);

await thisWindowRtrIstTimeout(null, s, history);
expect(logout).toHaveBeenCalled();
expect(setUnauthorizedPathToSession).toHaveBeenCalled();
expect(history.push).toHaveBeenCalledWith('/logout-timeout');
});

Expand All @@ -108,8 +125,13 @@ describe('SessionEventContainer event listeners', () => {
}
};
const history = { push: jest.fn() };
const qc = {};
const setUnauthorizedPathToSessionMock = setUnauthorizedPathToSession;
setUnauthorizedPathToSessionMock.mockReturnValue(null);

otherWindowStorage(e, s, history);
await otherWindowStorage(e, s, history, qc);
expect(logout).toHaveBeenCalledWith(s.okapi.url, s.store, qc);
expect(setUnauthorizedPathToSession).toHaveBeenCalled();
expect(history.push).toHaveBeenCalledWith('/logout-timeout');
});

Expand All @@ -125,8 +147,10 @@ describe('SessionEventContainer event listeners', () => {
}
};
const history = { push: jest.fn() };
const qc = {};

otherWindowStorage(e, s, history);
await otherWindowStorage(e, s, history, qc);
expect(logout).toHaveBeenCalledWith(s.okapi.url, s.store, qc);
expect(history.push).toHaveBeenCalledWith('/logout');
});
});
Expand Down

0 comments on commit e08f5de

Please sign in to comment.