const { expect } = require('chai');
const request = require('supertest');
const db = require('../db');
const app = require('../index');
const User = db.model('user');

describe('User routes', () => {

  beforeEach(() => {
    return db.sync({ force: true });
  });

  describe('/api/users/', () => {
    const codysFirstName = 'Cody';
    const codysLastName = 'Smith';
    const codysEmail = 'cody@workingonit.com';
    const jensFirstName = 'Jen';
    const jensLastName = 'Tam';
    const jensEmail = 'jen@jen.com';

    beforeEach(() => {
      return User.create({
        firstName: codysFirstName,
        lastName: codysLastName,
        email: codysEmail,
      })
      .then(() => {
        User.create({
          firstName: jensFirstName,
          lastName: jensLastName,
          email: jensEmail,
        })
      });
    });

    describe('GET /api/users', () => {
      it('retrieves all users', () => {
        return request(app)
        .get('/api/users')
        .expect(200)
        .then(res => {
          expect(res.body).to.be.an('array');
          expect(res.body[0].email).to.be.equal(codysEmail);
          expect(res.body[0].firstName).to.be.equal(codysFirstName);
          expect(res.body[0].lastName).to.be.equal(codysLastName);
          expect(res.body[1].email).to.be.equal(jensEmail);
          expect(res.body[1].firstName).to.be.equal(jensFirstName);
          expect(res.body[1].lastName).to.be.equal(jensLastName);
        })
      });
    });

    describe('GET /api/users/:id', () => {
      it('retrieves selected user', () => {
        return request(app)
        .get('/api/users/1')
        .expect(200)
        .then(res => {
          expect(res.body).to.be.an('object');
          expect(res.body.id).to.be.equal(1);
          expect(res.body.firstName).to.be.equal(codysFirstName);
          expect(res.body.lastName).to.be.equal(codysLastName);
          expect(res.body.email).to.be.equal(codysEmail);

        })
      });

      it('retrieves a different selected user', () => {
        return request(app)
        .get('/api/users/2')
        .expect(200)
        .then(res => {
          expect(res.body).to.be.an('object');
          expect(res.body.id).to.be.equal(2);
          expect(res.body.firstName).to.be.equal(jensFirstName);
          expect(res.body.lastName).to.be.equal(jensLastName);
          expect(res.body.email).to.be.equal(jensEmail);
        })
      });
    });

  });

});

@@ -2421,32 +2421,487 @@
     %7D)%0A      %7D);
+%0A%0A      it('fails with a 401 when user not logged in', () =%3E %7B%0A        return request(app)%0A        // .get('/api/users/???')%0A        // .expect(401)%0A        // .then(res =%3E %7B%0A        //   // ?%0A        // %7D)%0A      %7D);%0A    %7D);%0A%0A    describe('POST /api/users', () =%3E %7B%0A      it('creates a user', () =%3E %7B%0A        return request(app)%0A        .post('/api/users')%0A        .expect(200)%0A        .then(res =%3E %7B%0A          // should create a user%0A        %7D)%0A      %7D);
 %0A    %7D);%0A%0A  %7D);%0A

add additional tests to be fleshed out