From b19f936e64e4bb1e6a6bd9aca233c70cb65df2f3 Mon Sep 17 00:00:00 2001 From: gaba Date: Tue, 8 Nov 2016 15:59:35 -0800 Subject: [PATCH] Adds tests --- models/comment.js | 2 +- tests/models/comment.js | 43 +++++++++++++++++++++++++++++++++-------- tests/models/setting.js | 7 +++++++ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/models/comment.js b/models/comment.js index 0edbcb34e..caefaa65f 100644 --- a/models/comment.js +++ b/models/comment.js @@ -116,7 +116,7 @@ CommentSchema.statics.moderationQueue = function(moderationValue) { return comments; }); default: - throw new Error('Moderation setting not found.'); + return Error('Moderation setting not found.') ; } }); }; diff --git a/tests/models/comment.js b/tests/models/comment.js index 20f501da1..e46345e39 100644 --- a/tests/models/comment.js +++ b/tests/models/comment.js @@ -27,7 +27,7 @@ describe('Comment: models', () => { }, { body: 'comment 30', asset_id: '456', - status: 'rejected', + status: '', parent_id: '', author_id: '456', id: '3' @@ -43,12 +43,12 @@ describe('Comment: models', () => { const actions = [{ action_type: 'flag', - item_id: comments[0].id, + item_id: '3', item_type: 'comment', user_id: '123' }, { action_type: 'like', - item_id: comments[1].id, + item_id: '1', item_type: 'comment', user_id: '456' }]; @@ -87,10 +87,37 @@ describe('Comment: models', () => { }); describe('#moderationQueue()', () => { - it('should find an array of new comments to moderate when pre-moderation'); - it('should find an array of new comments to moderate when post-moderation'); - it('should find an array of new comments to moderate when pre-moderation in settings'); - it('should find an array of new comments to moderate when post-moderation in settings'); - it('should fail when the moderation is not pre or post'); + it('should find an array of new comments to moderate when pre-moderation', () => { + return Comment.moderationQueue('pre').then((result) => { + expect(result).to.not.be.null; + expect(result).to.have.lengthOf(2); + }); + }); + it('should find an array of new comments to moderate when post-moderation', () => { + return Comment.moderationQueue('post').then((result) => { + expect(result).to.not.be.null; + expect(result).to.have.lengthOf(1); + expect(result[0]).to.have.property('body', 'comment 30'); + }); + }); + it('should find an array of new comments to moderate when pre-moderation in settings', () => { + return Comment.moderationQueue().then((result) => { + expect(result).to.not.be.null; + expect(result).to.have.lengthOf(2); + }); + }); + it('should find an array of new comments to moderate when post-moderation in settings', () => { + return Comment.moderationQueue('post').then((result) => { + expect(result).to.not.be.null; + expect(result).to.have.lengthOf(1); + expect(result[0]).to.have.property('body', 'comment 30'); + }); + }); + it('should fail when the moderation is not pre or post', () => { + return Comment.moderationQueue('any').then((error, result) => { + expect(error).to.not.be.null; + expect(result).to.be.null; + }); + }); }); }); diff --git a/tests/models/setting.js b/tests/models/setting.js index e2600fb0f..f50110635 100644 --- a/tests/models/setting.js +++ b/tests/models/setting.js @@ -29,4 +29,11 @@ describe('Setting: model', () => { }); }); + describe('#getModerationSetting', () => { + it('should return the moderation settings', () => { + return Setting.getModerationSetting().then(({moderation}) => { + expect(moderation).not.to.be.null; + }); + }); + }); });