removed events

This commit is contained in:
Wyatt Johnson
2018-01-29 16:36:54 -07:00
parent 73cbe4ab4b
commit a06f76fd4c
12 changed files with 121 additions and 531 deletions
+2 -1
View File
@@ -3,6 +3,7 @@ const { graphql } = require('graphql');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
const AssetModel = require('../../../../models/asset');
const CommentModel = require('../../../../models/comment');
const UserModel = require('../../../../models/user');
const SettingsService = require('../../../../services/settings');
const CommentsService = require('../../../../services/comments');
@@ -50,7 +51,7 @@ describe('graph.mutations.addTag', () => {
expect(res.errors).to.be.empty;
let { tags } = await CommentsService.findById(comment.id);
let { tags } = await CommentModel.findOne({ id: comment.id });
expect(tags).to.have.length(1);
});
+6 -6
View File
@@ -3,12 +3,12 @@ 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 ActionModel = require('../../../../models/action');
const AssetModel = require('../../../../models/asset');
const CommentModel = require('../../../../models/comment');
const UserModel = require('../../../../models/user');
const SettingsService = require('../../../../services/settings');
const CommentsService = require('../../../../services/comments');
const { expect } = require('chai');
@@ -293,9 +293,9 @@ describe('graph.mutations.createComment', () => {
expect(data.createComment).to.have.property('comment').not.null;
expect(data.createComment).to.have.property('errors').null;
const { tags } = await CommentsService.findById(
data.createComment.comment.id
);
const { tags } = await CommentModel.findOne({
id: data.createComment.comment.id,
});
if (tag) {
expect(tags).to.have.length(1);
expect(tags[0].tag.name).to.have.equal(tag);
+9 -8
View File
@@ -1,12 +1,13 @@
const { graphql } = require('graphql');
const timekeeper = require('timekeeper');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
const UsersService = require('../../../../services/users');
const AssetModel = require('../../../../models/asset');
const SettingsService = require('../../../../services/settings');
const CommentModel = require('../../../../models/comment');
const CommentsService = require('../../../../services/comments');
const Context = require('../../../../graph/context');
const schema = require('../../../../graph/schema');
const SettingsService = require('../../../../services/settings');
const UsersService = require('../../../../services/users');
const { expect } = require('chai');
@@ -70,7 +71,7 @@ describe('graph.mutations.editComment', () => {
expect(response.data.editComment.errors).to.be.null;
// assert body has changed
const commentAfterEdit = await CommentsService.findById(comment.id);
const commentAfterEdit = await CommentModel.findOne({ id: comment.id });
expect(commentAfterEdit.body).to.equal(newBody);
expect(commentAfterEdit.body_history).to.be.instanceOf(Array);
expect(commentAfterEdit.body_history.length).to.equal(2);
@@ -110,7 +111,7 @@ describe('graph.mutations.editComment', () => {
expect(response.data.editComment.errors[0].translation_key).to.equal(
'EDIT_WINDOW_ENDED'
);
const commentAfterEdit = await CommentsService.findById(comment.id);
const commentAfterEdit = await CommentModel.findOne({ id: comment.id });
// it *hasn't* changed from the original
expect(commentAfterEdit.body).to.equal(comment.body);
@@ -142,7 +143,7 @@ describe('graph.mutations.editComment', () => {
expect(response.data.editComment.errors[0].translation_key).to.equal(
'NOT_AUTHORIZED'
);
const commentAfterEdit = await CommentsService.findById(comment.id);
const commentAfterEdit = await CommentModel.findOne({ id: comment.id });
// it *hasn't* changed from the original
expect(commentAfterEdit.body).to.equal(comment.body);
@@ -274,7 +275,7 @@ describe('graph.mutations.editComment', () => {
console.error(response.data.editComment.errors);
}
expect(response.data.editComment.errors).to.be.null;
const commentAfterEdit = await CommentsService.findById(comment.id);
const commentAfterEdit = await CommentModel.findOne({ id: comment.id });
expect(commentAfterEdit.body).to.equal(newBody);
expect(commentAfterEdit.status).to.equal(afterEdit.status);
}
+3 -2
View File
@@ -6,8 +6,9 @@ const UserModel = require('../../../../models/user');
const SettingModel = require('../../../../models/setting');
const AssetModel = require('../../../../models/asset');
const SettingsService = require('../../../../services/settings');
const CommentModel = require('../../../../models/comment');
const CommentsService = require('../../../../services/comments');
const SettingsService = require('../../../../services/settings');
const TagsService = require('../../../../services/tags');
const { expect } = require('chai');
@@ -59,7 +60,7 @@ describe('graph.mutations.removeTag', () => {
expect(response.errors).to.be.empty;
expect(response.data.removeTag).to.be.null;
let retrievedComment = await CommentsService.findById(comment.id);
let retrievedComment = await CommentModel.findOne({ id: comment.id });
expect(retrievedComment.tags).to.have.length(0);
});
-47
View File
@@ -6,14 +6,6 @@ const chai = require('chai');
chai.use(require('chai-as-promised'));
const expect = chai.expect;
const events = require('../../../services/events');
const {
ACTIONS_NEW,
ACTIONS_DELETE,
} = require('../../../services/events/constants');
const sinon = require('sinon');
describe('services.ActionsService', () => {
let mockActions = [];
let comment;
@@ -78,30 +70,6 @@ describe('services.ActionsService', () => {
expect(retrievedAction).has.property('id', createdAction.id);
expect(retrievedAction).has.property('item_id', comment.id);
});
it('fires the callback successfully', async () => {
const srcAction = {
action_type: 'LIKE',
item_type: 'COMMENTS',
item_id: comment.id,
};
const spy = sinon.spy();
events.once(ACTIONS_NEW, spy);
const createdAction = await ActionsService.create(srcAction);
expect(createdAction).is.not.null;
expect(createdAction).has.property('id');
expect(createdAction).has.property('item_id', comment.id);
expect(spy).to.have.been.calledWith(createdAction);
const retrievedComment = await CommentModel.findOne({ id: comment.id });
expect(retrievedComment).to.have.property('action_counts');
expect(retrievedComment.action_counts).to.have.property('like', 1);
});
});
describe('#delete', () => {
@@ -116,21 +84,6 @@ describe('services.ActionsService', () => {
expect(retrievedAction).is.null;
});
it('fires the callback successfully', async () => {
const spy = sinon.spy();
events.once(ACTIONS_DELETE, spy);
const deletedAction = await ActionsService.delete(mockActions[0]);
expect(deletedAction).has.property('id', mockActions[0].id);
expect(spy).to.have.been.calledWith(deletedAction);
const retrievedComment = await CommentModel.findOne({ id: comment.id });
expect(retrievedComment).to.have.property('action_counts');
expect(retrievedComment.action_counts).to.have.property('flag', -1);
});
});
describe('#findById()', () => {
+7 -39
View File
@@ -1,8 +1,6 @@
const CommentModel = require('../../../models/comment');
const ActionModel = require('../../../models/action');
const events = require('../../../services/events');
const { COMMENTS_EDIT } = require('../../../services/events/constants');
const UsersService = require('../../../services/users');
const SettingsService = require('../../../services/settings');
const CommentsService = require('../../../services/comments');
@@ -17,8 +15,6 @@ const chai = require('chai');
chai.use(require('sinon-chai'));
const expect = chai.expect;
const sinon = require('sinon');
describe('services.CommentsService', () => {
const comments = [
{
@@ -214,7 +210,9 @@ describe('services.CommentsService', () => {
await CommentsService.pushStatus(originalComment.id, 'ACCEPTED');
let retrivedComment = await CommentsService.findById(originalComment.id);
let retrivedComment = await CommentModel.findOne({
id: originalComment.id,
});
expect(retrivedComment).to.have.property('status', 'ACCEPTED');
expect(retrivedComment.status_history).to.have.length(2);
@@ -237,7 +235,7 @@ describe('services.CommentsService', () => {
'PREMOD'
);
retrivedComment = await CommentsService.findById(originalComment.id);
retrivedComment = await CommentModel.findOne({ id: originalComment.id });
expect(retrivedComment).to.have.property('status', 'PREMOD');
expect(retrivedComment.status_history).to.have.length(3);
@@ -248,41 +246,13 @@ describe('services.CommentsService', () => {
});
});
describe('#findById()', () => {
it('should find a comment by id', async () => {
const comment = await CommentsService.findById('1');
expect(comment).to.not.be.null;
expect(comment).to.have.property('body', 'comment 10');
});
});
describe('#findByAssetId()', () => {
it('should find an array of all comments by asset id', async () => {
const comments = await CommentsService.findByAssetId('123');
expect(comments).to.have.length(3);
comments.sort((a, b) => {
if (a.body < b.body) {
return -1;
} else {
return 1;
}
});
expect(comments[0]).to.have.property('body', 'comment 10');
expect(comments[1]).to.have.property('body', 'comment 20');
expect(comments[2]).to.have.property('body', 'comment 40');
});
});
describe('#changeStatus', () => {
it('should change the status of a comment from no status', async () => {
let comment_id = comments[0].id;
let c = await CommentsService.findById(comment_id);
let c = await CommentModel.findOne({ id: comment_id });
expect(c.status).to.be.equal('NONE');
const spy = sinon.spy();
events.once(COMMENTS_EDIT, spy);
let c2 = await CommentsService.pushStatus(comment_id, 'REJECTED', '123');
expect(c2).to.have.property('status');
expect(c2.status).to.equal('REJECTED');
@@ -290,9 +260,7 @@ describe('services.CommentsService', () => {
expect(c2.status_history[0]).to.have.property('type', 'REJECTED');
expect(c2.status_history[0]).to.have.property('assigned_by', '123');
expect(spy).to.have.been.called;
let c3 = await CommentsService.findById(comment_id);
let c3 = await CommentModel.findOne({ id: comment_id });
expect(c3).to.have.property('status');
expect(c3.status).to.equal('REJECTED');
expect(c3.status_history).to.have.length(1);
@@ -302,7 +270,7 @@ describe('services.CommentsService', () => {
it('should change the status of a comment from accepted', async () => {
await CommentsService.pushStatus(comments[1].id, 'REJECTED', '123');
const c = await CommentsService.findById(comments[1].id);
const c = await CommentModel.findOne({ id: comments[1].id });
expect(c).to.have.property('status_history');
expect(c).to.have.property('status');
expect(c.status).to.equal('REJECTED');
+7 -8
View File
@@ -1,4 +1,3 @@
const CommentsService = require('../../../services/comments');
const TagsService = require('../../../services/tags');
const UsersService = require('../../../services/users');
const SettingsService = require('../../../services/settings');
@@ -40,7 +39,7 @@ describe('services.TagsService', () => {
assigned_by,
});
const { tags } = await CommentsService.findById(id);
const { tags } = await CommentModel.findOne({ id });
expect(tags.length).to.equal(1);
expect(tags[0].tag.name).to.equal(name);
expect(tags[0].assigned_by).to.equal(assigned_by);
@@ -59,7 +58,7 @@ describe('services.TagsService', () => {
});
{
let { tags } = await CommentsService.findById(id);
let { tags } = await CommentModel.findOne({ id });
expect(tags.length).to.equal(1);
}
@@ -71,7 +70,7 @@ describe('services.TagsService', () => {
});
{
let { tags } = await CommentsService.findById(id);
let { tags } = await CommentModel.findOne({ id });
expect(tags.length).to.equal(1);
}
});
@@ -91,7 +90,7 @@ describe('services.TagsService', () => {
});
{
const { tags } = await CommentsService.findById(id);
const { tags } = await CommentModel.findOne({ id });
expect(tags.length).to.equal(1);
}
@@ -104,7 +103,7 @@ describe('services.TagsService', () => {
});
{
const { tags } = await CommentsService.findById(id);
const { tags } = await CommentModel.findOne({ id });
expect(tags.length).to.equal(0);
}
});
@@ -128,7 +127,7 @@ describe('services.TagsService', () => {
});
{
const { tags } = await CommentsService.findById(id);
const { tags } = await CommentModel.findOne({ id });
expect(tags.length).to.equal(2);
}
@@ -141,7 +140,7 @@ describe('services.TagsService', () => {
});
{
const { tags } = await CommentsService.findById(id);
const { tags } = await CommentModel.findOne({ id });
expect(tags.length).to.equal(1);
expect(tags[0].tag.name).to.equal('ANOTHER');
}