From 9916edc1277e3854d651a9ff2465ea1dfbfcd3e2 Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 4 Nov 2016 15:10:28 -0700 Subject: [PATCH 01/22] Adds implementation for get all comments --- routes/api/comments/index.js | 8 +++-- tests/routes/api/comments/index.js | 54 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index df9bbc456..c468d427f 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -8,8 +8,12 @@ const router = express.Router(); //============================================================================== -router.get('/', (req, res) => { - res.send('Read all of the comments ever'); +router.get('/', (req, res, next) => { + Comment.find({}).then((comments) => { + res.status(200).json(comments); + }).catch(error => { + next(error); + }); }); router.get('/:comment_id', (req, res, next) => { diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index ad21e54ec..db986db0c 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -13,6 +13,60 @@ const Comment = require('../../../../models/comment'); const Action = require('../../../../models/action'); const User = require('../../../../models/user'); + +describe('Get /: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 = [{ + id: '123', + display_name: 'John', + },{ + id: '456', + display_name: 'Paul', + }] + + const actions = [{ + action_type: 'flag', + item_id: 'abc' + },{ + action_type: 'like', + item_id: 'hij' + }] + + beforeEach(() => { + return Comment.create(comments).then(() => { + return User.create(users) + }).then(() => { + return Action.create(actions) + }) + }) + + it('should return all the comments', function(done){ + chai.request(app) + .get('/api/v1/comments') + .end(function(err, res){ + expect(err).to.be.null; + expect(res).to.have.status(200); + if (err) return done(err); + done(); + }); + }) +}) + describe('Post /comments', () => { const users = [{ id: '123', From f04e2505ec77dda0409d132b762b65f225335188 Mon Sep 17 00:00:00 2001 From: David Jay Date: Mon, 7 Nov 2016 13:25:45 -0500 Subject: [PATCH 02/22] Adding title to iframe for screen readers. --- client/coral-embed-stream/public/samplearticle.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-embed-stream/public/samplearticle.html b/client/coral-embed-stream/public/samplearticle.html index 493fc29fa..e973ee9be 100644 --- a/client/coral-embed-stream/public/samplearticle.html +++ b/client/coral-embed-stream/public/samplearticle.html @@ -9,7 +9,7 @@
From 108c50cb95c14721394b530de23de7269b635caf Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Mon, 7 Nov 2016 11:28:09 -0700 Subject: [PATCH 03/22] add tests to settings models/endpoints --- tests/models/setting.js | 32 +++++++++++++++ tests/routes/api/settings/index.js | 62 ++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/models/setting.js create mode 100644 tests/routes/api/settings/index.js diff --git a/tests/models/setting.js b/tests/models/setting.js new file mode 100644 index 000000000..53d0d6386 --- /dev/null +++ b/tests/models/setting.js @@ -0,0 +1,32 @@ +/* eslint-env node, mocha */ + +require('../utils/mongoose'); + +const Setting = require('../../models/setting'); +const expect = require('chai').expect; + +describe('Setting: model', () => { + + beforeEach(() => { + const defaults = {id: 1, moderation: 'pre'}; + return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}) + }) + + describe('#getSettings()', () => { + it('should have a moderation field defined', () => { + return Setting.getSettings().then(settings => { + expect(settings).to.have.property('moderation').and.to.equal('pre'); + }); + }); + }); + + describe('#updateSettings()', () => { + it('should update the settings with a passed object', () => { + const mockSettings = {moderation: 'post'}; + return Setting.updateSettings(mockSettings).then(updatedSettings => { + expect(updatedSettings).to.have.property('moderation').and.to.equal('post'); + }); + }); + }); + +}); diff --git a/tests/routes/api/settings/index.js b/tests/routes/api/settings/index.js new file mode 100644 index 000000000..fbf55d95f --- /dev/null +++ b/tests/routes/api/settings/index.js @@ -0,0 +1,62 @@ +process.env.NODE_ENV = 'test'; + +require('../../../utils/mongoose'); + +const app = require('../../../../app'); +const chai = require('chai'); +const chaiHttp = require('chai-http'); +chai.use(chaiHttp); +const expect = chai.expect; + +const Setting = require('../../../../models/setting'); +const defaults = {id: '1', moderation: 'pre'}; + +describe('GET /settings', () => { + + beforeEach(() => { + return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}); + }); + + it('should return a settings object', done => { + 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('pre'); + done(err); + }) + }); +}); + +// update the settings. +describe('update settings', () => { + + before(() => { + return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}); + }); + + 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'); + }); + }); +}); From cb682981715f131f9d08604ad30578b683cc74b4 Mon Sep 17 00:00:00 2001 From: David Jay Date: Mon, 7 Nov 2016 13:39:33 -0500 Subject: [PATCH 04/22] Adding temporary user name field to commentbox. --- client/coral-embed-stream/style/default.css | 8 +++- client/coral-plugin-commentbox/CommentBox.js | 45 +++++++++++++------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/client/coral-embed-stream/style/default.css b/client/coral-embed-stream/style/default.css index 219a7aef5..4421bfaed 100644 --- a/client/coral-embed-stream/style/default.css +++ b/client/coral-embed-stream/style/default.css @@ -56,7 +56,7 @@ hr { .coral-plugin-commentbox-textarea { flex: 1; - padding: 10px; + padding: 5px; } .coral-plugin-commentbox-button-container { @@ -75,6 +75,12 @@ hr { border-radius: 2px; } +.coral-plugin-commentbox-username { + width: 50%; + padding-left: 5px; + margin-bottom: 5px; +} + /* Comment styles */ .comment { margin-bottom: 10px; diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index c893be075..1bd138af9 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -8,32 +8,34 @@ class CommentBox extends Component { static propTypes = { postItem: PropTypes.func, updateItem: PropTypes.func, - item_id: PropTypes.string, + id: PropTypes.string, comments: PropTypes.array, reply: PropTypes.bool } state = { - content: '' + body: '', + username: '' } postComment = () => { - const {postItem, updateItem, item_id, reply, addNotification, appendItemArray} = this.props + const {postItem, updateItem, id, reply, addNotification, appendItemArray} = this.props let comment = { - content: this.state.content + body: this.state.body, + asset_id: id, + username: this.state.username } let related if (reply) { - comment.parent_id = item_id + comment.parent_id = id related = 'children' } else { - comment.asset_id = item_id related = 'comments' } - updateItem(item_id, 'showReply', false) + updateItem(id, 'showReply', false) postItem(comment, 'comments') - .then((id) => { - appendItemArray(item_id, related, id) + .then((comment_id) => { + appendItemArray(id, related, comment_id) addNotification('success', 'Your comment has been posted.') }).catch((err) => console.error(err)) this.setState({content: ''}) @@ -43,21 +45,30 @@ class CommentBox extends Component { const {styles, reply} = this.props // How to handle language in plugins? Should we have a dependency on our central translation file? return
+
+ this.setState({username: e.target.value})}/> +
+ className={name + '-container'}>