diff --git a/.babelrc b/.babelrc index cf99c0639..ca2e2cead 100644 --- a/.babelrc +++ b/.babelrc @@ -2,7 +2,7 @@ "sourceMaps": true, "presets": [ "stage-0", - "es2015-minimal" + "es2015" ], "plugins": [ ["transform-decorators-legacy"], diff --git a/models/setting.js b/models/setting.js index 6f142c760..83fdcbe1d 100644 --- a/models/setting.js +++ b/models/setting.js @@ -84,7 +84,15 @@ SettingSchema.method('merge', function(src) { */ SettingSchema.method('filterForUser', function(user = false) { if (!user || !user.roles.includes('admin')) { - return _.pick(this.toJSON(), ['moderation', 'infoBoxEnable', 'infoBoxContent']); + return _.pick(this.toJSON(), [ + 'moderation', + 'infoBoxEnable', + 'infoBoxContent', + 'closeTimeout', + 'closedMessage', + 'charCountEnable', + 'charCount' + ]); } return this.toJSON(); @@ -106,11 +114,6 @@ const SettingService = module.exports = {}; */ const selector = {id: '1'}; -/** - * The list of settings that can be viewed publicly. - */ -const publicSettings = 'moderation infoBoxEnable infoBoxContent closeTimeout closedMessage charCountEnable charCount'; - /** * Cache expiry time in seconds for when the cached entry of the settings object * expires. 2 minutes. @@ -125,14 +128,6 @@ SettingService.retrieve = () => cache.wrap('settings', EXPIRY_TIME, () => { return Setting.findOne(selector); }).then((setting) => new Setting(setting)); -/** - * Gets publicly available settings records - * @return {Promise} settings the publicly viewable settings record - */ -SettingService.public = () => cache.wrap('publicSettings', EXPIRY_TIME, () => { - return Setting.findOne(selector, publicSettings); -}).then((setting) => new Setting(setting)); - /** * This will update the settings object with whatever you pass in * @param {object} setting a hash of whatever settings you want to update @@ -147,11 +142,9 @@ SettingService.update = (settings) => Setting.findOneAndUpdate(selector, { }).then((settings) => { // Invalidate the settings cache. - return Promise.all([ - cache.set('settings', settings, EXPIRY_TIME), - cache.invalidate('publicSettings') - ]) - .then(() => settings); + return cache + .set('settings', settings, EXPIRY_TIME) + .then(() => settings); }); /** diff --git a/package.json b/package.json index 53af9910b..33b21f0da 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ "babel-plugin-transform-react-jsx": "^6.8.0", "babel-polyfill": "^6.16.0", "babel-preset-es2015": "^6.18.0", - "babel-preset-es2015-minimal": "^2.1.0", "babel-preset-stage-0": "^6.16.0", "chai": "^3.5.0", "chai-http": "^3.0.0", diff --git a/routes/api/stream/index.js b/routes/api/stream/index.js index 246e71b15..8d70adbb4 100644 --- a/routes/api/stream/index.js +++ b/routes/api/stream/index.js @@ -38,7 +38,7 @@ router.get('/', (req, res, next) => { }), // Get the moderation setting from the settings. - Setting.public() + Setting.retrieve() ]) .then(([asset, settings]) => { diff --git a/tests/models/asset.js b/tests/models/asset.js index c9eff819e..7c5869caf 100644 --- a/tests/models/asset.js +++ b/tests/models/asset.js @@ -24,11 +24,12 @@ describe('models.Asset', () => { }); describe('#findByUrl', ()=> { + beforeEach(() => Asset.findOrCreateByUrl('http://test.com')); + it('should find an asset by a url', () => { return Asset.findByUrl('http://test.com') .then((asset) => { - expect(asset).to.have.property('url') - .and.to.equal('http://test.com'); + expect(asset).to.have.property('url', 'http://test.com'); }); }); diff --git a/tests/models/setting.js b/tests/models/setting.js index f62e0a7df..a7c97abfb 100644 --- a/tests/models/setting.js +++ b/tests/models/setting.js @@ -20,20 +20,6 @@ describe('models.Setting', () => { }); }); - describe('#public()', () => { - it('should have a moderation field defined', () => { - return Setting.public().then(settings => { - expect(settings).to.have.property('moderation').and.to.equal('pre'); - }); - }); - - it('should not have the wordlist field defined', () => { - return Setting.public().then(settings => { - expect(settings).to.have.property('wordlist').and.to.have.length(0); - }); - }); - }); - describe('#update()', () => { it('should update the settings with a passed object', () => { const mockSettings = {moderation: 'post', infoBoxEnable: true, infoBoxContent: 'yeah'}; diff --git a/tests/models/user.js b/tests/models/user.js index 43b60a784..3883e2e42 100644 --- a/tests/models/user.js +++ b/tests/models/user.js @@ -95,12 +95,17 @@ describe('models.User', () => { }); describe('#ban', () => { + let mockComment; + beforeEach(() => { - return Promise.all([ - Comment.create([{body: 'testing the comment for that user if it is rejected.', id: mockUsers[0].id}]) + return Comment.create([ + { + body: 'testing the comment for that user if it is rejected.', + id: mockUsers[0].id + } ]) - .then((comment) => { + .then(([comment]) => { mockComment = comment; }); }); @@ -109,11 +114,11 @@ describe('models.User', () => { return User .setStatus(mockUsers[0].id, 'banned', mockComment.id) .then(() => { - User.findById(mockUsers[0].id) - .then((user) => { - expect(user).to.have.property('status') - .and.to.equal('banned'); - }); + return User.findById(mockUsers[0].id); + }) + .then((user) => { + expect(user).to.have.property('status') + .and.to.equal('banned'); }); }); @@ -121,23 +126,20 @@ describe('models.User', () => { return User .setStatus(mockUsers[0].id, 'banned', mockComment.id) .then(() => { - Comment.findById(mockComment.id) - .then((comment) => { - expect(comment).to.have.property('status') - .and.to.equal('rejected'); - }); + return Comment.findById(mockComment.id); + }) + .then((comment) => { + expect(comment).to.have.property('status') + .and.to.equal('rejected'); }); }); it('should still disable and ban the user if there is no comment', () => { return User .setStatus(mockUsers[0].id, 'banned', '') - .then(() => { - User.findById(mockUsers[0].id) - .then((user) => { - expect(user).to.have.property('status') - .and.to.equal('banned'); - }); + .then(() => User.findById(mockUsers[0].id)) + .then((user) => { + expect(user).to.have.property('status', 'banned'); }); }); }); @@ -156,12 +158,9 @@ describe('models.User', () => { it('should set the status to active', () => { return User .setStatus(mockUsers[0].id, 'active', mockComment.id) - .then(() => { - User.findById(mockUsers[0].id) - .then((user) => { - expect(user).to.have.property('status') - .and.to.equal('active'); - }); + .then(() => User.findById(mockUsers[0].id)) + .then((user) => { + expect(user).to.have.property('status', 'active'); }); }); });