2018-03-05 19:31:19 -08:00
|
|
|
const mongoose = require('mongoose')
|
2016-02-15 18:04:26 -05:00
|
|
|
|
2018-03-05 19:31:19 -08:00
|
|
|
function cleanDb () {
|
2016-02-15 18:04:26 -05:00
|
|
|
for (const collection in mongoose.connection.collections) {
|
2016-03-16 21:20:23 -04:00
|
|
|
if (mongoose.connection.collections.hasOwnProperty(collection)) {
|
|
|
|
|
mongoose.connection.collections[collection].remove()
|
|
|
|
|
}
|
2016-02-15 18:04:26 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-16 21:20:23 -04:00
|
|
|
|
2018-03-05 19:31:19 -08:00
|
|
|
function authUser (agent, callback) {
|
2016-03-16 21:20:23 -04:00
|
|
|
agent
|
|
|
|
|
.post('/users')
|
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
.send({ user: { username: 'test', password: 'pass' } })
|
|
|
|
|
.end((err, res) => {
|
|
|
|
|
if (err) { return callback(err) }
|
|
|
|
|
|
|
|
|
|
callback(null, {
|
|
|
|
|
user: res.body.user,
|
|
|
|
|
token: res.body.token
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
2018-03-05 19:31:19 -08:00
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
cleanDb,
|
|
|
|
|
authUser
|
|
|
|
|
}
|