mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
fix: Change update user routes to use PUT instead of POST
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('PUT /user/update-password', async () => {
|
||||
let endpoint = '/user/update-password';
|
||||
let user;
|
||||
let password = 'password';
|
||||
let wrongPassword = 'wrong-password';
|
||||
let newPassword = 'new-password';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('successfully changes the password', async () => {
|
||||
let previousHashedPassword = user.auth.local.hashed_password;
|
||||
let response = await user.put(endpoint, {
|
||||
password,
|
||||
newPassword,
|
||||
confirmPassword: newPassword,
|
||||
});
|
||||
expect(response).to.eql({});
|
||||
await user.sync();
|
||||
expect(user.auth.local.hashed_password).to.not.eql(previousHashedPassword);
|
||||
});
|
||||
|
||||
it('new passwords mismatch', async () => {
|
||||
await expect(user.put(endpoint, {
|
||||
password,
|
||||
newPassword,
|
||||
confirmPassword: `${newPassword}-wrong-confirmation`,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('passwordConfirmationMatch'),
|
||||
});
|
||||
});
|
||||
|
||||
it('existing password is wrong', async () => {
|
||||
await expect(user.put(endpoint, {
|
||||
password: wrongPassword,
|
||||
newPassword,
|
||||
confirmPassword: newPassword,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('wrongPassword'),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user