From 78edadf5361e402039d3ce0f5f1a83c8d8799640 Mon Sep 17 00:00:00 2001 From: David Inga Date: Thu, 21 Sep 2023 09:30:03 +0200 Subject: [PATCH] fixed profile form updated password --- client/CHANGELOG.md | 8 +++++- client/cypress/e2e/profile.cy.ts | 22 +++++++++++++++ .../update-password-form/component.tsx | 28 +++++++++++++------ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 client/cypress/e2e/profile.cy.ts diff --git a/client/CHANGELOG.md b/client/CHANGELOG.md index d813a8537..8be1fc18a 100644 --- a/client/CHANGELOG.md +++ b/client/CHANGELOG.md @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/). -## [v0.6.0 Unreleased] +## [Unreleased] + +### Fixed + +- Update password in profile form was not working as expected [LANDGRIF-1479](https://vizzuality.atlassian.net/browse/LANDGRIF-1479) + +## [v1.0.0] ### Added diff --git a/client/cypress/e2e/profile.cy.ts b/client/cypress/e2e/profile.cy.ts new file mode 100644 index 000000000..4ea791705 --- /dev/null +++ b/client/cypress/e2e/profile.cy.ts @@ -0,0 +1,22 @@ +describe('Profile', () => { + beforeEach(() => { + cy.login(); + }); + + afterEach(() => { + cy.logout(); + }); + + it('change password', () => { + cy.intercept('PATCH', '/api/v1/users/me/password', { + statusCode: 200, + body: {}, + }).as('updatePasswordRequest'); + cy.visit('/profile'); + + cy.get('[name="currentPassword"]').type(Cypress.env('PASSWORD')); + cy.get('[name="newPassword"]').type(Cypress.env('PASSWORD')); + cy.get('[name="passwordConfirmation"]').type(Cypress.env('PASSWORD')); + cy.get('button[data-testid="submit-update-password"]').click(); + }); +}); diff --git a/client/src/containers/update-password-form/component.tsx b/client/src/containers/update-password-form/component.tsx index 887244029..fcf82e653 100644 --- a/client/src/containers/update-password-form/component.tsx +++ b/client/src/containers/update-password-form/component.tsx @@ -32,15 +32,22 @@ const UserPasswordForm: React.FC = () => { const handleEditPassword = useCallback( (data: PasswordPayload) => { - updatePassword.mutate(data, { - onSuccess: () => { - toast.success('Your changes were successfully saved.'); + updatePassword.mutate( + { + // avoid passing passwordConfirmation to the API + currentPassword: data.currentPassword, + newPassword: data.newPassword, }, - onError: (error: ErrorResponse) => { - const { errors } = error.response?.data; - errors.forEach(({ title }) => toast.error(title)); + { + onSuccess: () => { + toast.success('Your changes were successfully saved.'); + }, + onError: (error: ErrorResponse) => { + const { errors } = error.response?.data; + errors.forEach(({ title }) => toast.error(title)); + }, }, - }); + ); }, [updatePassword], ); @@ -83,7 +90,12 @@ const UserPasswordForm: React.FC = () => {
-