diff --git a/client/cypress/e2e/forgot-password.cy.ts b/client/cypress/e2e/forgot-password.cy.ts new file mode 100644 index 000000000..e248819ad --- /dev/null +++ b/client/cypress/e2e/forgot-password.cy.ts @@ -0,0 +1,49 @@ +describe('Forgot password', () => { + afterEach(() => { + cy.logout(); + }); + + it('request recover password', () => { + cy.intercept('POST', '/api/v1/users/me/password/recover', { + statusCode: 201, + body: {}, + }).as('recoverPasswordRequest'); + + cy.visit('/auth/forgot-password'); + // Input the email + cy.get('[name="email"]').type(Cypress.env('USERNAME')); + cy.get('button[type="submit"]').click(); + + // Show success message + cy.wait('@recoverPasswordRequest').then(() => { + cy.get('h2').should('have.text', 'Check your email'); + }); + }); + + it('reset password', () => { + const fakeToken = 'nyancat'; + + cy.intercept('POST', '/api/v1/users/me/password/reset', { + statusCode: 201, + fixture: 'auth/me.json', + }).as('resetPasswordRequest'); + + cy.intercept('GET', '/api/auth/session', { + fixture: 'auth/session.json', + }).as('session'); + + cy.intercept('GET', '/api/v1/users/me', { + fixture: 'auth/me.json', + }); + + cy.visit(`/auth/reset-password/${fakeToken}`); + + // Input the new password + cy.get('[name="password"]').type(Cypress.env('PASSWORD')); + cy.get('[name="passwordConfirmation"]').type(Cypress.env('PASSWORD')); + cy.get('button[type="submit"]').click(); + + // Redirect to the map once the password is reset + cy.wait(['@resetPasswordRequest', '@session']); + }); +}); diff --git a/client/src/pages/auth/reset-password/[token].tsx b/client/src/pages/auth/reset-password/[token].tsx index 6b371a097..2b3ba7263 100644 --- a/client/src/pages/auth/reset-password/[token].tsx +++ b/client/src/pages/auth/reset-password/[token].tsx @@ -37,7 +37,7 @@ const ResetPassword: NextPageWithLayout = () => { const { mutate: resetPassword, isLoading } = useResetPassword(); const [isRedirecting, setIsRedirecting] = useState(false); - const handleResetPassord = useCallback( + const handleResetPassword = useCallback( ({ password }: yup.InferType) => { const token = query?.token as string; if (!token) { @@ -89,7 +89,7 @@ const ResetPassword: NextPageWithLayout = () => { noValidate className="space-y-6" id="signInForm" - onSubmit={handleSubmit(handleResetPassord)} + onSubmit={handleSubmit(handleResetPassword)} >