Skip to content

Commit

Permalink
added test for forgotten password
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsingal committed Sep 20, 2023
1 parent 592e791 commit 5cf32d4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
49 changes: 49 additions & 0 deletions client/cypress/e2e/forgot-password.cy.ts
Original file line number Diff line number Diff line change
@@ -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']);
});
});
4 changes: 2 additions & 2 deletions client/src/pages/auth/reset-password/[token].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ResetPassword: NextPageWithLayout = () => {
const { mutate: resetPassword, isLoading } = useResetPassword();
const [isRedirecting, setIsRedirecting] = useState<boolean>(false);

const handleResetPassord = useCallback(
const handleResetPassword = useCallback(
({ password }: yup.InferType<typeof schemaValidation>) => {
const token = query?.token as string;
if (!token) {
Expand Down Expand Up @@ -89,7 +89,7 @@ const ResetPassword: NextPageWithLayout = () => {
noValidate
className="space-y-6"
id="signInForm"
onSubmit={handleSubmit(handleResetPassord)}
onSubmit={handleSubmit(handleResetPassword)}
>
<div>
<Label htmlFor="password">New Password</Label>
Expand Down

0 comments on commit 5cf32d4

Please sign in to comment.