Fix tests related to tags on comments.

This commit is contained in:
gaba
2017-04-20 12:24:08 -07:00
parent 1137fca3b4
commit bd72bfc6ec
10 changed files with 139 additions and 81 deletions
+5 -8
View File
@@ -4,7 +4,7 @@ const {graphql} = require('graphql');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
const UserModel = require('../../../../models/user');
const TagModel = require('../../../../models/tag');
const TagService = require('../../../../services/tags');
const SettingsService = require('../../../../services/settings');
const CommentsService = require('../../../../services/comments');
@@ -19,9 +19,7 @@ describe('graph.mutations.addCommentTag', () => {
mutation AddCommentTag ($id: ID!, $tag: String!) {
addCommentTag(id:$id, tag:$tag) {
comment {
tags {
name
}
id
}
errors {
translation_key
@@ -38,10 +36,9 @@ describe('graph.mutations.addCommentTag', () => {
console.error(response.errors);
}
expect(response.errors).to.be.empty;
TagModel.find({
item_id: response.data.addCommentTag.comment.id,
name: 'BEST'
}).then((tags) => {
return TagService.findByItemIdAndName(response.data.addCommentTag.comment.id, 'BEST', 'COMMENTS')
.then((tags) => {
expect(tags).to.have.length(1);
});
});
+10 -4
View File
@@ -3,11 +3,14 @@ const {graphql} = require('graphql');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
const UserModel = require('../../../../models/user');
const AssetModel = require('../../../../models/asset');
const SettingsService = require('../../../../services/settings');
const ActionModel = require('../../../../models/action');
const SettingsService = require('../../../../services/settings');
const TagService = require('../../../../services/tags');
describe('graph.mutations.createComment', () => {
beforeEach(() => SettingsService.init());
@@ -217,11 +220,14 @@ 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');
})
.then((tags) => {
if (tag) {
expect(data.createComment.comment).to.have.property('tags').length(1);
expect(data.createComment.comment.tags[0]).to.have.property('name', tag);
expect(tags).to.have.length(1);
expect(tags[0]).to.have.property('name', tag);
} else {
expect(data.createComment.comment).to.have.property('tags').length(0);
expect(tags).length(0);
}
});
});
@@ -4,8 +4,10 @@ const {graphql} = require('graphql');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
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;
@@ -18,9 +20,7 @@ describe('graph.mutations.removeCommentTag', () => {
mutation RemoveCommentTag ($id: ID!, $tag: String!) {
removeCommentTag(id:$id, tag:$tag) {
comment {
tags {
name
}
id
}
errors {
translation_key
@@ -41,7 +41,12 @@ describe('graph.mutations.removeCommentTag', () => {
}
expect(response.errors).to.be.empty;
expect(response.data.removeCommentTag.errors).to.be.null;
expect(response.data.removeCommentTag.comment.tags).to.deep.equal([]);
TagService.findByItemIdAndName(response.data.removeCommentTag.comment.id, 'BEST')
.then((tags) => {
expect(tags).to.deep.equal([]);
});
});
describe('users who cant remove tags', () => {
@@ -60,8 +65,9 @@ describe('graph.mutations.removeCommentTag', () => {
console.error(response.errors);
}
expect(response.errors).to.be.empty;
expect(response.data.removeCommentTag.errors).to.deep.equal([{'translation_key':'NOT_AUTHORIZED'}]);
expect(response.data.removeCommentTag.comment).to.be.null;
expect(response.data.removeCommentTag.comment).to.be.null;
});
});
});