Skip to content

Instantly share code, notes, and snippets.

@jdcauley jdcauley/user.js
Created Oct 9, 2017

Embed
What would you like to do?
Testing V2
process.env.NODE_ENV = 'test';
//Require the dev-dependencies
let chai = require('chai')
let chaiHttp = require('chai-http')
let server = require('../index.js')
let should = chai.should()
let faker = require('faker')
const Models = require('../db.js')
const User = Models.User
chai.use(chaiHttp);
//Our parent block
describe('Users', () => {
let username = faker.Internet.userName()
let email = faker.Internet.email()
let response = null
before((done) => { //Before each test we empty the database
User.destroy({
where: {},
truncate: true
}).then((user) => {
return done()
})
.catch((err) => {
return done(err)
})
});
/*
* Test the /POST route
*/
describe('/POST user', () => {
before((done) => {
chai.request(server)
.post('/api/v1/users')
.send({
"username": username,
"email": email,
"password": "password123"
}).end((err, res) => {
response = res
return done()
})
})
it('it should have STATUS 201', (done) => {
response.should.have.status(201)
return done()
})
it('it should CREATE a USER', (done) => {
response.body.should.have.property('user')
response.body.user.should.have.property('id')
response.body.user.should.have.property('username')
response.body.user.should.have.property('email')
done()
})
it('it should CREATE an AUTH', (done) => {
response.body.should.have.property('user')
return done()
})
})
/*
* Test the /GET route
*/
describe('/GET user', () => {
before((done) => {
chai.request(server)
.get('/api/v1/users')
.end((err, res) => {
response = res
return done()
})
})
it('it should GET all users', (done) => {
response.should.have.status(200);
response.body.should.be.a('object')
response.body.users.should.be.a('array')
return done()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.