make tests pass

This commit is contained in:
riley
2017-01-09 10:47:28 -07:00
parent 976f0762b3
commit 7bc848b801
10 changed files with 117 additions and 85 deletions
+1 -1
View File
@@ -48,7 +48,7 @@
"include-text": "Include your text here.",
"comment-settings": "Comment Settings",
"embed-comment-stream": "Embed Comment Stream",
"banned-word-header": "Write the bannned words list",
"banned-word-header": "Write the banned words list",
"suspect-word-header": "Write the suspect words list",
"banned-word-text": "Comments which contain these words or phrases (not case-sensitive) will be automatically removed from the comment stream. Type a word and press Enter or Tab to add. Optionally paste a comma-separated list.",
"suspect-word-text": "Comments which contain these words or phrases (not case-sensitive) will be highlighted in the comment stream. Type a word and press Enter or Tab to add. Optionally paste a comma-separated list.",
+1 -1
View File
@@ -3,5 +3,5 @@ const Setting = require('./models/setting');
module.exports = () => Promise.all([
// Upsert the settings object.
Setting.init({id: '1', moderation: 'pre'})
Setting.init({id: '1', moderation: 'pre', wordlist: {banned: [], suspect: []}})
]);
+10 -7
View File
@@ -3,7 +3,7 @@ const User = require('../../models/user');
const Action = require('../../models/action');
const Setting = require('../../models/setting');
const settings = {id: '1', moderation: 'pre'};
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
const expect = require('chai').expect;
@@ -82,12 +82,15 @@ describe('models.Comment', () => {
user_id: '456'
}];
beforeEach(() => Promise.all([
Setting.init(settings),
Comment.create(comments),
User.createLocalUsers(users),
Action.create(actions)
]));
beforeEach(() => {
return Setting.init(settings).then(() => {
return Promise.all([
Comment.create(comments),
User.createLocalUsers(users),
Action.create(actions)
]);
});
});
describe('#publicCreate()', () => {
+19 -14
View File
@@ -1,25 +1,30 @@
const User = require('../../models/user');
const Comment = require('../../models/comment');
const Setting = require('../../models/setting');
const expect = require('chai').expect;
describe('models.User', () => {
let mockUsers;
beforeEach(() => {
return User.createLocalUsers([{
email: 'stampi@gmail.com',
displayName: 'Stampi',
password: '1Coral!-'
}, {
email: 'sockmonster@gmail.com',
displayName: 'Sockmonster',
password: '2Coral!2'
}, {
email: 'marvel@gmail.com',
displayName: 'Marvel',
password: '3Coral!3'
}]).then((users) => {
mockUsers = users;
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
return Setting.init(settings).then(() => {
return User.createLocalUsers([{
email: 'stampi@gmail.com',
displayName: 'Stampi',
password: '1Coral!-'
}, {
email: 'sockmonster@gmail.com',
displayName: 'Sockmonster',
password: '2Coral!2'
}, {
email: 'marvel@gmail.com',
displayName: 'Marvel',
password: '3Coral!3'
}]).then((users) => {
mockUsers = users;
});
});
});
+11 -7
View File
@@ -24,14 +24,18 @@ const Setting = require('../../../../models/setting');
describe('/api/v1/auth/local', () => {
let mockUser;
beforeEach(() => User.createLocalUser('maria@gmail.com', 'password!', 'Maria').then((user) => {
mockUser = user;
}));
beforeEach(() => {
const settings = {requireEmailConfirmation: false, wordlist: {banned: ['bad'], suspect: ['naughty']}};
return Setting.init(settings).then(() => {
return User.createLocalUser('maria@gmail.com', 'password!', 'Maria')
.then((user) => {
mockUser = user;
});
});
});
describe('email confirmation disabled', () => {
beforeEach(() => Setting.init({requireEmailConfirmation: false}));
describe('#post', () => {
it('should send back the user on a successful login', () => {
return chai.request(app)
@@ -41,7 +45,7 @@ describe('/api/v1/auth/local', () => {
expect(res2).to.have.status(200);
expect(res2).to.be.json;
expect(res2.body).to.have.property('user');
expect(res2.body.user).to.have.property('displayName', 'Maria');
expect(res2.body.user).to.have.property('displayName', 'maria');
});
});
@@ -84,7 +88,7 @@ describe('/api/v1/auth/local', () => {
expect(res).to.have.status(200);
expect(res).to.be.json;
expect(res.body).to.have.property('user');
expect(res.body.user).to.have.property('displayName', 'Maria');
expect(res.body.user).to.have.property('displayName', 'maria');
});
});
});
+14 -10
View File
@@ -346,11 +346,13 @@ describe('/api/v1/comments/:comment_id', () => {
}];
beforeEach(() => {
return Promise.all([
Comment.create(comments),
User.createLocalUsers(users),
Action.create(actions)
]);
return Setting.init(settings).then(() => {
return Promise.all([
Comment.create(comments),
User.createLocalUsers(users),
Action.create(actions)
]);
});
});
describe('#get', () => {
@@ -453,11 +455,13 @@ describe('/api/v1/comments/:comment_id/actions', () => {
}];
beforeEach(() => {
return Promise.all([
Comment.create(comments),
User.createLocalUsers(users),
Action.create(actions)
]);
return Setting.init(settings).then(() => {
return Promise.all([
Comment.create(comments),
User.createLocalUsers(users),
Action.create(actions)
]);
});
});
describe('#post', () => {
+18 -16
View File
@@ -13,7 +13,7 @@ const Action = require('../../../../models/action');
const User = require('../../../../models/user');
const Setting = require('../../../../models/setting');
const settings = {id: '1', moderation: 'pre'};
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['banned'], suspect: ['suspect']}};
describe('/api/v1/queue', () => {
const comments = [{
@@ -62,23 +62,25 @@ describe('/api/v1/queue', () => {
}];
beforeEach(() => {
return User.createLocalUsers(users)
.then((u) => {
comments[0].author_id = u[0].id;
comments[1].author_id = u[1].id;
comments[2].author_id = u[1].id;
return Setting.init(settings).then(() => {
return User.createLocalUsers(users)
.then((u) => {
comments[0].author_id = u[0].id;
comments[1].author_id = u[1].id;
comments[2].author_id = u[1].id;
return Comment.create(comments);
})
.then((c) => {
actions[0].item_id = c[0].id;
actions[1].item_id = c[1].id;
return Comment.create(comments);
})
.then((c) => {
actions[0].item_id = c[0].id;
actions[1].item_id = c[1].id;
return Promise.all([
Action.create(actions),
Setting.init(settings)
]);
});
return Promise.all([
Action.create(actions),
Setting.init(settings)
]);
});
});
});
it('should return all the pending comments, users and actions', () => {
+33 -28
View File
@@ -17,7 +17,11 @@ describe('/api/v1/stream', () => {
describe('#get', () => {
const settings = {
id: '1',
moderation: 'post'
moderation: 'post',
wordlist: {
banned: ['banned'],
suspect: ['suspect']
}
};
const comments = [{
@@ -71,34 +75,35 @@ describe('/api/v1/stream', () => {
}];
beforeEach(() => {
return Promise.all([
User.createLocalUsers(users),
Asset.findOrCreateByUrl('http://test.com'),
Asset
.findOrCreateByUrl('http://coralproject.net/asset2')
.then((asset) => {
return Asset
.overrideSettings(asset.id, {moderation: 'pre'})
.then(() => asset);
})
])
.then(([users, asset1, asset2]) => {
comments[0].author_id = users[0].id;
comments[1].author_id = users[1].id;
comments[2].author_id = users[0].id;
comments[3].author_id = users[1].id;
comments[0].asset_id = asset1.id;
comments[1].asset_id = asset1.id;
comments[2].asset_id = asset2.id;
comments[3].asset_id = asset2.id;
return Setting.init(settings).then(() => {
return Promise.all([
Comment.create(comments),
Action.create(actions),
Setting.init(settings)
]);
User.createLocalUsers(users),
Asset.findOrCreateByUrl('http://test.com'),
Asset
.findOrCreateByUrl('http://coralproject.net/asset2')
.then((asset) => {
return Asset
.overrideSettings(asset.id, {moderation: 'pre'})
.then(() => asset);
})
])
.then(([users, asset1, asset2]) => {
comments[0].author_id = users[0].id;
comments[1].author_id = users[1].id;
comments[2].author_id = users[0].id;
comments[3].author_id = users[1].id;
comments[0].asset_id = asset1.id;
comments[1].asset_id = asset1.id;
comments[2].asset_id = asset2.id;
comments[3].asset_id = asset2.id;
return Promise.all([
Comment.create(comments),
Action.create(actions)
]);
});
});
});
+6 -1
View File
@@ -4,6 +4,9 @@ const app = require('../../../../app');
const chai = require('chai');
const expect = chai.expect;
const Setting = require('../../../../models/setting');
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
// Setup chai.
chai.should();
chai.use(require('chai-http'));
@@ -23,7 +26,9 @@ describe('/api/v1/users/:user_id/actions', () => {
}];
beforeEach(() => {
return User.createLocalUsers(users);
return Setting.init(settings).then(() => {
return User.createLocalUsers(users);
});
});
describe('#post', () => {
+4
View File
@@ -1,6 +1,7 @@
const expect = require('chai').expect;
const Errors = require('../../errors');
const Wordlist = require('../../services/wordlist');
const Setting = require('../../models/setting');
describe('wordlist: services', () => {
@@ -16,6 +17,9 @@ describe('wordlist: services', () => {
};
let wordlist = new Wordlist();
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
beforeEach(() => Setting.init(settings));
describe('#init', () => {