Got first test working with controlled start

This commit is contained in:
Chris Troutner
2018-03-24 10:52:38 -07:00
parent dfc9cdb0cc
commit bf58f90dad
5 changed files with 141 additions and 42 deletions
+39 -1
View File
@@ -1,4 +1,7 @@
const mongoose = require('mongoose')
const rp = require('request-promise')
const LOCALHOST = 'http://localhost:5000'
function cleanDb () {
for (const collection in mongoose.connection.collections) {
@@ -23,7 +26,42 @@ function authUser (agent, callback) {
})
}
// This function is used to create new users.
// userObj = {
// username,
// password
// }
async function createUser (userObj) {
try {
const options = {
method: 'POST',
uri: `${LOCALHOST}/users`,
resolveWithFullResponse: true,
json: true,
body: {
user: {
username: userObj.username,
password: userObj.password
}
}
}
let result = await rp(options)
const retObj = {
user: result.body.user,
token: result.body.token
}
return retObj
} catch (err) {
console.log('Error in utils.js/createUser(): ' + JSON.stringify(err, null, 2))
throw err
}
}
module.exports = {
cleanDb,
authUser
authUser,
createUser
}