mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Clean db before tests
This commit is contained in:
@@ -1,12 +1,18 @@
|
|||||||
import app from '../config/server'
|
import app from '../config/server'
|
||||||
import supertest from 'supertest'
|
import supertest from 'supertest'
|
||||||
import { expect, should } from 'chai'
|
import { expect, should } from 'chai'
|
||||||
|
import { cleanDb } from './utils'
|
||||||
|
|
||||||
should()
|
should()
|
||||||
const request = supertest.agent(app.listen())
|
const request = supertest.agent(app.listen())
|
||||||
const context = {}
|
const context = {}
|
||||||
|
|
||||||
describe('Users', () => {
|
describe('Users', () => {
|
||||||
|
before((done) => {
|
||||||
|
cleanDb()
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
describe('POST /users', () => {
|
describe('POST /users', () => {
|
||||||
it('should reject signup when data is incomplete', (done) => {
|
it('should reject signup when data is incomplete', (done) => {
|
||||||
request
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import mongoose from 'mongoose'
|
||||||
|
|
||||||
|
export function cleanDb () {
|
||||||
|
for (const collection in mongoose.connection.collections) {
|
||||||
|
mongoose.connection.collections[collection].remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user