From c72cb2428e241dd6b97790ff22542d2b26bb137c Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 5 May 2017 14:33:02 -0700 Subject: [PATCH] Fixed errors on tags creation --- services/comments.js | 4 ++-- test/server/graph/mutations/removeCommentTag.js | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/services/comments.js b/services/comments.js index 41c383725..aae5c8248 100644 --- a/services/comments.js +++ b/services/comments.js @@ -57,14 +57,14 @@ module.exports = class CommentsService { // Check that the tag is allowed by the system OR in our setting.tags. return SettingsService.retrieve() .then((settings) => { - + // Moderators or ADMIN can add any tag automatically. if (added_by != null && (added_by.hasRoles('ADMIN') || added_by.hasRoles('MODERATOR'))) { SettingModel.findOneAndUpdate({id: settings.id}, { $push: { tags: { id: name, - added_by: added_by.id + models: ['COMMENTS'] } } }); diff --git a/test/server/graph/mutations/removeCommentTag.js b/test/server/graph/mutations/removeCommentTag.js index 4deb4bd5e..663e0de9a 100644 --- a/test/server/graph/mutations/removeCommentTag.js +++ b/test/server/graph/mutations/removeCommentTag.js @@ -4,6 +4,7 @@ const {graphql} = require('graphql'); const schema = require('../../../../graph/schema'); const Context = require('../../../../graph/context'); const UserModel = require('../../../../models/user'); +const SettingModel = require('../../../../models/setting'); const SettingsService = require('../../../../services/settings'); const CommentsService = require('../../../../services/comments'); @@ -33,7 +34,7 @@ describe('graph.mutations.removeCommentTag', () => { const context = new Context({user}); // add a tag first - await CommentsService.addTag(comment.id, 'BEST', user.id, 'PUBLIC'); + await CommentsService.addTag(comment.id, 'BEST', user); const response = await graphql(schema, query, {}, context, {id: comment.id, tag: 'BEST'}); if (response.errors && response.errors.length) { console.error(response.errors); @@ -49,6 +50,16 @@ describe('graph.mutations.removeCommentTag', () => { }); describe('users who cant remove tags', () => { + + // allow the tag in the settings + SettingModel.findOneAndUpdate({id: 1}, { + $push: { + tags: { + id: 'BEST', + models: ['COMMENTS'] + } + } + }); Object.entries({ 'anonymous': undefined, 'regular commenter': new UserModel({}), @@ -58,7 +69,7 @@ describe('graph.mutations.removeCommentTag', () => { const context = new Context({user}); // add a tag first - await CommentsService.addTag(comment.id, 'BEST', user ? user.id : null, 'PUBLIC'); + await CommentsService.addTag(comment.id, 'BEST', user); const response = await graphql(schema, query, {}, context, {id: comment.id, tag: 'BEST'}); if (response.errors && response.errors.length) { console.error(response.errors);