mirror of
https://github.com/wassname/talk.git
synced 2026-07-09 11:44:45 +08:00
Fix tests.
This commit is contained in:
@@ -28,7 +28,7 @@ const createComment = ({user, loaders: {Comments}, pubsub}, {body, asset_id, par
|
||||
.then(async (comment) => {
|
||||
|
||||
if (user.hasRoles('ADMIN') || user.hasRoles('MODERATOR')) {
|
||||
await CommentsService.addTag(comment.id, 'STAFF', user.id);
|
||||
await CommentsService.addTag(comment.id, 'STAFF', user);
|
||||
}
|
||||
|
||||
// If the loaders are present, clear the caches for these values because we
|
||||
@@ -209,7 +209,7 @@ const setCommentStatus = ({user, loaders: {Comments}}, {id, status}) => {
|
||||
* @param {String} tag name of the tag
|
||||
*/
|
||||
const addCommentTag = ({user, loaders: {Comments}}, {id, tag}) => {
|
||||
return CommentsService.addTag(id, tag, user.id);
|
||||
return CommentsService.addTag(id, tag, user);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+24
-15
@@ -2,7 +2,7 @@ const CommentModel = require('../models/comment');
|
||||
|
||||
const ActionModel = require('../models/action');
|
||||
const ActionsService = require('./actions');
|
||||
|
||||
const SettingModel = require('../models/setting');
|
||||
const SettingsService = require('./settings');
|
||||
|
||||
const STATUSES = [
|
||||
@@ -25,8 +25,6 @@ module.exports = class CommentsService {
|
||||
*/
|
||||
static publicCreate(comment) {
|
||||
|
||||
console.log('-----------------> debug publicCreate');
|
||||
|
||||
// Check to see if this is an array of comments, if so map it out.
|
||||
if (Array.isArray(comment)) {
|
||||
return Promise.all(comment.map(CommentsService.publicCreate));
|
||||
@@ -56,22 +54,33 @@ module.exports = class CommentsService {
|
||||
*/
|
||||
static addTag(id, name, added_by) {
|
||||
|
||||
console.log('-----------------> debug addtag', name);
|
||||
|
||||
SettingsService.retrieve()
|
||||
.then(({tags}) => {
|
||||
if (!ALLOWED_TAGS.includes(name) || tags.findIndex((t) => {return t.id === name & t.models.include('COMMENTS');}) === -1) {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (!ALLOWED_TAGS.includes(name) || settings.tags.findIndex((t) => {return t.id === name & t.models.include('COMMENTS');}) === -1) {
|
||||
return Promise.reject(new Error('tag not allowed'));
|
||||
}
|
||||
});
|
||||
|
||||
return CommentModel.findOneAndUpdate({id}, {
|
||||
$push: {
|
||||
tags: {
|
||||
id: name,
|
||||
added_by: added_by
|
||||
return CommentModel.findOneAndUpdate({id}, {
|
||||
$push: {
|
||||
tags: {
|
||||
id: name,
|
||||
added_by: added_by.id
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,27 +23,11 @@ describe('graph.loaders.Metrics', () => {
|
||||
|
||||
describe('different comment states', () => {
|
||||
|
||||
beforeEach(() =>{
|
||||
CommentModel.create( {id: '1', body: 'a new comment!'})
|
||||
.then((comment) => {
|
||||
console.log('*************** wtf comment', comment);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('1 debug the rror create ', error);
|
||||
});
|
||||
console.log('debug 1');
|
||||
CommentModel.create({id: '2', body: 'a new comment!'})
|
||||
.catch((error) => {
|
||||
console.log('2 debug the rror create ', error);
|
||||
});
|
||||
console.log('debug 2');
|
||||
beforeEach(() =>[
|
||||
CommentModel.create( {id: '1', body: 'a new comment!'}),
|
||||
CommentModel.create({id: '2', body: 'a new comment!'}),
|
||||
CommentModel.create({id: '3', body: 'a new comment!'})
|
||||
.catch((error) => {
|
||||
console.log('3 debug the rror create ', error);
|
||||
});
|
||||
console.log('debug 3');
|
||||
}
|
||||
);
|
||||
]);
|
||||
|
||||
[
|
||||
{flagged: 0, actions: []},
|
||||
@@ -56,7 +40,6 @@ describe('graph.loaders.Metrics', () => {
|
||||
]}
|
||||
].forEach(({flagged, actions}) => {
|
||||
|
||||
console.log('-----------------> debug forEach');
|
||||
describe(`with actions=${actions.length}`, () => {
|
||||
|
||||
beforeEach(() => ActionModel.create(actions));
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('graph.mutations.createComment', () => {
|
||||
id
|
||||
status
|
||||
tags {
|
||||
name
|
||||
id
|
||||
}
|
||||
}
|
||||
errors {
|
||||
@@ -228,7 +228,7 @@ describe('graph.mutations.createComment', () => {
|
||||
.then(({tags}) => {
|
||||
if (tag) {
|
||||
expect(tags).to.have.length(1);
|
||||
expect(tags[0]).to.have.property('name', tag);
|
||||
expect(tags[0]).to.have.property('id', tag);
|
||||
} else {
|
||||
expect(tags).length(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user