-
Notifications
You must be signed in to change notification settings - Fork 0
#142 if user is verified after registration put the changes to the database #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IhorMasechko
wants to merge
23
commits into
main
Choose a base branch
from
142-if-user-is-verified-after-registration-put-the-changes-to-the-database
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
eab20aa
Added Gmail messenger
IhorMasechko a384c93
Merged with main branch
IhorMasechko f98d561
Merge branch 'main' into 142-if-user-is-verified-after-registration-p…
IhorMasechko 805fe25
Added mutation for the isVerified field
IhorMasechko 2f6e49a
Added a toaster and the option to log in during registration
IhorMasechko b4b3114
Merge branch 'main' into 142-if-user-is-verified-after-registration-p…
IhorMasechko 00078a2
Fixed jest test errors
IhorMasechko 69dc92b
Added jest test for the new code
IhorMasechko 9a696e5
Fixed test code
IhorMasechko 43cab36
Fixed lint error
IhorMasechko 0ff185b
Fixed Security Hotspots with password in test file
IhorMasechko e608ea1
Fixed password error in jest tests
IhorMasechko 82784e3
Fixed potentially hard-coded password
IhorMasechko bdbb985
Avoid duplication code
IhorMasechko cdedd9c
Fixed issues from Sonar
IhorMasechko 8c2f28d
Fixed Unexpected constant nullishness on the left-hand side of a exp…
IhorMasechko 767034c
Fix cross-site cookie issue for Keystone auth (SameSite/secure config)
IhorMasechko 1372736
Changed placeholder for the email verification component
IhorMasechko 8e10489
Merge branch 'main' into 142-if-user-is-verified-after-registration-p…
IhorMasechko 7fff76a
Fix keystone session
IhorMasechko b2b3b58
Fix statelessSessions
IhorMasechko 4e3df4a
Set isSecureEnv for the session
IhorMasechko 20a03aa
Merge branch 'main' into 142-if-user-is-verified-after-registration-p…
IhorMasechko 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
132 changes: 132 additions & 0 deletions
132
veterans/components/common/authForm/EmailVerification/EmailVerification.test.tsx
This file contains hidden or 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,132 @@ | ||
| import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import { useMutation, useQuery } from '@apollo/client'; | ||
| import { useRouter } from 'next/navigation'; | ||
| import { toast } from 'react-hot-toast'; | ||
| import EmailVerification from './EmailVerification'; | ||
|
|
||
| jest.mock('@apollo/client'); | ||
| jest.mock('next/navigation'); | ||
| jest.mock('react-hot-toast', () => ({ | ||
| toast: { | ||
| error: jest.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| describe('EmailVerification', () => { | ||
| const mockRouterPush = jest.fn(); | ||
| const mockUseQuery = useQuery as jest.Mock; | ||
| const mockUseMutation = useMutation as jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
|
|
||
| (useRouter as jest.Mock).mockReturnValue({ | ||
| push: mockRouterPush, | ||
| }); | ||
|
|
||
| mockUseQuery.mockReturnValue({ | ||
| data: { user: { id: '1' } }, | ||
| }); | ||
|
|
||
| mockUseMutation.mockReturnValue([jest.fn()]); | ||
| }); | ||
|
|
||
| it('renders the component correctly', () => { | ||
| render( | ||
| <EmailVerification verificationCode="1234" email="test@example.com" />, | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByPlaceholderText('Verification code'), | ||
| ).toBeInTheDocument(); | ||
| expect(screen.getByText('Verify your email address')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('handles invalid verification code', async () => { | ||
| render( | ||
| <EmailVerification verificationCode="1234" email="test@example.com" />, | ||
| ); | ||
|
|
||
| fireEvent.change(screen.getByPlaceholderText('Verification code'), { | ||
| target: { value: 'wrong-code' }, | ||
| }); | ||
|
|
||
| fireEvent.click(screen.getByText('Ok')); | ||
|
|
||
| await waitFor(() => | ||
| expect(toast.error).toHaveBeenCalledWith('Invalid verification code'), | ||
| ); | ||
| }); | ||
|
|
||
| it('successfully verifies the email and redirects', async () => { | ||
| const mockUpdateUserVerification = jest.fn().mockResolvedValue({ | ||
| data: { | ||
| updateUser: { isVerified: true }, | ||
| }, | ||
| }); | ||
| mockUseMutation.mockReturnValue([mockUpdateUserVerification]); | ||
|
|
||
| render( | ||
| <EmailVerification verificationCode="1234" email="test@example.com" />, | ||
| ); | ||
|
|
||
| fireEvent.change(screen.getByPlaceholderText('Verification code'), { | ||
| target: { value: '1234' }, | ||
| }); | ||
|
|
||
| fireEvent.click(screen.getByText('Ok')); | ||
|
|
||
| await waitFor(() => | ||
| expect(mockUpdateUserVerification).toHaveBeenCalledWith({ | ||
| variables: { id: '1', isVerified: true }, | ||
| }), | ||
| ); | ||
|
|
||
| expect(mockRouterPush).toHaveBeenCalledWith('/'); | ||
| }); | ||
|
|
||
| it('handles failed verification', async () => { | ||
| const mockUpdateUserVerification = jest.fn().mockResolvedValue({ | ||
| data: { | ||
| updateUser: { isVerified: false }, | ||
| }, | ||
| }); | ||
| mockUseMutation.mockReturnValue([mockUpdateUserVerification]); | ||
|
|
||
| render( | ||
| <EmailVerification verificationCode="1234" email="test@example.com" />, | ||
| ); | ||
|
|
||
| fireEvent.change(screen.getByPlaceholderText('Verification code'), { | ||
| target: { value: '1234' }, | ||
| }); | ||
|
|
||
| fireEvent.click(screen.getByText('Ok')); | ||
|
|
||
| await waitFor(() => | ||
| expect(toast.error).toHaveBeenCalledWith('Verification failed'), | ||
| ); | ||
| }); | ||
|
|
||
| it('handles mutation error', async () => { | ||
| const mockUpdateUserVerification = jest | ||
| .fn() | ||
| .mockRejectedValue(new Error('Network error')); | ||
| mockUseMutation.mockReturnValue([mockUpdateUserVerification]); | ||
|
|
||
| render( | ||
| <EmailVerification verificationCode="1234" email="test@example.com" />, | ||
| ); | ||
|
|
||
| fireEvent.change(screen.getByPlaceholderText('Verification code'), { | ||
| target: { value: '1234' }, | ||
| }); | ||
|
|
||
| fireEvent.click(screen.getByText('Ok')); | ||
|
|
||
| await waitFor(() => | ||
| expect(toast.error).toHaveBeenCalledWith('Network error'), | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.