Merge branch 'master' of https://github.com/coralproject/talk into stream-e2e

This commit is contained in:
David Jay
2016-11-22 15:04:36 -05:00
64 changed files with 1502 additions and 4209 deletions
@@ -29,21 +29,23 @@ describe('itemActions', () => {
],
actions: [
{
type: 'like',
id: '123',
action_type: 'like',
item_id: '123',
count: 1,
id: 'like_123',
current_user: false
},
{
type: 'flag',
id: '456',
action_type: 'flag',
item_id: '456',
count: 5,
id: 'flag_456',
current_user: true
}
]
};
it('should get an stream from an asset_id and send the appropriate dispatches', () => {
it('should get an stream from an asset_url and send the appropriate dispatches', () => {
fetchMock.get('*', JSON.stringify(response));
return actions.getStream(assetUrl)(store.dispatch)
.then((res) => {
@@ -173,7 +175,7 @@ describe('itemActions', () => {
fetchMock.delete('*', {});
return actions.deleteAction('abc', 'flag', '123', 'comments')(store.dispatch)
.then(response => {
expect(fetchMock.calls().matched[0][0]).to.equal('/api/v1/comments/abc/actions');
expect(fetchMock.calls().matched[0][0]).to.equal('/api/v1/actions/abc');
expect(response).to.deep.equal({});
});
});
+9 -8
View File
@@ -10,10 +10,6 @@ describe('Action: models', () => {
action_type: 'flag',
item_id: '123',
item_type: 'comments'
}, {
action_type: 'like',
item_id: '789',
item_type: 'comments'
}, {
action_type: 'flag',
item_id: '456',
@@ -22,6 +18,10 @@ describe('Action: models', () => {
action_type: 'flag',
item_id: '123',
item_type: 'comments'
}, {
action_type: 'like',
item_id: '123',
item_type: 'comments'
}]).then((actions) => {
mockActions = actions;
});
@@ -39,7 +39,7 @@ describe('Action: models', () => {
describe('#findByItemIdArray()', () => {
it('should find an array of actions from an array of item_ids', () => {
return Action.findByItemIdArray(['123', '456']).then((result) => {
expect(result).to.have.length(3);
expect(result).to.have.length(4);
});
});
});
@@ -48,16 +48,17 @@ describe('Action: models', () => {
it('should return properly formatted summaries from an array of item_ids', () => {
return Action.getActionSummaries(['123', '789']).then((result) => {
expect(result).to.have.length(2);
const sorted = result.sort((a, b) => a.count - b.count);
delete sorted[0].id;
delete sorted[1].id;
expect(sorted[0]).to.deep.equal({
action_type: 'like',
count: 1,
item_id: '789',
item_id: '123',
item_type: 'comments',
current_user: false
});
expect(sorted[1]).to.deep.equal({
action_type: 'flag',
count: 2,
+16
View File
@@ -43,6 +43,22 @@ describe('User: models', () => {
});
});
describe('#findPublicByIdArray()', () => {
it('should find an array of users from an array of ids', () => {
const ids = mockUsers.map((user) => user.id);
return User.findPublicByIdArray(ids).then((result) => {
expect(result).to.have.length(3);
const sorted = result.sort((a, b) => {
if(a.displayName < b.displayName) {return -1;}
if(a.displayName > b.displayName) {return 1;}
return 0;
});
expect(sorted[0]).to.have.property('displayName')
.and.to.equal('Marvel');
});
});
});
describe('#findLocalUser', () => {
it('should find a user when we give the right credentials', () => {
+52 -103
View File
@@ -10,6 +10,7 @@ const expect = chai.expect;
chai.should();
chai.use(require('chai-http'));
const wordlist = require('../../../../services/wordlist');
const Comment = require('../../../../models/comment');
const Action = require('../../../../models/action');
const User = require('../../../../models/user');
@@ -64,13 +65,13 @@ describe('Get /comments', () => {
]);
});
it('should return all the comments', function(done){
chai.request(app)
it('should return all the comments', () => {
return chai.request(app)
.get('/api/v1/comments')
.end(function(err, res){
expect(err).to.be.null;
.then((res) => {
expect(res).to.have.status(200);
done();
});
});
});
@@ -122,48 +123,42 @@ describe('Get comments by status and action', () => {
]);
});
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;
it('should return all the rejected comments', () => {
return chai.request(app)
.get('/api/v1/comments?status=rejected')
.then((res) => {
expect(res).to.have.status(200);
expect(res.body[0]).to.have.property('id', 'abc');
done();
});
});
it('should return all the approved comments', function(done){
chai.request(app)
.get('/api/v1/comments/status/accepted')
.end(function(err, res){
expect(err).to.be.null;
it('should return all the approved comments', () => {
return chai.request(app)
.get('/api/v1/comments?status=accepted')
.then((res) => {
expect(res).to.have.status(200);
expect(res.body[0]).to.have.property('id', 'hij');
done();
});
});
it('should return all the new comments', function(done){
chai.request(app)
.get('/api/v1/comments/status/new')
.end(function(err, res){
expect(err).to.be.null;
it('should return all the new comments', () => {
return chai.request(app)
.get('/api/v1/comments?status=new')
.then((res) => {
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){
it('should return all the flagged comments', () => {
return chai.request(app)
.get('/api/v1/comments?action_type=flag')
.then((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();
});
});
});
@@ -190,18 +185,31 @@ describe('Post /comments', () => {
beforeEach(() => {
return Promise.all([
User.createLocalUsers(users),
Action.create(actions)
Action.create(actions),
wordlist.insert([
'bad words'
])
]);
});
it('it should create a comment', function(done) {
chai.request(app)
it('should create a comment', () => {
return chai.request(app)
.post('/api/v1/comments')
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': '1', 'parent_id': ''})
.end(function(err, res){
expect(res).to.have.status(200);
.then((res) => {
expect(res).to.have.status(201);
expect(res.body).to.have.property('id');
done();
});
});
it('should create a comment with a rejected status if it contains a bad word', () => {
return chai.request(app)
.post('/api/v1/comments')
.send({'body': 'bad words are the baddest', 'author_id': '123', 'asset_id': '1', 'parent_id': ''})
.then((res) => {
expect(res).to.have.status(201);
expect(res.body).to.have.property('id');
expect(res.body).to.have.property('status', 'rejected');
});
});
});
@@ -251,72 +259,14 @@ describe('Get /:comment_id', () => {
]);
});
it('should return the right comment for the comment_id', function(done){
chai.request(app)
it('should return the right comment for the comment_id', () => {
return chai.request(app)
.get('/api/v1/comments/abc')
.end(function(err, res){
expect(err).to.be.null;
.then((res) => {
expect(res).to.have.status(200);
expect(res).to.have.property('body');
expect(res.body).to.have.property('body', 'comment 10');
done();
});
});
});
describe('Put /:comment_id', () => {
const comments = [{
id: 'abc',
body: 'comment 10',
asset_id: 'asset',
author_id: '123'
}, {
id: 'def',
body: 'comment 20',
asset_id: 'asset',
author_id: '456'
}, {
id: 'hij',
body: 'comment 30',
asset_id: '456'
}];
const users = [{
displayName: 'Ana',
email: 'ana@gmail.com',
password: '123'
}, {
displayName: 'Maria',
email: 'maria@gmail.com',
password: '123'
}];
const actions = [{
action_type: 'flag',
item_id: 'abc'
}, {
action_type: 'like',
item_id: 'hij'
}];
beforeEach(() => {
return Promise.all([
Comment.create(comments),
User.createLocalUsers(users),
Action.create(actions)
]);
});
it('it should update comment', function(done) {
chai.request(app)
.post('/api/v1/comments/abc')
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': '1', 'parent_id': ''})
.end(function(err, res){
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res.body).to.have.property('body', 'Something body.');
done();
});
});
});
@@ -369,7 +319,7 @@ describe('Remove /:comment_id', () => {
return chai.request(app)
.delete('/api/v1/comments/abc')
.then((res) => {
expect(res).to.have.status(201);
expect(res).to.have.status(204);
return Comment.findById('abc');
})
@@ -384,7 +334,7 @@ process.on('unhandledRejection', (reason) => {
console.error(reason);
});
describe('Post /:comment_id/status', () => {
describe('Put /:comment_id/status', () => {
const comments = [{
id: 'abc',
@@ -433,12 +383,11 @@ describe('Post /:comment_id/status', () => {
it('it should update status', function() {
return chai.request(app)
.post('/api/v1/comments/abc/status')
.put('/api/v1/comments/abc/status')
.send({status: 'accepted'})
.then((res) => {
expect(res).to.have.status(200);
expect(res).to.have.body;
expect(res.body).to.have.property('status', 'accepted');
expect(res).to.have.status(204);
expect(res.body).to.be.empty;
});
});
});
@@ -495,7 +444,7 @@ describe('Post /:comment_id/actions', () => {
.post('/api/v1/comments/abc/actions')
.send({'user_id': '456', 'action_type': 'flag'})
.then((res) => {
expect(res).to.have.status(200);
expect(res).to.have.status(201);
expect(res).to.have.body;
expect(res.body).to.have.property('item_type', 'comment');
expect(res.body).to.have.property('action_type', 'flag');
+119
View File
@@ -0,0 +1,119 @@
const expect = require('chai').expect;
const wordlist = require('../../services/wordlist');
describe('wordlist: services', () => {
before(() => wordlist.insert([
'BAD',
'bad',
'how to murder',
'how to kill'
]));
beforeEach(() => {
expect(wordlist.list).to.not.be.empty;
expect(wordlist.enabled).to.be.true;
});
describe('#init', () => {
it('has entries', () => {
expect(wordlist.list).to.not.be.empty;
expect(wordlist.enabled).to.be.true;
});
});
describe('#match', () => {
it('does match on a bad word', () => {
[
'how to kill',
'what is bad',
'bad',
'BAD.',
'how to murder',
'How To mUrDer'
].forEach((word) => {
expect(wordlist.match(word)).to.be.true;
});
});
it('does not match on a good word', () => {
[
'how to',
'kill',
'bads',
'how to be a great person?',
'how to not kill?'
].forEach((word) => {
expect(wordlist.match(word)).to.be.false;
});
});
});
describe('#filter', () => {
it('matches on bodies containing bad words', (done) => {
let req = {
body: {
content: 'how to kill?'
}
};
wordlist.filter('content')(req, {}, (err) => {
expect(err).to.be.undefined;
expect(req).to.have.property('wordlist');
expect(req.wordlist).to.have.property('matched');
expect(req.wordlist.matched).to.be.equal(wordlist.ErrContainsProfanity);
done();
});
});
it('does not match on bodies not containing bad words', (done) => {
let req = {
body: {
content: 'how to be a great person?'
}
};
wordlist.filter('content')(req, {}, (err) => {
expect(err).to.be.undefined;
expect(req).to.have.property('wordlist');
expect(req.wordlist).to.have.property('matched');
expect(req.wordlist.matched).to.be.false;
done();
});
});
it('does not match on bodies not containing the bad word field', (done) => {
let req = {
body: {
author: 'how to kill?',
content: 'how to be a great person?'
}
};
wordlist.filter('content')(req, {}, (err) => {
expect(err).to.be.undefined;
expect(req).to.have.property('wordlist');
expect(req.wordlist).to.have.property('matched');
expect(req.wordlist.matched).to.be.false;
done();
});
});
});
});