<commit_before>import chai from 'chai';
import request from 'supertest';
import models, { User } from '../../src/data/models';
import app from '../../src/app';


// const assert = chai.assert;

/*
 * get users list
 */
describe('GET /api/users/', () => {
  beforeEach((done) => {
    models.sync({ force: true }).then(() => {
      User.create({
        username: 'jimmy',
        email: '<EMAIL>',
        password: '<PASSWORD>',
        type: 'student',
      })
      .then(() => {
        done();
      })
      .catch(done);
    }).catch((error) => {
      done(error);
    });
  });

  it('should respond 401 unautherized without login', (done) => {
    request(app)
    .get('/api/users/')
    .expect('Content-Type', /json/)
    .expect(401, done);
  });

  it('should respond 200 with login', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .end((err, res) => {
      if (err || !res.ok) {
        done(err);
      } else {
        // get /api/users/
        agent
        .get('/api/users/')
        .expect('Content-Type', /json/)
        .expect(200, done);
      }
    });
  });

});

/*
 * user login
 */
describe('GET /api/login/', () => {
  beforeEach((done) => {
    models.sync({ force: true }).then(() => {
      User.create({
        username: 'jimmy',
        email: '<EMAIL>',
        password: '<PASSWORD>',
        type: 'student',
      })
      .then(() => {
        done();
      })
      .catch(done);
    }).catch((error) => {
      done(error);
    });
  });

  it('should respond 401 unautherized with wrong email', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .expect(401, done);
  });

  it('should respond 401 unautherized with wrong password', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .expect(401, done);
  });

  it('should respond 200 with correct email and password', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .expect('Content-Type', /json/)
    .expect(200, done);
  });

});

/*
 * user logout
 */
describe('GET /api/logout/', () => {
  beforeEach((done) => {
    models.sync({ force: true }).then(() => {
      User.create({
        username: 'jimmy',
        email: '<EMAIL>',
        password: '<PASSWORD>',
        type: 'student',
      })
      .then(() => {
        done();
      })
      .catch(done);
    }).catch((error) => {
      done(error);
    });
  });

  it('should respond 401 unautherized without login', (done) => {
    const agent = request.agent(app);
    agent
    .get('/api/logout/')
    .expect('Content-Type', /json/)
    .expect(401, done);
  });

  it('should respond 200 with login', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .end((err, res) => {
      if (err || !res.ok) {
        done(err);
      } else {
        // logout user
        agent
        .get('/api/logout/')
        .expect('Content-Type', /json/)
        .expect(200, done);
      }
    });
  });

});<commit_msg>add test case for registration<commit_after>import chai from 'chai';
import request from 'supertest';
import models, { User, Course, School } from '../../src/data/models';
import app from '../../src/app';


const assert = chai.assert;

/*
 * get users list
 */
describe('GET /api/users/', () => {
  beforeEach((done) => {
    models.sync({ force: true })
    .then(() => {
      return User.create({
        username: 'jimmy',
        email: '<EMAIL>',
        password: '<PASSWORD>',
      });
    })
    .then(() => {
      done();
    })
    .catch(done);
  });

  it('should respond 401 unautherized without login', (done) => {
    request(app)
    .get('/api/users/')
    .expect('Content-Type', /json/)
    .expect(401, done);
  });

  it('should respond 200 with login', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .end((err, res) => {
      if (err || !res.ok) {
        done(err);
      } else {
        // get /api/users/
        agent
        .get('/api/users/')
        .expect('Content-Type', /json/)
        .expect(200, done);
      }
    });
  });

});

/*
 * user login
 */
describe('GET /api/login/', () => {
  beforeEach((done) => {
    models.sync({ force: true })
    .then(() => {
      return User.create({
        username: 'jimmy',
        email: '<EMAIL>',
        password: '<PASSWORD>',
      });
    })
    .then(() => {
      done();
    })
    .catch(done);
  });

  it('should respond 401 unautherized with wrong email', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .expect(401, done);
  });

  it('should respond 401 unautherized with wrong password', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .expect(401, done);
  });

  it('should respond 200 with correct email and password', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .expect('Content-Type', /json/)
    .expect(200, done);
  });

});

/*
 * user logout
 */
describe('GET /api/logout/', () => {
  beforeEach((done) => {
    models.sync({ force: true })
    .then(() => {
      return User.create({
        username: 'jimmy',
        email: '<EMAIL>',
        password: '<PASSWORD>',
      });
    })
    .then(() => {
      done();
    })
    .catch(done);
  });

  it('should respond 401 unautherized without login', (done) => {
    const agent = request.agent(app);
    agent
    .get('/api/logout/')
    .expect('Content-Type', /json/)
    .expect(401, done);
  });

  it('should respond 200 with login', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/login/')
    .send({ email: '<EMAIL>', password: '<PASSWORD>' })
    .end((err, res) => {
      if (err || !res.ok) {
        done(err);
      } else {
        // logout user
        agent
        .get('/api/logout/')
        .expect('Content-Type', /json/)
        .expect(200, done);
      }
    });
  });
});


/*
 * user register
 */
describe('POST /api/register/', () => {
  beforeEach((done) => {
    models.sync({ force: true })
    .then(() => {
      const allPromises = [];
      for (let i=0; i<3; i++) {
        allPromises.push(Course.create({name: 'course ' + (i+1)}));
      }
      allPromises.push(School.create({name: 'columbia'}));
      return Promise.all(allPromises);
    })
    .then(() => {
      done();
    })
    .catch(done);
  });

  it('should respond 200', (done) => {
    const agent = request.agent(app);
    agent
    .post('/api/register/')
    .send(
      { 
        email: '<EMAIL>',
        password: '<PASSWORD>',
        school: 1,
        courses: [
          {
            id: 1,
            joinType: 'student'
          },
          {
            id: 2,
            joinType: 'ta'
          }
        ]
      }
    )
    .expect('Content-Type', /json/)
    .expect((res) => {
      assert.equal(res.body.userId, 1);
    })
    .expect(200, done);
  });
});
{'fraction_non_alphanumeric': 0.21493963115297865, 'fraction_numerical': 0.012869842112246252, 'mean_word_length': 2.012789768185452, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2732930', 'n_tokens_mistral': 2586, 'n_tokens_neox': 2509, 'n_words': 543}