import chai from 'chai';
import supertest from 'supertest';
import app from '../../config/app';
import db from '../../models';
import userHelper from '../Helpers/UserHelper';

const expect = chai.expect;
const request = supertest(app);
const goodUser = userHelper.goodUser;
const badGroup = userHelper.badUser;
const userDoesntExist = userHelper.userDoesntExist;
let newUserResponse;

describe('POST api/user/signup', () => {
  beforeEach((done) => {
    request.post('/api/user/signup')
    .send(goodUser)
    .end((err, res) => {
      if (err) return err;
      newUserResponse = res;
      done();
    });
  });
  afterEach(() => db.Users.destroy({ where: {} }));
  it('should create a new user', (done) => {
    expect(newUserResponse.status).to.equal(201);
    expect(newUserResponse.body).to.have.property('username');
    expect(newUserResponse.body).to.have.property('email');
	  expect(newUserResponse.body).to.have.property('password');
    done();
  }); 
  it('should have a createdAt property', (done) => {
    expect(newUserResponse.body).to.have.property('createdAt');
    done();
  });
  it('should not create user with missing property ', (done) => {
    request.post('/api/user/signup')
    .send(badGroup)
    .end((err, res) => {
      expect(res.body.message).to.equal('property mising');
      return done();
    });
  });
  it('should not create a user if already exist ', (done) => {
    request.post('/api/user/signup')
    .send(goodUser)
    .end((err, res) => {
      expect(res.status).to.equal(409);
      expect(res.body.message).to.equal('user already exist');
      return done();
    });
  });
  it('should signin a user', (done) => {
    request.post('/api/user/signin')
    .send(goodUser)
    .end((err, res) => {
      expect(res.status).to.equal(200);
      expect(res.body.message).to.equal('You have been loggedin successfully');
      return done();
    });
  });
  it('should not signin a user if user does not exist', (done) => {
    request.post('/api/user/signin')
    .send(userDoesntExist)
    .end((err, res) => {
      expect(res.status).to.equal(409);
      expect(res.body.message).to.equal('incorrect Email and password');
      return done();
    });
  });
  it('should get all existing users', (done) => {
    request.get('/api/user')
    .end((err, res) => {
      expect(res.body.users.length).to.equal(1);
      return done();
    });
  });
});

@@ -280,30 +280,113 @@
  bad
-Group = userHelper.bad
+User1 = userHelper.badUser1;%0Aconst badUser2 = userHelper.badUser2;%0Aconst anotherUser = userHelper.another
 User
@@ -443,27 +443,52 @@
 st;%0A
-let newUserResponse
+const anotherUser2 = userHelper.anotherUser2
 ;%0A%0Ad
@@ -665,37 +665,8 @@
 rr;%0A
-      newUserResponse = res;%0A
     
@@ -696,20 +696,16 @@
 %0A  after
-Each
 (() =%3E d
@@ -710,33 +710,36 @@
  db.
-U
 se
-rs.destroy(%7B where: %7B%7D
+quelize.sync(%7B force: true
  %7D))
@@ -789,38 +789,140 @@
 %3E %7B%0A    
-expect(newUserResponse
+request.post('/api/user/signup')%0A    .send(anotherUser)%0A    .end((err, res) =%3E %7B%0A      if (err) return err;%0A      expect(res
 .status)
@@ -941,38 +941,28 @@
 1);%0A    
+ 
+ 
 expect(
-newUserResponse
+res
 .body).t
@@ -994,38 +994,28 @@
 ');%0A    
+  
 expect(
-newUserResponse
+res
 .body).t
@@ -1044,9 +1044,12 @@
 ');%0A
-%09
+    
   ex
@@ -1049,39 +1049,27 @@
      expect(
-newUserResponse
+res
 .body).to.ha
@@ -1101,102 +1101,20 @@
     
-done();%0A  %7D); %0A  it('should have a createdAt property', (done) =%3E %7B%0A    expect(newUserResponse
+  expect(res
 .bod
@@ -1151,24 +1151,26 @@
 ');%0A    
+  
 done();%0A
   %7D);%0A  
@@ -1161,22 +1161,34 @@
 done();%0A
+  
   %7D);%0A
+  %7D); %0A  %0A
   it('sh
@@ -1299,13 +1299,13 @@
 (bad
-Group
+User1
 )%0A  
@@ -1372,23 +1372,32 @@
 al('
-property mising
+Unexpected error occured
 ');%0A
@@ -2446,17 +2446,17 @@
 o.equal(
-1
+2
 );%0A     
@@ -2485,12 +2485,536 @@
 ;%0A  %7D);%0A
-%7D);
+  it('should validate email address', (done) =%3E %7B%0A    request.post('/api/user/signup')%0A    .send(badUser2)%0A    .end((err, res) =%3E %7B%0A      if (err) return err;%0A      expect(res.body.message).to.equal('Unexpected error occured');%0A      return done();%0A    %7D);%0A  %7D);%0A  it('should unique username', (done) =%3E %7B%0A    request.post('/api/user/signup')%0A    .send(anotherUser2)%0A    .end((err, res) =%3E %7B%0A      if (err) return err;%0A      expect(res.body.message).to.equal('Unexpected error occured');%0A      return done();%0A    %7D);%0A  %7D);%0A%7D);%0A
 %0A

add more test cases