Skip to content

Instantly share code, notes, and snippets.

@Sammuel09
Created January 16, 2019 12:44
Show Gist options
  • Save Sammuel09/a6c9ece9473025458fdcd17f1cf46e2e to your computer and use it in GitHub Desktop.
Save Sammuel09/a6c9ece9473025458fdcd17f1cf46e2e to your computer and use it in GitHub Desktop.
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: 'tayo@gmail.com',
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: 'tayo@gmail.com',
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: 'tayo7@gmail.com',
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