mirror of
https://github.com/wassname/talk.git
synced 2026-08-15 12:55:10 +08:00
Merge branch 'master' of https://github.com/coralproject/talk into reader-flags
This commit is contained in:
@@ -66,6 +66,86 @@ describe('Get /comments', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Get moderation queues rejected, pending, flags', () => {
|
||||
const comments = [{
|
||||
id: 'abc',
|
||||
body: 'comment 10',
|
||||
asset_id: 'asset',
|
||||
author_id: '123',
|
||||
status: 'rejected'
|
||||
}, {
|
||||
id: 'def',
|
||||
body: 'comment 20',
|
||||
asset_id: 'asset',
|
||||
author_id: '456'
|
||||
}, {
|
||||
id: 'hij',
|
||||
body: 'comment 30',
|
||||
asset_id: '456',
|
||||
status: 'accepted'
|
||||
}];
|
||||
|
||||
const users = [{
|
||||
id: '123',
|
||||
display_name: 'Ana',
|
||||
}, {
|
||||
id: '456',
|
||||
display_name: 'Maria',
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
item_id: 'abc',
|
||||
item_type: 'comment'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: 'hij',
|
||||
item_type: 'comment'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Comment.create(comments).then(() => {
|
||||
return User.create(users);
|
||||
}).then(() => {
|
||||
return Action.create(actions);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return all the rejected comments', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments/status/rejected')
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body[0]).to.have.property('id', 'abc');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return all the pending comments', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments/status/pending')
|
||||
.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 flagged comments', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments/action/flag')
|
||||
.end(function(err, res){
|
||||
expect(res).to.have.status(200);
|
||||
expect(err).to.be.null;
|
||||
expect(res.body.length).to.equal(1);
|
||||
expect(res.body[0]).to.have.property('id', 'abc');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Post /comments', () => {
|
||||
const users = [{
|
||||
id: '123',
|
||||
@@ -128,10 +208,12 @@ describe('Get /:comment_id', () => {
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
item_id: 'abc'
|
||||
item_id: 'abc',
|
||||
item_type: 'comment'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: 'hij'
|
||||
item_id: 'hij',
|
||||
item_type: 'comment'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -144,14 +226,12 @@ describe('Get /:comment_id', () => {
|
||||
|
||||
it('should return the right comment for the comment_id', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments')
|
||||
.query({'comment_id': 'abc'})
|
||||
.get('/api/v1/comments/abc')
|
||||
.end(function(err, res){
|
||||
const sorted = res.body.sort((a, b) => a.body - b.body);
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(sorted[0]).to.have.property('body')
|
||||
.and.to.equal('comment 10');
|
||||
expect(res).to.have.property('body');
|
||||
expect(res.body).to.have.property('body', 'comment 10');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -206,14 +286,13 @@ describe('Put /:comment_id', () => {
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body).to.have.property('body');
|
||||
expect(res.body.body).to.equal('Something body.');
|
||||
expect(res.body).to.have.property('body', 'Something body.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Delete /:comment_id', () => {
|
||||
describe('Remove /:comment_id', () => {
|
||||
|
||||
const comments = [{
|
||||
id: 'abc',
|
||||
@@ -259,9 +338,10 @@ describe('Delete /:comment_id', () => {
|
||||
chai.request(app)
|
||||
.delete('/api/v1/comments/abc')
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(201);
|
||||
Comment.findById({'id': 'abc'}).then((comment) => {
|
||||
expect(comment).to.be.null;
|
||||
Comment.findById('abc').then((comment) => {
|
||||
expect(comment).to.be.empty;
|
||||
});
|
||||
done();
|
||||
});
|
||||
@@ -321,8 +401,7 @@ describe('Post /:comment_id/status', () => {
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res).to.have.body;
|
||||
expect(res.body).to.have.property('status');
|
||||
expect(res.body.status).to.equal('accepted');
|
||||
expect(res.body).to.have.property('status', 'accepted');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -381,14 +460,10 @@ describe('Post /:comment_id/actions', () => {
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res).to.have.body;
|
||||
expect(res.body).to.have.property('item_type');
|
||||
expect(res.body.item_type).to.equal('comment');
|
||||
expect(res.body).to.have.property('action_type');
|
||||
expect(res.body.action_type).to.equal('flag');
|
||||
expect(res.body).to.have.property('item_id');
|
||||
expect(res.body.item_id).to.equal('abc');
|
||||
expect(res.body).to.have.property('user_id');
|
||||
expect(res.body.user_id).to.equal('456');
|
||||
expect(res.body).to.have.property('item_type', 'comment');
|
||||
expect(res.body).to.have.property('action_type', 'flag');
|
||||
expect(res.body).to.have.property('item_id', 'abc');
|
||||
expect(res.body).to.have.property('user_id', '456');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,8 +24,7 @@ describe('GET /settings', () => {
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res).to.be.json;
|
||||
expect(res.body).to.have.property('moderation');
|
||||
expect(res.body.moderation).to.equal('pre');
|
||||
expect(res.body).to.have.property('moderation', 'pre');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
@@ -33,30 +32,24 @@ describe('GET /settings', () => {
|
||||
|
||||
// update the settings.
|
||||
describe('update settings', () => {
|
||||
it('should respond ok to a PUT', () => {
|
||||
return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true})
|
||||
.then(() => {
|
||||
return chai.request(app)
|
||||
.put('/api/v1/settings')
|
||||
.send({moderation: 'post'})
|
||||
.then(res => {
|
||||
expect(res).to.have.status(204);
|
||||
|
||||
before(() => {
|
||||
return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true});
|
||||
});
|
||||
return Setting.getSettings();
|
||||
|
||||
it('should respond to a PUT with new settings', () => {
|
||||
chai.request(app)
|
||||
.put('/api/v1/settings')
|
||||
.send({moderation: 'post'}, (err, res) => {
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(204);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have updates settings', () => {
|
||||
chai.request(app)
|
||||
.get('/api/v1/settings')
|
||||
.end((err, res) => {
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res).to.be.json;
|
||||
expect(res.body).to.have.property('moderation');
|
||||
expect(res.body.moderation).to.equal('post');
|
||||
}).then(settings => {
|
||||
// confirm updated settings in db
|
||||
expect(settings).to.have.property('moderation');
|
||||
expect(settings.moderation).to.equal('post');
|
||||
}).catch(err => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,7 +60,6 @@ describe('api/stream: routes', () => {
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
if (err) {return done(err);}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user