Created
January 16, 2019 12:44
-
-
Save Sammuel09/a6c9ece9473025458fdcd17f1cf46e2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { describe, it } from 'mocha'; | |
import chai, { expect } from 'chai'; | |
import chaiHttp from 'chai-http'; | |
import app from '../../../index'; | |
import model from '../../models'; | |
chai.use(chaiHttp); | |
const { User } = model; | |
describe('User Model', () => { | |
describe('authentication tests', () => { | |
it('should send a token back to client', async () => { | |
const res = await chai | |
.request(app) | |
.post('/api/v1/auth/signup') | |
.send({ | |
fullName: 'tayo', | |
userName: 'tayolee', | |
email: '[email protected]', | |
password: 'tayoo', | |
roleId: 1 | |
}); | |
expect(res).to.have.status(201); | |
expect(res.body).to.be.an('object'); | |
expect(res.body).to.have.property('data'); | |
expect(res.body.data).to.be.an('object'); | |
expect(res.body.data).to.have.property('token'); | |
expect(res.body.data.token).to.be.a('string'); | |
expect(res.body.data).to.have.property('message'); | |
expect(res.body.data.message).to.be.a('string'); | |
expect(res.body).to.have.property('status'); | |
expect(res.body.status).to.be.a('string'); | |
expect(res.body.status).to.equal('success'); | |
}); | |
it('Email already exists', async () => { | |
const res = await chai | |
.request(app) | |
.post('/api/v1/auth/signup') | |
.send({ | |
fullName: 'tayo', | |
userName: 'tayolee', | |
email: '[email protected]', | |
password: 'tayo' | |
}); | |
expect(res).to.have.status(409); | |
expect(res.body).to.be.an('object'); | |
expect(res.body).to.have.property('status'); | |
expect(res.body.status).to.be.a('string'); | |
expect(res.body).to.have.property('message'); | |
expect(res.body.message).to.be.a('string'); | |
}); | |
it('should send back an error message', async () => { | |
const res = await chai | |
.request(app) | |
.post('/api/v1/auth/signup') | |
.send({ | |
fullName: 'tayo8', | |
userName: 'tayolee8', | |
email: '[email protected]', | |
password: 'tayoo88', | |
roleId: 'hello' | |
}); | |
expect(res).to.have.status(400); | |
expect(res.body).to.be.an('object'); | |
expect(res.body).to.have.property('error'); | |
expect(res.body.error).to.be.a('string'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment