UNPKG

express-api-cli

Version:

Cli tool for generating an express project. Instead of wasting extra time creating your project structure, start building right away

42 lines (34 loc) 972 B
import { expect } from 'chai'; import request from 'supertest'; import mongoose from 'mongoose'; import app from '../../src/index'; describe('User APIs Test', () => { before((done) => { const clearCollections = () => { for (const collection in mongoose.connection.collections) { mongoose.connection.collections[collection].deleteOne(() => {}); } }; const mongooseConnect = async () => { await mongoose.connect(process.env.DATABASE_TEST); clearCollections(); }; if (mongoose.connection.readyState === 0) { mongooseConnect(); } else { clearCollections(); } done(); }); describe('GET /users', () => { it('should return empty array', (done) => { request(app.getApp()) .get('/api/v1/users') .end((err, res) => { expect(res.statusCode).to.be.equal(200); expect(res.body.data).to.be.an('array'); done(); }); }); }); });