Merge pull request #170 from coralproject/build-fix

Updated tests, fixes #166
This commit is contained in:
Riley Davis
2016-12-13 16:24:49 -07:00
committed by GitHub
7 changed files with 41 additions and 63 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
"sourceMaps": true,
"presets": [
"stage-0",
"es2015-minimal"
"es2015"
],
"plugins": [
["transform-decorators-legacy"],
+12 -19
View File
@@ -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);
});
/**
-1
View File
@@ -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",
+1 -1
View File
@@ -38,7 +38,7 @@ router.get('/', (req, res, next) => {
}),
// Get the moderation setting from the settings.
Setting.public()
Setting.retrieve()
])
.then(([asset, settings]) => {
+3 -2
View File
@@ -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');
});
});
-14
View File
@@ -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'};
+24 -25
View File
@@ -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');
});
});
});