Merge branch 'master' of github.com:coralproject/talk into wordlist

This commit is contained in:
David Jay
2016-12-09 13:05:11 -05:00
30 changed files with 451 additions and 191 deletions
+20 -24
View File
@@ -11,14 +11,14 @@ describe('models.Comment', () => {
const comments = [{
body: 'comment 10',
asset_id: '123',
status: [],
status_history: [],
parent_id: '',
author_id: '123',
id: '1'
}, {
body: 'comment 20',
asset_id: '123',
status: [{
status_history: [{
type: 'accepted'
}],
parent_id: '',
@@ -27,14 +27,14 @@ describe('models.Comment', () => {
}, {
body: 'comment 30',
asset_id: '456',
status: [],
status_history: [],
parent_id: '',
author_id: '456',
id: '3'
}, {
body: 'comment 40',
asset_id: '123',
status: [{
status_history: [{
type: 'rejected'
}],
parent_id: '',
@@ -43,7 +43,7 @@ describe('models.Comment', () => {
}, {
body: 'comment 50',
asset_id: '1234',
status: [{
status_history: [{
type: 'premod'
}],
parent_id: '',
@@ -52,7 +52,7 @@ describe('models.Comment', () => {
}, {
body: 'comment 60',
asset_id: '1234',
status: [{
status_history: [{
type: 'premod'
}],
parent_id: '',
@@ -99,8 +99,7 @@ describe('models.Comment', () => {
expect(c).to.not.be.null;
expect(c.id).to.not.be.null;
expect(c.id).to.be.uuid;
expect(c.status).to.have.length(1);
expect(c.status[0]).to.have.property('type', 'accepted');
expect(c.status).to.be.equal('accepted');
});
});
@@ -116,17 +115,15 @@ describe('models.Comment', () => {
}]).then(([c1, c2, c3]) => {
expect(c1).to.not.be.null;
expect(c1.id).to.be.uuid;
expect(c1.status).to.have.length(1);
expect(c1.status[0]).to.have.property('type', 'accepted');
expect(c1.status).to.be.equal('accepted');
expect(c2).to.not.be.null;
expect(c2.id).to.be.uuid;
expect(c2.status).to.have.length(0);
expect(c2.status).to.be.null;
expect(c3).to.not.be.null;
expect(c3.id).to.be.uuid;
expect(c3.status).to.have.length(1);
expect(c3.status[0]).to.have.property('type', 'rejected');
expect(c3.status).to.be.equal('rejected');
});
});
@@ -220,17 +217,16 @@ describe('models.Comment', () => {
return Comment.findById(comment_id)
.then((c) => {
expect(c).to.have.property('status');
expect(c.status).to.have.length(0);
expect(c.status).to.be.null;
return Comment.pushStatus(comment_id, 'rejected', '123');
})
.then(() => Comment.findById(comment_id))
.then((c) => {
expect(c).to.have.property('status');
expect(c.status).to.have.length(1);
expect(c.status[0]).to.have.property('type', 'rejected');
expect(c.status[0]).to.have.property('assigned_by', '123');
expect(c.status_history).to.have.length(1);
expect(c.status_history[0]).to.have.property('type', 'rejected');
expect(c.status_history[0]).to.have.property('assigned_by', '123');
});
});
@@ -238,13 +234,13 @@ describe('models.Comment', () => {
return Comment.pushStatus(comments[1].id, 'rejected', '123')
.then(() => Comment.findById(comments[1].id))
.then((c) => {
expect(c).to.have.property('status');
expect(c.status).to.have.length(2);
expect(c.status[0]).to.have.property('type', 'accepted');
expect(c.status[0]).to.have.property('assigned_by', null);
expect(c).to.have.property('status_history');
expect(c.status_history).to.have.length(2);
expect(c.status_history[0]).to.have.property('type', 'accepted');
expect(c.status_history[0]).to.have.property('assigned_by', null);
expect(c.status[1]).to.have.property('type', 'rejected');
expect(c.status[1]).to.have.property('assigned_by', '123');
expect(c.status_history[1]).to.have.property('type', 'rejected');
expect(c.status_history[1]).to.have.property('assigned_by', '123');
});
});
+14
View File
@@ -39,4 +39,18 @@ describe('models.Setting', () => {
});
});
});
describe('#merge', () => {
it('should merge a settings object and its overrides', () => {
return Setting
.retrieve()
.then((settings) => {
let ovrSett = {moderation: 'post'};
settings.merge(ovrSett);
expect(settings).to.have.property('moderation', 'post');
});
});
});
});
+61 -16
View File
@@ -19,6 +19,12 @@ const settings = {id: '1', moderation: 'pre'};
describe('/api/v1/comments', () => {
// Ensure that the settings are always available.
beforeEach(() => Promise.all([
wordlist.insert(['bad words']),
Setting.init(settings)
]));
describe('#get', () => {
const comments = [{
body: 'comment 10',
@@ -32,13 +38,13 @@ describe('/api/v1/comments', () => {
body: 'comment 20',
asset_id: 'asset',
author_id: '456',
status: [{
status_history: [{
type: 'rejected'
}]
}, {
body: 'comment 30',
asset_id: '456',
status: [{
status_history: [{
type: 'accepted'
}]
}];
@@ -75,11 +81,7 @@ describe('/api/v1/comments', () => {
return Action.create(actions);
}),
User.createLocalUsers(users),
wordlist.insert([
'bad words'
]),
Setting.init(settings)
User.createLocalUsers(users)
]);
});
@@ -142,11 +144,19 @@ describe('/api/v1/comments', () => {
describe('#post', () => {
let asset_id;
beforeEach(() => Asset.findOrCreateByUrl('https://coralproject.net/section/article-is-the-best').then((asset) => {
// Update the asset id.
asset_id = asset.id;
}));
it('should create a comment', () => {
return chai.request(app)
.post('/api/v1/comments')
.set(passport.inject({roles: []}))
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': '1', 'parent_id': ''})
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': asset_id, 'parent_id': ''})
.then((res) => {
expect(res).to.have.status(201);
expect(res.body).to.have.property('id');
@@ -157,12 +167,11 @@ describe('/api/v1/comments', () => {
return chai.request(app)
.post('/api/v1/comments')
.set(passport.inject({roles: []}))
.send({'body': 'bad words are the baddest', 'author_id': '123', 'asset_id': '1', 'parent_id': ''})
.send({'body': 'bad words are the baddest', 'author_id': '123', 'asset_id': asset_id, 'parent_id': ''})
.then((res) => {
expect(res).to.have.status(201);
expect(res.body).to.have.property('id');
expect(res.body).to.have.property('status').and.to.have.length(1);
expect(res.body.status[0]).to.have.property('type', 'rejected');
expect(res.body).to.have.property('status', 'rejected');
});
});
@@ -184,10 +193,46 @@ describe('/api/v1/comments', () => {
expect(res).to.have.status(201);
expect(res.body).to.have.property('id');
expect(res.body).to.have.property('asset_id');
expect(res.body).to.have.property('status').and.to.have.length(1);
expect(res.body.status[0]).to.have.property('type', 'premod');
expect(res.body).to.have.property('status', 'premod');
});
});
it('shouldn\'t create a comment when the asset has expired commenting', () => {
return Asset.create({
closedAt: new Date().setDate(0),
closedMessage: 'tests said expired!'
})
.then((asset) => {
return chai.request(app)
.post('/api/v1/comments')
.set(passport.inject({roles: []}))
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': asset.id, 'parent_id': ''});
})
.then((res) => {
expect(res).to.have.status(500);
})
.catch((err) => {
expect(err.response.body).to.not.be.null;
expect(err.response.body).to.have.property('message');
expect(err.response.body.message).to.contain('tests said expired!');
});
});
it('should create a comment when the asset has not expired yet', () => {
return Asset.create({
closedAt: new Date().setDate(32),
closedMessage: 'tests said expired!'
})
.then((asset) => {
return chai.request(app)
.post('/api/v1/comments')
.set(passport.inject({roles: []}))
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': asset.id, 'parent_id': ''});
})
.then((res) => {
expect(res).to.have.status(201);
});
});
});
});
@@ -301,20 +346,20 @@ describe('/api/v1/comments/:comment_id/actions', () => {
body: 'comment 10',
asset_id: 'asset',
author_id: '123',
status: []
status_history: []
}, {
id: 'def',
body: 'comment 20',
asset_id: 'asset',
author_id: '456',
status: [{
status_history: [{
type: 'rejected'
}]
}, {
id: 'hij',
body: 'comment 30',
asset_id: '456',
status: [{
status_history: [{
type: 'accepted'
}]
}];
+3 -3
View File
@@ -21,7 +21,7 @@ describe('/api/v1/queue', () => {
body: 'comment 10',
asset_id: 'asset',
author_id: '123',
status: [{
status_history: [{
type: 'rejected'
}]
}, {
@@ -29,14 +29,14 @@ describe('/api/v1/queue', () => {
body: 'comment 20',
asset_id: 'asset',
author_id: '456',
status: [{
status_history: [{
type: 'premod'
}]
}, {
id: 'hij',
body: 'comment 30',
asset_id: '456',
status: [{
status_history: [{
type: 'accepted'
}]
}];
+15 -4
View File
@@ -25,7 +25,7 @@ describe('/api/v1/stream', () => {
body: 'comment 10',
author_id: '',
parent_id: '',
status: [{
status_history: [{
type: 'accepted'
}]
}, {
@@ -33,21 +33,21 @@ describe('/api/v1/stream', () => {
body: 'comment 20',
author_id: '',
parent_id: '',
status: []
status_history: []
}, {
id: 'uio',
body: 'comment 30',
asset_id: 'asset',
author_id: '456',
parent_id: '',
status: [{
status_history: [{
type: 'accepted'
}]
}, {
id: 'hij',
body: 'comment 40',
asset_id: '456',
status: [{
status_history: [{
type: 'rejected'
}]
}];
@@ -116,6 +116,16 @@ describe('/api/v1/stream', () => {
});
});
it('should reject requests without a scheme in the asset_url', () => {
return chai.request(app)
.get('/api/v1/stream')
.query({asset_url: 'test.com'})
.catch((err) => {
expect(err).to.have.status(400);
expect(err.response.body.message).to.contain('asset_url is invalid');
});
});
it('should merge the settings when the asset contains settings to override it with', () => {
return chai.request(app)
.get('/api/v1/stream')
@@ -126,6 +136,7 @@ describe('/api/v1/stream', () => {
expect(res.body.comments.length).to.equal(1);
expect(res.body.users.length).to.equal(1);
expect(res.body.settings).to.have.property('moderation', 'pre');
expect(res.body.settings).to.not.have.property('wordlist');
});
});
});