mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix: Change update user routes to use PUT instead of POST
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
|||||||
} from '../../../../helpers/api-v3-integration.helper';
|
} from '../../../../helpers/api-v3-integration.helper';
|
||||||
import { model as User } from '../../../../../website/src/models/user';
|
import { model as User } from '../../../../../website/src/models/user';
|
||||||
|
|
||||||
describe('POST /user/update-email', () => {
|
describe('PUT /user/update-email', () => {
|
||||||
let user;
|
let user;
|
||||||
let fbUser;
|
let fbUser;
|
||||||
let endpoint = '/user/update-email';
|
let endpoint = '/user/update-email';
|
||||||
@@ -17,7 +17,7 @@ describe('POST /user/update-email', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not change email if one is not provided', async () => {
|
it('does not change email if one is not provided', async () => {
|
||||||
await expect(user.post(endpoint)).to.eventually.be.rejected.and.eql({
|
await expect(user.put(endpoint)).to.eventually.be.rejected.and.eql({
|
||||||
code: 400,
|
code: 400,
|
||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
message: t('invalidReqParams'),
|
message: t('invalidReqParams'),
|
||||||
@@ -25,7 +25,7 @@ describe('POST /user/update-email', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not change email if password is not provided', async () => {
|
it('does not change email if password is not provided', async () => {
|
||||||
await expect(user.post(endpoint, {
|
await expect(user.put(endpoint, {
|
||||||
newEmail,
|
newEmail,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
code: 400,
|
code: 400,
|
||||||
@@ -35,7 +35,7 @@ describe('POST /user/update-email', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not change email if wrong password is provided', async () => {
|
it('does not change email if wrong password is provided', async () => {
|
||||||
await expect(user.post(endpoint, {
|
await expect(user.put(endpoint, {
|
||||||
newEmail,
|
newEmail,
|
||||||
password: 'wrong password',
|
password: 'wrong password',
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
@@ -46,7 +46,7 @@ describe('POST /user/update-email', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('changes email if new email and existing password are provided', async () => {
|
it('changes email if new email and existing password are provided', async () => {
|
||||||
let response = await user.post(endpoint, {
|
let response = await user.put(endpoint, {
|
||||||
newEmail,
|
newEmail,
|
||||||
password: thePassword,
|
password: thePassword,
|
||||||
});
|
});
|
||||||
@@ -64,7 +64,7 @@ describe('POST /user/update-email', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not change email if user.auth.local.email does not exist for this user', async () => {
|
it('does not change email if user.auth.local.email does not exist for this user', async () => {
|
||||||
await expect(fbUser.post(endpoint, {
|
await expect(fbUser.put(endpoint, {
|
||||||
newEmail,
|
newEmail,
|
||||||
password: thePassword,
|
password: thePassword,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../../helpers/api-integration/v3';
|
} from '../../../../helpers/api-integration/v3';
|
||||||
|
|
||||||
describe('POST /user/update-password', async () => {
|
describe('PUT /user/update-password', async () => {
|
||||||
let endpoint = '/user/update-password';
|
let endpoint = '/user/update-password';
|
||||||
let user;
|
let user;
|
||||||
let password = 'password';
|
let password = 'password';
|
||||||
@@ -16,7 +16,7 @@ describe('POST /user/update-password', async () => {
|
|||||||
|
|
||||||
it('successfully changes the password', async () => {
|
it('successfully changes the password', async () => {
|
||||||
let previousHashedPassword = user.auth.local.hashed_password;
|
let previousHashedPassword = user.auth.local.hashed_password;
|
||||||
let response = await user.post(endpoint, {
|
let response = await user.put(endpoint, {
|
||||||
password,
|
password,
|
||||||
newPassword,
|
newPassword,
|
||||||
confirmPassword: newPassword,
|
confirmPassword: newPassword,
|
||||||
@@ -27,7 +27,7 @@ describe('POST /user/update-password', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('new passwords mismatch', async () => {
|
it('new passwords mismatch', async () => {
|
||||||
await expect(user.post(endpoint, {
|
await expect(user.put(endpoint, {
|
||||||
password,
|
password,
|
||||||
newPassword,
|
newPassword,
|
||||||
confirmPassword: `${newPassword}-wrong-confirmation`,
|
confirmPassword: `${newPassword}-wrong-confirmation`,
|
||||||
@@ -39,7 +39,7 @@ describe('POST /user/update-password', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('existing password is wrong', async () => {
|
it('existing password is wrong', async () => {
|
||||||
await expect(user.post(endpoint, {
|
await expect(user.put(endpoint, {
|
||||||
password: wrongPassword,
|
password: wrongPassword,
|
||||||
newPassword,
|
newPassword,
|
||||||
confirmPassword: newPassword,
|
confirmPassword: newPassword,
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
} from '../../../../helpers/api-integration/v3';
|
} from '../../../../helpers/api-integration/v3';
|
||||||
import { model as User } from '../../../../../website/src/models/user';
|
import { model as User } from '../../../../../website/src/models/user';
|
||||||
|
|
||||||
describe('POST /user/update-username', async () => {
|
describe('PUT /user/update-username', async () => {
|
||||||
let endpoint = '/user/update-username';
|
let endpoint = '/user/update-username';
|
||||||
let user;
|
let user;
|
||||||
let newUsername = 'new-username';
|
let newUsername = 'new-username';
|
||||||
@@ -17,7 +17,7 @@ describe('POST /user/update-username', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('successfully changes username', async () => {
|
it('successfully changes username', async () => {
|
||||||
let response = await user.post(endpoint, {
|
let response = await user.put(endpoint, {
|
||||||
username: newUsername,
|
username: newUsername,
|
||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
@@ -32,8 +32,9 @@ describe('POST /user/update-username', async () => {
|
|||||||
user = await generateUser();
|
user = await generateUser();
|
||||||
await user.update({'auth.local.username': existingUsername, 'auth.local.lowerCaseUsername': existingUsername });
|
await user.update({'auth.local.username': existingUsername, 'auth.local.lowerCaseUsername': existingUsername });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prevents username update', async () => {
|
it('prevents username update', async () => {
|
||||||
await expect(user.post(endpoint, {
|
await expect(user.put(endpoint, {
|
||||||
username: existingUsername,
|
username: existingUsername,
|
||||||
password,
|
password,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
@@ -43,8 +44,9 @@ describe('POST /user/update-username', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('password is wrong', async () => {
|
it('password is wrong', async () => {
|
||||||
await expect(user.post(endpoint, {
|
await expect(user.put(endpoint, {
|
||||||
username: newUsername,
|
username: newUsername,
|
||||||
password: wrongPassword,
|
password: wrongPassword,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
@@ -53,13 +55,15 @@ describe('POST /user/update-username', async () => {
|
|||||||
message: t('wrongPassword'),
|
message: t('wrongPassword'),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('social-only user', async () => {
|
describe('social-only user', async () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
user = await generateUser();
|
user = await generateUser();
|
||||||
await user.update({ 'auth.local': { ok: true } });
|
await user.update({ 'auth.local': { ok: true } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prevents username update', async () => {
|
it('prevents username update', async () => {
|
||||||
await expect(user.post(endpoint, {
|
await expect(user.put(endpoint, {
|
||||||
username: newUsername,
|
username: newUsername,
|
||||||
password,
|
password,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
@@ -69,8 +73,9 @@ describe('POST /user/update-username', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('new username is not provided', async () => {
|
it('new username is not provided', async () => {
|
||||||
await expect(user.post(endpoint, {
|
await expect(user.put(endpoint, {
|
||||||
password,
|
password,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
code: 400,
|
code: 400,
|
||||||
@@ -43,7 +43,7 @@ api.getUser = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} /user/update-password
|
* @api {put} /user/update-password
|
||||||
* @apiVersion 3.0.0
|
* @apiVersion 3.0.0
|
||||||
* @apiName updatePassword
|
* @apiName updatePassword
|
||||||
* @apiGroup User
|
* @apiGroup User
|
||||||
@@ -53,7 +53,7 @@ api.getUser = {
|
|||||||
* @apiSuccess {Object} The success message
|
* @apiSuccess {Object} The success message
|
||||||
**/
|
**/
|
||||||
api.updatePassword = {
|
api.updatePassword = {
|
||||||
method: 'POST',
|
method: 'PUT',
|
||||||
middlewares: [authWithHeaders(), cron],
|
middlewares: [authWithHeaders(), cron],
|
||||||
url: '/user/update-password',
|
url: '/user/update-password',
|
||||||
async handler (req, res) {
|
async handler (req, res) {
|
||||||
@@ -82,7 +82,7 @@ api.updatePassword = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} /user/update-username
|
* @api {put} /user/update-username
|
||||||
* @apiVersion 3.0.0
|
* @apiVersion 3.0.0
|
||||||
* @apiName updateUsername
|
* @apiName updateUsername
|
||||||
* @apiGroup User
|
* @apiGroup User
|
||||||
@@ -91,7 +91,7 @@ api.updatePassword = {
|
|||||||
* @apiSuccess {Object} The new username
|
* @apiSuccess {Object} The new username
|
||||||
**/
|
**/
|
||||||
api.updateUsername = {
|
api.updateUsername = {
|
||||||
method: 'POST',
|
method: 'PUT',
|
||||||
middlewares: [authWithHeaders(), cron],
|
middlewares: [authWithHeaders(), cron],
|
||||||
url: '/user/update-username',
|
url: '/user/update-username',
|
||||||
async handler (req, res) {
|
async handler (req, res) {
|
||||||
@@ -128,7 +128,7 @@ api.updateUsername = {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} /user/update-email
|
* @api {put} /user/update-email
|
||||||
* @apiVersion 3.0.0
|
* @apiVersion 3.0.0
|
||||||
* @apiName UpdateEmail
|
* @apiName UpdateEmail
|
||||||
* @apiGroup User
|
* @apiGroup User
|
||||||
@@ -139,7 +139,7 @@ api.updateUsername = {
|
|||||||
* @apiSuccess {Object} An object containing the new email address
|
* @apiSuccess {Object} An object containing the new email address
|
||||||
*/
|
*/
|
||||||
api.updateEmail = {
|
api.updateEmail = {
|
||||||
method: 'POST',
|
method: 'PUT',
|
||||||
middlewares: [authWithHeaders(), cron],
|
middlewares: [authWithHeaders(), cron],
|
||||||
url: '/user/update-email',
|
url: '/user/update-email',
|
||||||
async handler (req, res) {
|
async handler (req, res) {
|
||||||
|
|||||||
Reference in New Issue
Block a user