From ca5049feeb2effd7a8001303b6dd3c67f8cedf6a Mon Sep 17 00:00:00 2001 From: David Jay Date: Mon, 28 Nov 2016 16:52:00 -0500 Subject: [PATCH] Adding settings to stream. --- routes/api/stream/index.js | 20 +++++++++++--------- tests/routes/api/stream/index.js | 9 +++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/routes/api/stream/index.js b/routes/api/stream/index.js index acbfe3d77..a22fdd691 100644 --- a/routes/api/stream/index.js +++ b/routes/api/stream/index.js @@ -18,21 +18,21 @@ router.get('/', (req, res, next) => { // Get the asset_id for this url (or create it if it doesn't exist) Promise.all([ Asset.findOrCreateByUrl(decodeURIComponent(req.query.asset_url)), - Setting.getModerationSetting() + Setting.getSettings() ]) - .then(([asset, {moderation}]) => { + .then(([asset, settings]) => { // Get the sitewide moderation setting and return the appropriate comments - switch(moderation){ + switch(settings.moderation){ case 'pre': - return Promise.all([Comment.findAcceptedByAssetId(asset.id), asset]); + return Promise.all([Comment.findAcceptedByAssetId(asset.id), asset, settings]); case 'post': - return Promise.all([Comment.findAcceptedAndNewByAssetId(asset.id), asset]); + return Promise.all([Comment.findAcceptedAndNewByAssetId(asset.id), asset, settings]); default: return Promise.reject(new Error('Moderation setting not found.')); } }) // Get all the users and actions for those comments. - .then(([comments, asset]) => { + .then(([comments, asset, settings]) => { return Promise.all([ [asset], comments, @@ -41,15 +41,17 @@ router.get('/', (req, res, next) => { asset.id, ...comments.map((comment) => comment.id), ...comments.map((comment) => comment.author_id) - ])) + ])), + settings ]); }) - .then(([assets, comments, users, actions]) => { + .then(([assets, comments, users, actions, settings]) => { res.json({ assets, comments, users, - actions + actions, + settings }); }) .catch(error => { diff --git a/tests/routes/api/stream/index.js b/tests/routes/api/stream/index.js index 009184b6b..3f032c1d7 100644 --- a/tests/routes/api/stream/index.js +++ b/tests/routes/api/stream/index.js @@ -91,10 +91,11 @@ describe('api/stream: routes', () => { .query({'asset_url': 'http://test.com'}) .then(res => { expect(res).to.have.status(200); - expect(res.body.assets.length).to.equal(1); - expect(res.body.comments.length).to.equal(1); - expect(res.body.users.length).to.equal(1); - expect(res.body.actions.length).to.equal(1); + expect(res.body.assets[0]).to.have.property('url'); + expect(res.body.comments[0]).to.have.property('body'); + expect(res.body.users[0]).to.have.property('displayName'); + expect(res.body.actions[0]).to.have.property('action_type'); + expect(res.body.settings).to.have.property('moderation'); }); }); });