<commit_before>var User = require('../../api/models/User');
var Sails = require('sails').Sails;
var sinon = require('sinon');
var expect = require('chai').expect;


describe('Users', function() {

  before(function beforeRunningAnyTests(done) {
    // Load the app without lifting sails
    new Sails().load({
      log: {
        level: 'warn'
      },
      hooks: {
        grunt: false
      }
    }, function whenAppIsReady(err, sailsApp) {
      done(err, sailsApp);
    });
  });

  after(function afterAllTestsFinish(done) {
    sails.lower(done);
  });

  describe('before a user is created', function() {
    // Wrap method in a spy
    before(function(done) {
      sinon.spy(User, "beforeCreate");
      done();
    });

    // Remove spy from method
    after(function(done) {
      User.beforeCreate.restore();
      done();
    });

    it ('should hash the password', function(done) {
      User.beforeCreate({
        password: 'password'
      }, function(err, user) {
        expect(user.password).to.not.equal('password');
        expect(user.password).to.have.length(60);
        done();
      });
    });

    it('should not allow duplicate emails');
    it('should require a username');
    it('should require a password');

  });

  describe('when the json form of the user is requested', function() {
    it('sound return valid json representation');
    it('should not include the password');
  });<commit_msg>Add tests for required username and password<commit_after>var User = require('../../api/models/User');
var Sails = require('sails').Sails;
var sinon = require('sinon');
var expect = require('chai').expect;


describe('Users', function() {

  before(function beforeRunningAnyTests(done) {
    // Load the app without lifting sails
    new Sails().load({
      log: {
        level: 'warn'
      },
      hooks: {
        grunt: false
      }
    }, function whenAppIsReady(err, sailsApp) {
      done(err, sailsApp);
    });
  });

  after(function afterAllTestsFinish(done) {
    sails.lower(done);
  });

  describe('before a user is created', function() {
    // Wrap method in a spy
    before(function(done) {
      sinon.spy(User, "beforeCreate");
      done();
    });

    // Remove spy from method
    after(function(done) {
      User.beforeCreate.restore();
      done();
    });

    it ('should hash the password', function(done) {
      User.beforeCreate({
        password: 'password'
      }, function(err, user) {
        expect(user.password).to.not.equal('password');
        expect(user.password).to.have.length(60);
        done();
      });
    });

    it('should not allow duplicate emails');

    it('should require a username', function(done) {
      sails.request({
        url: '/api/v1/users',
        method: 'POST',
        params: {
          user: {
            username: '',
            password: 'password'
          }
        },
        headers: {},
      }, function(err, clientRes, body) {
        expect(err).to.exist;
        expect(err).to.be.instanceof(Error);
        expect(err).to.have.property('status', 400);
        expect(err).to.have.deep.property('body.error', 'E_VALIDATION');
        expect(err).to.have.deep.property('body.invalidAttributes.username');
        done();
      });
    });

    it('should require a password', function(done) {
      sails.request({
        url: '/api/v1/users',
        method: 'POST',
        params: {
          user: {
            username: '<EMAIL>',
            password: ''
          }
        },
        headers: {}
      }, function(err, clientRes, body) {
        expect(err).to.exist;
        expect(err).to.be.instanceof(Error);
        expect(err).to.have.property('status', 400);
        expect(err).to.have.deep.property('body.error', 'E_VALIDATION');
        expect(err).to.have.deep.property('body.invalidAttributes.password');
        done();
      });
    });

  });

  describe('when the json form of the user is requested', function() {
    it('sound return valid json representation');
    it('should not include the password');
  });
{'fraction_non_alphanumeric': 0.15926380368098159, 'fraction_numerical': 0.00294478527607362, 'mean_word_length': 2.3881961762261015, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '2244349', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1180, 'n_words': 266}