This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Refactor auth and enable static file serving #577
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5533c70
Rewrite auth
elliotbonneville a1e054b
Remove unnecessary API files
elliotbonneville 7555497
Improve error handling in new user creation
elliotbonneville ac050e6
Enable static build export and serving
elliotbonneville 190a741
Remove next-redux-wrapper
elliotbonneville c0876d0
Correct breaking ESLint file
elliotbonneville 3760c8b
Clean up linting errors
elliotbonneville 156647c
Clean up merge artifacts
elliotbonneville 1aac32e
Update existing tests to use new auth
elliotbonneville 09b8925
Implement auth testing
elliotbonneville 8855660
Cleanup merge artifact
elliotbonneville 75fbdd0
Cleanup merge artifacts
elliotbonneville 0439fe9
Update Subject Requests detail page to use new auth
elliotbonneville 0148c81
Update docs and changelog
elliotbonneville d3e351d
Stop colocating tests in pages/ directory
elliotbonneville 819d657
Require authentication for request details page
elliotbonneville 673548f
Update error logging to use console.error
elliotbonneville 4564194
Improve privacy request details page loading sequence
elliotbonneville e76cd24
Remove extraneous comment
elliotbonneville 13176a4
Merge branch 'main' into feature/refactor-auth
elliotbonneville File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = { | ||
extends: [ | ||
'airbnb', | ||
'airbnb-typescript/base', | ||
'prettier', | ||
'next/core-web-vitals', | ||
], | ||
plugins: ['simple-import-sort'], | ||
root: true, | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
}, | ||
rules: { | ||
// causes bug in re-exporting default exports, see | ||
// https://github.com/eslint/eslint/issues/15617 | ||
'no-restricted-exports': [0], | ||
'react/function-component-definition': [ | ||
2, | ||
{ | ||
namedComponents: 'arrow-function', | ||
}, | ||
], | ||
'react/jsx-filename-extension': [1, { extensions: ['.tsx'] }], | ||
'react/jsx-props-no-spreading': [0], | ||
'simple-import-sort/imports': 'error', | ||
'simple-import-sort/exports': 'error', | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ typings/ | |
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
// __tests__/index.test.tsx | ||
import { SessionProvider } from 'next-auth/react'; | ||
|
||
import Home from '../src/pages/index'; | ||
import { render, screen } from './test-utils'; | ||
|
||
describe('Home', () => { | ||
it('renders the Subject Requests page by default', () => { | ||
render( | ||
<SessionProvider> | ||
<Home /> | ||
</SessionProvider> | ||
); | ||
it('renders the Subject Requests page by default when logged in', () => { | ||
render(<Home />, { | ||
preloadedState: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whoa this is very cool 🤩 |
||
auth: { | ||
user: { | ||
username: 'Test', | ||
}, | ||
token: 'valid-token', | ||
}, | ||
}, | ||
}); | ||
|
||
const message = screen.getAllByText('Subject Requests')[0]; | ||
expect(message).toBeInTheDocument(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { rest } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
|
||
import LoginPage from '../../src/pages/login'; | ||
import { act, fireEvent, render, screen, waitFor } from '../test-utils'; | ||
|
||
const useRouter = jest.spyOn(require('next/router'), 'useRouter'); | ||
|
||
afterAll(() => { | ||
useRouter.mockRestore(); | ||
}); | ||
|
||
describe('/login', () => { | ||
it('Should redirect when the user logs in successfully', async () => { | ||
const server = setupServer( | ||
rest.post(`/login`, (req, res, ctx) => | ||
res( | ||
ctx.json({ | ||
user_data: { | ||
username: 'Test', | ||
}, | ||
token_data: { | ||
access_token: 'test-access-token', | ||
}, | ||
}) | ||
) | ||
) | ||
); | ||
|
||
server.listen(); | ||
|
||
const push = jest.fn(); | ||
useRouter.mockImplementation(() => ({ | ||
push, | ||
})); | ||
|
||
await act(async () => { | ||
render(<LoginPage />); | ||
}); | ||
|
||
expect(push).toBeCalledTimes(0); | ||
|
||
const email = screen.getByRole('textbox', { name: /email/i }); | ||
const passwordInput = screen.getByLabelText(/password/i); | ||
const loginButton = screen.getByRole('button'); | ||
|
||
await act(async () => { | ||
await fireEvent.change(email, { target: { value: 'test-user' } }); | ||
await fireEvent.change(passwordInput, { | ||
target: { value: 'test-user-password' }, | ||
}); | ||
await fireEvent.submit(loginButton); | ||
}); | ||
|
||
await waitFor(() => expect(push).toHaveBeenCalledTimes(1)); | ||
expect(push).toHaveBeenCalledWith('/'); | ||
|
||
server.close(); | ||
}); | ||
|
||
it('Should redirect to "/" when the user is already logged in', async () => { | ||
await act(async () => { | ||
const push = jest.fn(); | ||
useRouter.mockImplementation(() => ({ | ||
push, | ||
})); | ||
|
||
await act(async () => { | ||
render(<LoginPage />, { | ||
preloadedState: { | ||
auth: { | ||
user: { | ||
username: 'Test User', | ||
}, | ||
token: 'valid-token', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
expect(push).toHaveBeenCalledWith('/'); | ||
expect(push).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
// test-utils.jsx | ||
import { Store } from '@reduxjs/toolkit'; | ||
import { render as rtlRender, RenderOptions } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import { AppState, AppStore, makeStore } from '../src/app/store'; | ||
import { makeStore, RootState } from '../src/app/store'; | ||
|
||
type CustomRenderOptions = { | ||
preloadedState?: AppState; | ||
store?: AppStore; | ||
preloadedState?: Partial<RootState>; | ||
customStore?: Store; | ||
} & RenderOptions; | ||
|
||
function render( | ||
ui: React.ReactElement<any, string | React.JSXElementConstructor<any>>, | ||
{ | ||
preloadedState, | ||
store = makeStore(preloadedState), | ||
customStore = makeStore(preloadedState), | ||
...renderOptions | ||
}: CustomRenderOptions = {} | ||
) { | ||
const Wrapper: React.FC = ({ children }) => ( | ||
<Provider store={store}>{children}</Provider> | ||
<Provider store={customStore}>{children}</Provider> | ||
); | ||
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions }); | ||
} | ||
|
||
// re-export everything | ||
export * from '@testing-library/react'; | ||
|
||
// override render method | ||
export { render }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the .env.local file no longer needed for auth to work properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. This was an artifact of the previous library, which we're no longer using.