Error on duplicate.

This commit is contained in:
gaba
2017-05-08 13:11:48 -07:00
parent 28920eb357
commit cb09c50820
19 changed files with 173 additions and 266 deletions
+22 -6
View File
@@ -23,11 +23,27 @@ describe('graph.loaders.Metrics', () => {
describe('different comment states', () => {
beforeEach(() => CommentModel.create([
{id: '1', body: 'a new comment!'},
{id: '2', body: 'a new comment!'},
{id: '3', body: 'a new comment!'}
]));
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');
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: []},
@@ -40,6 +56,7 @@ describe('graph.loaders.Metrics', () => {
]}
].forEach(({flagged, actions}) => {
console.log('-----------------> debug forEach');
describe(`with actions=${actions.length}`, () => {
beforeEach(() => ActionModel.create(actions));
@@ -52,7 +69,6 @@ describe('graph.loaders.Metrics', () => {
to: (new Date()).setMinutes((new Date()).getMinutes() + 5)
})
.then(({data, errors}) => {
console.log(errors);
expect(errors).to.be.undefined;
expect(data.flagged).to.have.length(flagged);
});
+5 -6
View File
@@ -4,7 +4,6 @@ const {graphql} = require('graphql');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
const UserModel = require('../../../../models/user');
const TagService = require('../../../../services/tags');
const SettingsService = require('../../../../services/settings');
const CommentsService = require('../../../../services/comments');
@@ -16,8 +15,8 @@ describe('graph.mutations.addCommentTag', () => {
});
const query = `
mutation AddCommentTag ($id: ID!, $tag: String!, $privacy_type: String!) {
addCommentTag(id:$id, tag:$tag, privacy_type:$privacy_type) {
mutation AddCommentTag ($id: ID!, $tag: String!) {
addCommentTag(id:$id, tag:$tag) {
comment {
id
}
@@ -31,14 +30,14 @@ describe('graph.mutations.addCommentTag', () => {
it('moderators can add tags to comments', async () => {
const user = new UserModel({roles: ['MODERATOR' ]});
const context = new Context({user});
const response = await graphql(schema, query, {}, context, {id: comment.id, tag: 'BEST', privacy_type: 'PUBLIC'});
const response = await graphql(schema, query, {}, context, {id: comment.id, tag: 'BEST'});
if (response.errors && response.errors.length) {
console.error(response.errors);
}
expect(response.errors).to.be.empty;
return TagService.findByItemIdAndName(response.data.addCommentTag.comment.id, 'BEST', 'COMMENTS')
.then((tags) => {
return CommentsService.findById(response.data.addCommentTag.comment.id)
.then(({tags}) => {
expect(tags).to.have.length(1);
});
});
+3 -3
View File
@@ -9,7 +9,7 @@ const AssetModel = require('../../../../models/asset');
const ActionModel = require('../../../../models/action');
const SettingsService = require('../../../../services/settings');
const TagService = require('../../../../services/tags');
const CommentsService = require('../../../../services/comments');
describe('graph.mutations.createComment', () => {
beforeEach(() => SettingsService.init());
@@ -223,9 +223,9 @@ describe('graph.mutations.createComment', () => {
expect(data.createComment).to.have.property('comment').not.null;
expect(data.createComment).to.have.property('errors').null;
return TagService.findByItemIdAndName(data.createComment.comment.id, tag, 'COMMENTS');
return CommentsService.findById(data.createComment.comment.id);
})
.then((tags) => {
.then(({tags}) => {
if (tag) {
expect(tags).to.have.length(1);
expect(tags[0]).to.have.property('name', tag);
@@ -7,7 +7,6 @@ const UserModel = require('../../../../models/user');
const SettingsService = require('../../../../services/settings');
const CommentsService = require('../../../../services/comments');
const TagService = require('../../../../services/tags');
describe('graph.mutations.removeCommentTag', () => {
let comment;
@@ -42,8 +41,8 @@ describe('graph.mutations.removeCommentTag', () => {
expect(response.errors).to.be.empty;
expect(response.data.removeCommentTag.errors).to.be.null;
TagService.findByItemIdAndName(response.data.removeCommentTag.comment.id, 'BEST')
.then((tags) => {
CommentsService.findById(response.data.removeCommentTag.comment.id)
.then(({tags}) => {
expect(tags).to.deep.equal([]);
});
+5 -6
View File
@@ -5,7 +5,6 @@ const ActionsService = require('../../../services/actions');
const UsersService = require('../../../services/users');
const SettingsService = require('../../../services/settings');
const CommentsService = require('../../../services/comments');
const TagService = require('../../../services/tags');
const settings = {id: '1', moderation: 'PRE', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
@@ -226,7 +225,7 @@ describe('services.CommentsService', () => {
const tagName = 'BEST';
const userId = users[0].id;
await CommentsService.addTag(commentId, tagName, userId, 'PUBLIC');
const tags = await TagService.findByItemIdAndName(commentId, 'BEST', 'COMMENTS');
const {tags} = await CommentsService.findById(commentId);
expect(tags.length).to.equal(1);
expect(tags[0].name).to.equal(tagName);
expect(tags[0].assigned_by).to.equal(userId);
@@ -257,13 +256,13 @@ describe('services.CommentsService', () => {
const commentId = comments[0].id;
const tagName = 'BEST';
await CommentsService.addTag(commentId, tagName, users[0].id, 'PUBLIC');
const tags = await TagService.findByItemIdAndName(commentId, tagName, 'COMMENTS');
const {tags} = await CommentsService.findById(commentId);
expect(tags.length).to.equal(1);
// ok now to remove it
await CommentsService.removeTag(commentId, tagName);
const tags2 = await TagService.findByItemIdAndName(commentId, tagName, 'COMMENTS');
expect(tags2.length).to.equal(0);
const comment = await CommentsService.findById(commentId);
expect(comment.tags.length).to.equal(0);
});
it('throws if removing a tag that isn\'t there', async () => {
const commentId = comments[0].id;
@@ -271,7 +270,7 @@ describe('services.CommentsService', () => {
const tagName = 'BEST';
// just make sure it has no tags to start
const tags = await TagService.findByItemIdAndName(commentId, tagName, 'COMMENTS');
const {tags} = await CommentsService.findById(commentId);
expect(tags.length).to.equal(0);
// ok now to remove it