fix: Fix redirect loop (#676)

MICROBA-1523
This commit is contained in:
Thomas Tracy
2021-10-07 16:35:08 -04:00
committed by GitHub
parent 1f7cb2cc28
commit 09072f318b
2 changed files with 3 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ const NoticesProvider = ({ children }) => {
useEffect(async () => {
if (getConfig().ENABLE_NOTICES) {
const data = await getNotices();
if (data && data.results) {
if (data && data.results && data.results.length > 0) {
const { results } = data;
setIsRedirected(true);
window.location.replace(`${results[0]}?next=${window.location.href}`);

View File

@@ -44,7 +44,7 @@ describe('NoticesProvider', () => {
delete window.location;
window.location = { replace: jest.fn() };
process.env.ENABLE_NOTICES = true;
await act(() => buildAndRender());
await act(async () => buildAndRender());
expect(window.location.replace).toHaveBeenCalledWith(`${redirectUrl}?next=${window.location.href}`);
});
@@ -54,7 +54,7 @@ describe('NoticesProvider', () => {
delete window.location;
window.location = { replace: jest.fn() };
process.env.ENABLE_NOTICES = true;
await act(() => buildAndRender());
await act(async () => buildAndRender());
expect(window.location.replace).toHaveBeenCalledTimes(0);
expect(window.location.toString() === 'http://localhost/');
});