Test was failing as I was not returning an error.

This commit is contained in:
gaba
2017-05-08 16:05:40 -07:00
parent 743a96cd21
commit 96cd5197e3
5 changed files with 40 additions and 14 deletions
+22 -7
View File
@@ -76,21 +76,26 @@ module.exports = class CommentsService {
});
}
else if (!ALLOWED_TAGS.includes(name) || settings.tags.findIndex((t) => {return t.id === name & t.models.include('COMMENTS');}) === -1) {
return Promise.reject(errors.ErrorTagNotAllowed);
return Promise.reject(errors.ErrTagNotAllowed);
}
});
return CommentModel.findOneAndUpdate({id}, {
return CommentModel.findOneAndUpdate({id, 'tags.id': {$ne: name}}, {
$push: {
tags: {
id: name,
added_by: added_by
}
},
},
{
new: false,
upsert: false
})
.then(({nModified}) => {
switch (nModified) {
case 0:
return Promise.reject(errors.ErrNoCommentFound);
case 1:
return;
default:
}
});
});
}
@@ -102,12 +107,22 @@ module.exports = class CommentsService {
* @param {String} tag_id the id of the tag to remove
*/
static removeTag(id, tag_id) {
return CommentModel.findOneAndUpdate({id}, {
return CommentModel.findOneAndUpdate({id, 'tags.id': tag_id}, {
$pull: {
tags: {
id: tag_id
}
}
}
)
.then(({nModified}) => {
switch(nModified) {
case 0:
return Promise.reject(errors.ErrNoCommentFound);
case 1:
return;
default:
}
});
}