mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
* Added check - user can't block himself * removed exclusive test
This commit is contained in:
committed by
Sabe Jones
parent
444f393f3a
commit
15626b8ae1
@@ -25,6 +25,15 @@ describe('shared.ops.blockUser', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('validates user can\'t block himself', (done) => {
|
||||||
|
try {
|
||||||
|
blockUser(user, { params: { uuid: user._id } });
|
||||||
|
} catch (error) {
|
||||||
|
expect(error.message).to.eql(i18n.t('blockYourself'));
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('blocks user', () => {
|
it('blocks user', () => {
|
||||||
let [result] = blockUser(user, { params: { uuid: blockedUser._id } });
|
let [result] = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||||
expect(user.inbox.blocks).to.eql([blockedUser._id]);
|
expect(user.inbox.blocks).to.eql([blockedUser._id]);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
"pageMustBeNumber": "req.query.page must be a number",
|
"pageMustBeNumber": "req.query.page must be a number",
|
||||||
"userNotFound": "User not found.",
|
"userNotFound": "User not found.",
|
||||||
"invalidUUID": "UUID must be valid",
|
"invalidUUID": "UUID must be valid",
|
||||||
|
"blockYourself": "You can't block yourself!",
|
||||||
"title": "Title",
|
"title": "Title",
|
||||||
"moreDetails": "More details (1-7)",
|
"moreDetails": "More details (1-7)",
|
||||||
"moreDetails2": "more details (8-9)",
|
"moreDetails2": "more details (8-9)",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
|
|
||||||
module.exports = function blockUser (user, req = {}) {
|
module.exports = function blockUser (user, req = {}) {
|
||||||
if (!validator.isUUID(req.params.uuid)) throw new BadRequest(i18n.t('invalidUUID', req.language));
|
if (!validator.isUUID(req.params.uuid)) throw new BadRequest(i18n.t('invalidUUID', req.language));
|
||||||
|
if (req.params.uuid === user._id) throw new BadRequest(i18n.t('blockYourself', req.language));
|
||||||
|
|
||||||
let i = user.inbox.blocks.indexOf(req.params.uuid);
|
let i = user.inbox.blocks.indexOf(req.params.uuid);
|
||||||
if (i === -1) {
|
if (i === -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user