Add tests to stream on moderated comments.

This commit is contained in:
gaba
2016-11-09 09:33:15 -08:00
parent 48d404137d
commit ab68b81f21
4 changed files with 52 additions and 4 deletions
+12 -2
View File
@@ -58,13 +58,23 @@ CommentSchema.statics.findById = function(id) {
};
/**
* Finds a comment by the asset_id.
* Finds ALL the comments by the asset_id.
* @param {String} asset_id identifier of the asset which owns this comment (uuid)
*/
CommentSchema.statics.findByAssetId = function(asset_id) {
CommentSchema.statics.findAllByAssetId = function(asset_id) {
return Comment.find({asset_id});
};
/**
* Finds the comments by the asset_id.
* get the comments that are approved.
* if post: get the comments that new and not flagged.
* @param {String} asset_id identifier of the asset which owns the comments (uuid)
*/
CommentSchema.statics.findByAssetId = function(asset_id) {
return Comment.find({asset_id: asset_id, status:'accepted'});
};
/**
* Find comments by an action that was performed on them.
* @param {String} action_type the type of action that was performed on the comment
+4
View File
@@ -8,8 +8,12 @@ const router = express.Router();
router.get('/', (req, res, next) => {
// find all the comments by a specific asset_id.
// - get the comments that are approved.
// - if post: get the comments that new and not flagged.
const commentsPromise = Comment.findByAssetId(req.query.asset_id);
// get all the users and actions for those comments.
commentsPromise.then(comments => {
return Promise.all([
comments,
+12 -2
View File
@@ -73,8 +73,8 @@ describe('Comment: models', () => {
});
describe('#findByAssetId()', () => {
it('should find an array of comments by asset id', () => {
return Comment.findByAssetId('123').then((result) => {
it('should find an array of all comments by asset id', () => {
return Comment.findAllByAssetId('123').then((result) => {
expect(result).to.have.length(2);
result.sort((a, b) => {
if (a.body < b.body) {return -1;}
@@ -84,6 +84,16 @@ describe('Comment: models', () => {
expect(result[1]).to.have.property('body', 'comment 20');
});
});
it('should find an array of approved comments by asset id', () => {
return Comment.findByAssetId('123').then((result) => {
expect(result).to.have.length(1);
result.sort((a, b) => {
if (a.body < b.body) {return -1;}
else {return 1;}
});
expect(result[0]).to.have.property('body', 'comment 20');
});
});
});
describe('#moderationQueue()', () => {
+24
View File
@@ -140,6 +140,30 @@ describe('Get moderation queues rejected, pending, flags', () => {
});
});
it('should return all the pending comments as pre moderated', function(done){
chai.request(app)
.get('/api/v1/comments/status/pending')
.query({'moderation': 'pre'})
.end(function(err, res){
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res.body[0]).to.have.property('id', 'def');
done();
});
});
it('should return all the pending comments as post moderated', function(done){
chai.request(app)
.get('/api/v1/comments/status/pending')
.query({'moderation': 'post'})
.end(function(err, res){
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res.body).to.have.lengthOf(0);
done();
});
});
it('should return all the flagged comments', function(done){
chai.request(app)
.get('/api/v1/comments/action/flag')