<commit_before>require('./init');
var chai = require('chai');
var should = chai.should();
var User = require('../models/user');

describe('User attributes', function() {
  before(function(done) {
    user = new User({
      username: 'test',
      email: '<EMAIL>',
      password: 'password'
    });
    done();
  });

  it('email should be a string', function() {
    user.email.should.be.a('string');
  });

  it('password should be a string', function() {
    user.password.should.be.a('string');
  });

  it('should save a user', function(done) {
    user.save(done);
  });

  it('should find our newly created user', function(done) {
    User.findOne({ email: user.email }, function(err, user) {
      should.exist(user);
      user.email.should.equal('<EMAIL>');
      done();
    });
  });

  it('should not allow users with duplicate emails', function(done) {
    user.save(function(err) {
      if (err) {
        err.code.should.equal(11000);
      }
      done();
    });
  });
});<commit_msg>Add tests for 422 errors<commit_after>require('./init');
var chai = require('chai');
var should = chai.should();
var User = require('../models/user');

describe('User attributes', function() {
  before(function(done) {
    user = new User({
      username: 'test',
      email: '<EMAIL>',
      password: 'password'
    });
    done();
  });

  it('email should be a string', function() {
    user.email.should.be.a('string');
  });

  it('password should be a string', function() {
    user.password.should.be.a('string');
  });

  it('should save a user', function(done) {
    user.save(done);
  });

  it('should find our newly created user', function(done) {
    User.findOne({ email: user.email }, function(err, user) {
      should.exist(user);
      user.email.should.equal('<EMAIL>');
      done();
    });
  });

  it('should not allow users with duplicate username', function(done) {
    var dupe = new User({username: 'test', email: '<EMAIL>', password: 'password'});
    dupe.save(function(err) {
      err.status.should.equal(422);
      err.message.should.equal('username_not_unique');
      done();
    });
  });

  it('should not allow users with duplicate email', function(done) {
    var dupe = new User({username: 'test2', email: '<EMAIL>', password: 'password'});
    dupe.save(function(err) {
      err.status.should.equal(422);
      err.message.should.equal('email_not_unique');
      done();
    });
  });
});
{'fraction_non_alphanumeric': 0.19073010664479081, 'fraction_numerical': 0.0061525840853158325, 'mean_word_length': 3.140916808149406, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '324158', 'n_tokens_mistral': 786, 'n_tokens_neox': 766, 'n_words': 177}