From 7bc848b8018dc1a7c7a9d0371f77c1fc39e21b9e Mon Sep 17 00:00:00 2001 From: riley Date: Mon, 9 Jan 2017 10:47:28 -0700 Subject: [PATCH] make tests pass --- client/coral-admin/src/translations.json | 2 +- init.js | 2 +- tests/models/comment.js | 17 ++++--- tests/models/user.js | 33 +++++++------ tests/routes/api/auth/index.js | 18 ++++--- tests/routes/api/comments/index.js | 24 ++++++---- tests/routes/api/queue/index.js | 34 ++++++------- tests/routes/api/stream/index.js | 61 +++++++++++++----------- tests/routes/api/user/index.js | 7 ++- tests/services/wordlist.js | 4 ++ 10 files changed, 117 insertions(+), 85 deletions(-) diff --git a/client/coral-admin/src/translations.json b/client/coral-admin/src/translations.json index 4142c109f..0fbd1e7b9 100644 --- a/client/coral-admin/src/translations.json +++ b/client/coral-admin/src/translations.json @@ -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.", diff --git a/init.js b/init.js index ec675d5a4..c29684b23 100644 --- a/init.js +++ b/init.js @@ -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: []}}) ]); diff --git a/tests/models/comment.js b/tests/models/comment.js index f97fe8da3..363fd9222 100644 --- a/tests/models/comment.js +++ b/tests/models/comment.js @@ -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()', () => { diff --git a/tests/models/user.js b/tests/models/user.js index 1e2805bbb..69be314c4 100644 --- a/tests/models/user.js +++ b/tests/models/user.js @@ -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; + }); }); }); diff --git a/tests/routes/api/auth/index.js b/tests/routes/api/auth/index.js index e3907575a..6b39e0c8e 100644 --- a/tests/routes/api/auth/index.js +++ b/tests/routes/api/auth/index.js @@ -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'); }); }); }); diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index 26166fa0c..59160a36f 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -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', () => { diff --git a/tests/routes/api/queue/index.js b/tests/routes/api/queue/index.js index e1ac09eb6..378899967 100644 --- a/tests/routes/api/queue/index.js +++ b/tests/routes/api/queue/index.js @@ -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', () => { diff --git a/tests/routes/api/stream/index.js b/tests/routes/api/stream/index.js index b4dea133d..5d192e976 100644 --- a/tests/routes/api/stream/index.js +++ b/tests/routes/api/stream/index.js @@ -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) + ]); + }); }); }); diff --git a/tests/routes/api/user/index.js b/tests/routes/api/user/index.js index ad2b036fc..5ee8c7140 100644 --- a/tests/routes/api/user/index.js +++ b/tests/routes/api/user/index.js @@ -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', () => { diff --git a/tests/services/wordlist.js b/tests/services/wordlist.js index e544d4f01..5bb1d32ab 100644 --- a/tests/services/wordlist.js +++ b/tests/services/wordlist.js @@ -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', () => {