From 15810e3ece781411aef26ac33662de60654751e7 Mon Sep 17 00:00:00 2001 From: David Jay Date: Mon, 21 Nov 2016 15:27:31 -0500 Subject: [PATCH] Running comment post test w/ proper settings. --- .gitignore | 2 +- package.json | 4 +-- pree2e.sh | 3 ++- tests/e2e/tests/EmbedStreamTests.js | 21 ++++++++++++---- tests/utils/e2e-mongoose.js | 39 +++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 tests/utils/e2e-mongoose.js diff --git a/.gitignore b/.gitignore index 1ba4be442..4fe8d7e31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules -npm-debug.log +npm-debug.log* dist !dist/coral-admin dist/coral-admin/bundle.js diff --git a/package.json b/package.json index 371a23378..537887a56 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "mocha": "^3.1.2", "mocha-junit-reporter": "^1.12.1", "nightwatch": "^0.9.9", + "node-fetch": "^1.6.3", "postcss-loader": "^1.1.0", "postcss-modules": "^0.5.2", "postcss-smart-import": "^0.5.1", @@ -117,8 +118,7 @@ "style-loader": "^0.13.1", "supertest": "^2.0.1", "timeago.js": "^2.0.3", - "webpack": "^1.13.3", - "whatwg-fetch": "^1.0.0" + "webpack": "^1.13.3" }, "engines": { "node": ">=7.0.0" diff --git a/pree2e.sh b/pree2e.sh index e61bceb1f..49b9a11f2 100755 --- a/pree2e.sh +++ b/pree2e.sh @@ -1,4 +1,5 @@ node_modules/selenium-standalone/bin/selenium-standalone install export TALK_PORT=3011 -export TALK_MONGO_URL='mongodb://localhost/talk_test' +export TALK_MONGO_URL='mongodb://localhost/test' +export TALK_DEBUG='talk*' npm start & diff --git a/tests/e2e/tests/EmbedStreamTests.js b/tests/e2e/tests/EmbedStreamTests.js index 106feee2b..716db93db 100644 --- a/tests/e2e/tests/EmbedStreamTests.js +++ b/tests/e2e/tests/EmbedStreamTests.js @@ -1,24 +1,35 @@ -require('../../utils/mongoose'); +const utils = require('../../utils/e2e-mongoose'); const Setting = require('../../../models/setting'); +const fetch = require('node-fetch'); const comment = 'This is a test comment.'; module.exports = { '@tags': ['embed-stream', 'post'], - before: () => { - Setting.create({moderation: 'post'}); + beforeEach: client => { + return fetch(`${client.globals.baseUrl}/api/v1/settings`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }, + body: JSON.stringify({ + moderation: 'post' + }) + }); }, 'User posts a comment': client => { client.resizeWindow(1200, 800) .url(client.globals.baseUrl) .frame('coralStreamIframe') - .waitForElementVisible('#commentBox', 1000) + .waitForElementVisible('#commentBox', 2000) .setValue('#commentBox .coral-plugin-commentbox-textarea', comment) .click('#commentBox .coral-plugin-commentbox-button') .waitForElementVisible('.comment', 1000) - .expect.element('.coral-plugin-comment').to.equal(comment); + .assert.containsText('.comment', comment); }, after: client => { + utils.after(); client.end(); } }; diff --git a/tests/utils/e2e-mongoose.js b/tests/utils/e2e-mongoose.js new file mode 100644 index 000000000..e5a0cb568 --- /dev/null +++ b/tests/utils/e2e-mongoose.js @@ -0,0 +1,39 @@ +const mongoose = require('../../mongoose'); + +// Ensure the NODE_ENV is set to 'test', +// this is helpful when you would like to change behavior when testing. +function clearDB() { + for (let i in mongoose.connection.collections) { + mongoose.connection.collections[i].remove(function() {}); + } +} + +module.exports = { + before: () => { + const url = process.env.TALK_MONGO_URL || 'mongodb://localhost'; + return mongoose.connect(url, (err) => { + if (err) { + throw err; + } + debug('Connected to MongoDB!'); + }); + }, + beforeEach: () => { + console.log('beforeEach', mongoose.connection.name); + if (mongoose.connection.readyState === 0) { + mongoose.on('open', function() { + if (err) { + throw err; + } + + return clearDB(); + }); + } else { + return clearDB(); + } + }, + after: () => { + clearDB(); + mongoose.disconnect(); + } +};