mirror of
https://github.com/wassname/talk.git
synced 2026-07-24 13:20:47 +08:00
Updates to user cli + e2e + tests
- Updates to before + beforeEach for mongooose - Removed reference to dotenv from cli in e2e, should use NODE_ENV=test instead. - Changed test port from 30?? to 3000 to be consistent with what nightwatch was expecting
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ const util = require('../util');
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
|
||||
const port = normalizePort(process.env.TALK_PORT || (process.env.NODE_ENV === 'test' ? '3011' : '3000'));
|
||||
const port = normalizePort(process.env.TALK_PORT || '3000');
|
||||
|
||||
app.set('port', port);
|
||||
|
||||
|
||||
+10
-6
@@ -80,12 +80,16 @@ function createUser(options) {
|
||||
.then((user) => {
|
||||
console.log(`Created user ${user.id}.`);
|
||||
|
||||
return User
|
||||
.addRoleToUser(user.id, result.role.trim())
|
||||
.then(() => {
|
||||
console.log(`Added the admin ${result.role.trim()} to User ${user.id}.`);
|
||||
util.shutdown();
|
||||
});
|
||||
if (result.role && result.role.length > 0) {
|
||||
return User
|
||||
.addRoleToUser(user.id, result.role.trim())
|
||||
.then(() => {
|
||||
console.log(`Added the admin ${result.role.trim()} to User ${user.id}.`);
|
||||
util.shutdown();
|
||||
});
|
||||
} else {
|
||||
util.shutdown();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
|
||||
+3
-3
@@ -4,12 +4,12 @@
|
||||
selenium-standalone install
|
||||
|
||||
# Creating Admin Test User
|
||||
{ echo admin@test.com; echo test; echo test; echo Admin Test User; echo admin;} | ./bin/cli-users create
|
||||
./bin/cli-users create --flag_mode --email "admin@test.com" --password "test" --name "Admin Test User" --role "admin"
|
||||
|
||||
# Creating Moderator Test User
|
||||
{ echo moderator@test.com; echo test; echo test; echo Moderator Test User; echo moderator;} | ./bin/cli-users create
|
||||
./bin/cli-users create --flag_mode --email "moderator@test.com" --password "test" --name "Moderator Test User" --role "moderator"
|
||||
|
||||
# Creating Commenter Test User
|
||||
{ echo commenter@test.com; echo test; echo test; echo Commenter Test User; echo ;} | ./bin/cli-users create
|
||||
./bin/cli-users create --flag_mode --email "commenter@test.com" --password "test" --name "commenter@test.com"
|
||||
|
||||
npm start &
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const uuid = require('uuid');
|
||||
|
||||
module.exports = {
|
||||
'@tags': ['signup', 'visitor'],
|
||||
before: client => {
|
||||
@@ -9,11 +11,10 @@ module.exports = {
|
||||
},
|
||||
'Visitor signs up': client => {
|
||||
const embedStreamPage = client.page.embedStreamPage();
|
||||
const hash = Math.floor(Math.random() * (999 - 0));
|
||||
|
||||
embedStreamPage
|
||||
.signUp({
|
||||
email: `visitor_${hash}@test.com`,
|
||||
email: `visitor_${uuid.v4()}@test.com`,
|
||||
displayName: 'Visitor',
|
||||
pass: 'testtest'
|
||||
});
|
||||
|
||||
+24
-18
@@ -4,24 +4,30 @@ const expect = require('chai').expect;
|
||||
describe('models.Action', () => {
|
||||
let mockActions = [];
|
||||
|
||||
beforeEach(() => Action.create([{
|
||||
action_type: 'flag',
|
||||
item_id: '123',
|
||||
item_type: 'comment',
|
||||
user_id: 'flagginguserid'
|
||||
}, {
|
||||
action_type: 'flag',
|
||||
item_id: '456',
|
||||
item_type: 'comment'
|
||||
}, {
|
||||
action_type: 'flag',
|
||||
item_id: '123',
|
||||
item_type: 'comment'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: '123',
|
||||
item_type: 'comment'
|
||||
}]).then((actions) => {
|
||||
beforeEach(() => Action.create([
|
||||
{
|
||||
action_type: 'flag',
|
||||
item_id: '123',
|
||||
item_type: 'comment',
|
||||
user_id: 'flagginguserid'
|
||||
},
|
||||
{
|
||||
action_type: 'flag',
|
||||
item_id: '456',
|
||||
item_type: 'comment'
|
||||
},
|
||||
{
|
||||
action_type: 'flag',
|
||||
item_id: '123',
|
||||
item_type: 'comment'
|
||||
},
|
||||
{
|
||||
action_type: 'like',
|
||||
item_id: '123',
|
||||
item_type: 'comment'
|
||||
}
|
||||
]).then((actions) => {
|
||||
console.log('all created');
|
||||
mockActions = actions;
|
||||
}));
|
||||
|
||||
|
||||
+39
-16
@@ -1,27 +1,50 @@
|
||||
const mongoose = require('../services/mongoose');
|
||||
|
||||
beforeEach(function (done) {
|
||||
function clearDB() {
|
||||
for (let collection in mongoose.connection.collections) {
|
||||
mongoose.connection.collections[collection].remove(function() {});
|
||||
}
|
||||
return done();
|
||||
}
|
||||
|
||||
if (mongoose.connection.readyState === 0) {
|
||||
mongoose.on('open', function() {
|
||||
function waitTillConnect() {
|
||||
return new Promise((resolve, reject) => {
|
||||
mongoose.connection.on('open', function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
return clearDB();
|
||||
return resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
before(function(done) {
|
||||
this.timeout(30000);
|
||||
|
||||
waitTillConnect()
|
||||
.then(() => {
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
done(err);
|
||||
});
|
||||
} else {
|
||||
return clearDB();
|
||||
}
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
beforeEach(function(done) {
|
||||
Promise.all(Object.keys(mongoose.connection.collections).map((collection) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
mongoose.connection.collections[collection].remove(function(err) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
return resolve();
|
||||
});
|
||||
});
|
||||
}))
|
||||
.then(() => {
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
mongoose.disconnect();
|
||||
return done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user