From a0decb70cca8c6c4606ab0239ebe338987fdf4d2 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Mon, 11 Nov 2024 13:48:02 +0000 Subject: [PATCH] test(user): write tests for updatePassword --- packages/backend/src/models/user.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/backend/src/models/user.test.js b/packages/backend/src/models/user.test.js index 9b5e140f..ed2f1805 100644 --- a/packages/backend/src/models/user.test.js +++ b/packages/backend/src/models/user.test.js @@ -580,4 +580,28 @@ describe('User model', () => { expect(refetchedUser.invitationTokenSentAt).toBe(null); expect(refetchedUser.status).toBe('active'); }); + + describe('updatePassword', () => { + it('should update password when the given current password matches with the user password', async () => { + const user = await createUser({ password: 'sample-password' }); + + const updatedUser = await user.updatePassword({ + currentPassword: 'sample-password', + password: 'new-password', + }); + + expect(await updatedUser.login('new-password')).toBe(true); + }); + + it('should throw validation error when the given current password does not match with the user password', async () => { + const user = await createUser({ password: 'sample-password' }); + + await expect( + user.updatePassword({ + currentPassword: 'wrong-password', + password: 'new-password', + }) + ).rejects.toThrowError('currentPassword: is incorrect.'); + }); + }); });