Clean db before tests

This commit is contained in:
Adrian Obelmejias
2016-02-15 18:04:26 -05:00
parent 1dfc2fe826
commit 995c2c5d60
2 changed files with 29 additions and 0 deletions
+22
View File
@@ -1,12 +1,18 @@
import app from '../config/server'
import supertest from 'supertest'
import { expect, should } from 'chai'
import { cleanDb } from './utils'
should()
const request = supertest.agent(app.listen())
const context = {}
describe('Users', () => {
before((done) => {
cleanDb()
done()
})
describe('POST /users', () => {
it('should reject signup when data is incomplete', (done) => {
request
@@ -36,4 +42,20 @@ describe('Users', () => {
})
})
})
describe('GET /users', () => {
it('should not fetch users if token is invalid', (done) => {
request
.get('/users?token=1')
.set('Accept', 'application/json')
.expect(401, done)
})
it('should fetch all users', (done) => {
request
.get(`/users?token=${context.token}`)
.set('Accept', 'application/json')
.expect(200, done)
})
})
})
+7
View File
@@ -0,0 +1,7 @@
import mongoose from 'mongoose'
export function cleanDb () {
for (const collection in mongoose.connection.collections) {
mongoose.connection.collections[collection].remove();
}
}