Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath committed Apr 9, 2021
1 parent fad8444 commit 8382c3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions tests/frontend/with-page-auth-required.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ describe('with-page-auth-required csr', () => {
const ProtectedPage = withPageAuthRequired(MyPage, { returnTo: '/foo' });

render(<ProtectedPage />, { wrapper: withUserProvider() });
await waitFor(() => expect(window.location.assign).toHaveBeenCalledWith(expect.stringContaining('?returnTo=/foo')));
await waitFor(() =>
expect(window.location.assign).toHaveBeenCalledWith(
expect.stringContaining(`?returnTo=${encodeURIComponent('/foo')}`)
)
);
});

it('should use a custom login url', async () => {
Expand All @@ -117,7 +121,9 @@ describe('with-page-auth-required csr', () => {

render(<ProtectedPage />, { wrapper: withUserProvider() });
await waitFor(() =>
expect(window.location.assign).toHaveBeenCalledWith(expect.stringContaining('?returnTo=/foo/bar'))
expect(window.location.assign).toHaveBeenCalledWith(
expect.stringContaining(`?returnTo=${encodeURIComponent('/foo/bar')}`)
)
);
routerMock.basePath = basePath;
routerMock.asPath = asPath;
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/with-page-auth-required.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('with-page-auth-required ssr', () => {
res: { statusCode, headers }
} = await get(baseUrl, '/protected', { fullResponse: true });
expect(statusCode).toBe(307);
expect(headers.location).toBe('/api/auth/login?returnTo=/protected');
expect(decodeURIComponent(headers.location)).toBe('/api/auth/login?returnTo=/protected');
});

test('allow access to a page with a valid session', async () => {
Expand All @@ -32,7 +32,7 @@ describe('with-page-auth-required ssr', () => {
res: { statusCode, headers }
} = await get(baseUrl, '/protected', { fullResponse: true });
expect(statusCode).toBe(307);
expect(headers.location).toBe('/api/auth/login?returnTo=/foo');
expect(decodeURIComponent(headers.location)).toBe('/api/auth/login?returnTo=/foo');
});

test('accept custom server-side props', async () => {
Expand All @@ -57,7 +57,7 @@ describe('with-page-auth-required ssr', () => {
res: { statusCode, headers }
} = await get(baseUrl, '/protected', { fullResponse: true });
expect(statusCode).toBe(307);
expect(headers.location).toBe('/api/foo?returnTo=/protected');
expect(decodeURIComponent(headers.location)).toBe('/api/foo?returnTo=/protected');
delete process.env.NEXT_PUBLIC_AUTH0_LOGIN;
});

Expand Down

0 comments on commit 8382c3d

Please sign in to comment.