test(user): write tests for updatePassword

This commit is contained in:
Ali BARIN
2024-11-11 13:48:02 +00:00
committed by Faruk AYDIN
parent abf30dfc1a
commit a0decb70cc

View File

@@ -580,4 +580,28 @@ describe('User model', () => {
expect(refetchedUser.invitationTokenSentAt).toBe(null); expect(refetchedUser.invitationTokenSentAt).toBe(null);
expect(refetchedUser.status).toBe('active'); 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.');
});
});
}); });