utils.js 618 B

1234567891011121314151617181920212223242526
  1. import mongoose from 'mongoose'
  2. export function cleanDb() {
  3. for (const collection in mongoose.connection.collections) {
  4. if (mongoose.connection.collections.hasOwnProperty(collection)) {
  5. mongoose.connection.collections[collection].remove()
  6. }
  7. }
  8. }
  9. export function authUser(agent, callback) {
  10. agent
  11. .post('/users')
  12. .set('Accept', 'application/json')
  13. .send({ user: { username: 'test', password: 'pass' } })
  14. .end((err, res) => {
  15. if (err) {
  16. return callback(err)
  17. }
  18. callback(null, {
  19. user : res.body.user,
  20. token: res.body.token
  21. })
  22. })
  23. }