mirror of
https://github.com/wassname/talk.git
synced 2026-08-15 12:55:10 +08:00
Add tests to stream on moderated comments.
This commit is contained in:
+12
-2
@@ -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
|
||||
|
||||
@@ -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
@@ -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()', () => {
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user