Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const should = require('should')
- const schema = require('../../models/user')
- const mongoose = require('mongoose')
- const User = mongoose.model('User', schema)
- const app = require('../../app')
- const request = require('supertest')
- describe('Auth: routes', () => {
- const baseUrl = '/auth/signin'
- const emailAddress = 'max@example.com'
- const realPassword = 'secret1'
- beforeEach(done => {
- User.hashPassword(realPassword, function (err, passwordHash) {
- // Create a User
- const newUser = new User({
- name: 'Name',
- passwordHash: passwordHash,
- email: emailAddress,
- })
- newUser.save((err, item) =>{
- should.not.exist(err)
- should.exist(item)
- done()
- })
- })
- })
- describe('POST /auth/signin', function () {
- it('should response with token if authentication success', (done) => {
- const data = {
- email: emailAddress,
- password: realPassword,
- };
- request(app)
- .post(baseUrl)
- .send(data)
- .expect(200)
- .end(function (err, res) {
- should.not.exist(err)
- should.exist(res.body.data)
- done()
- });
- })
- it('should response with error or errors array if authentication fails', (done) => {
- const data = {
- email: 'berry@example.com',
- password: 'fakepassword',
- };
- request(app)
- .post(baseUrl)
- .send(data)
- .expect(400)
- .end(function (err, res) {
- should.not.exist(err);
- should.exist(res.body.error || res.body.errors)
- done();
- });
- })
- })
- describe('POST /auth/signup', function () {
- it('should response with token if signup success', (done) => {
- const data = {
- email: emailAddress,
- password: realPassword,
- };
- request(app)
- .post('/auth/signin')
- .send(data)
- .expect(200)
- .end(function (err, res) {
- should.not.exist(err)
- should.exist(res.body.data)
- done()
- });
- })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement