Merge branch 'master' into update-settings-in-ui

This commit is contained in:
gaba
2016-11-09 13:57:19 -08:00
5 changed files with 129 additions and 22 deletions
+67 -19
View File
@@ -1,30 +1,73 @@
require('../utils/mongoose');
const Comment = require('../../models/comment');
const User = require('../../models/user');
const Action = require('../../models/action');
const Setting = require('../../models/setting');
const settings = {id: '1', moderation: 'pre'};
const expect = require('chai').expect;
describe('Comment: models', () => {
let mockComments;
const comments = [{
body: 'comment 10',
asset_id: '123',
status: '',
parent_id: '',
author_id: '123',
id: '1'
}, {
body: 'comment 20',
asset_id: '123',
status: 'accepted',
parent_id: '',
author_id: '123',
id: '2'
}, {
body: 'comment 30',
asset_id: '456',
status: 'rejected',
parent_id: '',
author_id: '456',
id: '3'
}];
const users = [{
id: '123',
display_name: 'Ana',
}, {
id: '456',
display_name: 'Maria',
}];
const actions = [{
action_type: 'flag',
item_id: comments[0].id,
item_type: 'comment',
user_id: '123'
}, {
action_type: 'like',
item_id: comments[1].id,
item_type: 'comment',
user_id: '456'
}];
beforeEach(() => {
return Comment.create([{
body: 'comment 10',
asset_id: '123'
}, {
body: 'comment 20',
asset_id: '123'
}, {
body: 'comment 30',
asset_id: '456'
}]).then((comments) => {
mockComments = comments;
return Setting.create(settings).then(() => {
return Comment.create(comments);
}).then(() => {
return User.create(users);
}).then(() => {
return Action.create(actions);
});
});
describe('#findById()', () => {
it('should find a comment by id', () => {
return Comment.findById(mockComments[0].id).then((result) => {
expect(result).to.have.property('body')
.and.to.equal('comment 10');
return Comment.findById('1').then((result) => {
expect(result).to.not.be.null;
expect(result).to.have.property('body', 'comment 10');
});
});
});
@@ -37,11 +80,16 @@ describe('Comment: models', () => {
if (a.body < b.body) {return -1;}
else {return 1;}
});
expect(result[0]).to.have.property('body')
.and.to.equal('comment 10');
expect(result[1]).to.have.property('body')
.and.to.equal('comment 20');
expect(result[0]).to.have.property('body', 'comment 10');
expect(result[1]).to.have.property('body', 'comment 20');
});
});
});
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');
});
});