<commit_before>'use strict';
/*jshint expr: true*/
var should = require('should'),
  request = require('request'),
  async = require('async'),
  hunt = require('./../index.js'),
  Hunt,
  huntKey,
  port = 3373;


describe('Local strategy test', function () {
  this.timeout(5000);
  //afterEach(function (done) {
  //  setTimeout(done, 1500);
  //});

  before(function (done) {
    Hunt = hunt({
      'port': port,
      'disableCsrf': true,
      'views': __dirname + '/hogan-views',
      'passport': {
        'local': true,
        'signUpByEmail': true,
        'verifyEmail': true,
        'verifyEmailTemplate': 'verifyEmail',
        'resetPasswordEmailTemplate': 'resetEmail',
        'resetPasswordPageTemplate': 'resetPassword',
        'resetPassword': true
      }
    });
    Hunt.once('start', function (payload) {
      payload.type.should.be.equal('webserver');
      payload.port.should.be.equal(port);
      should.not.exist(payload.error);
      Hunt.model.User.remove({}, done);
    });
    Hunt.startWebServer();
  });
//*/
  describe('trying to signup user by POST /auth/signup', function () {
    var
      r1, r2, r3, b1, b2, b3,
      evnt,
      welcomeLink;
    before(function (done) {
      Hunt.once('user:notify:email', function (emailOrdered) {
        evnt = emailOrdered;
        welcomeLink = evnt.user.keychain.welcomeLink;
        setTimeout(done, 500);
      });
      async.parallel({
        'doSignUp': function (cb) {
          request({
            'method': 'POST',
            'url': 'http://localhost:' + port + '/auth/signup',
            'form': {
              'email': '<EMAIL>',
              'password': '<PASSWORD>'
            }
          }, function (err, response, body) {
            if (err) {
              cb(err);
            } else {
              r1 = response;
              b1 = body;

              request({
                'method': 'POST',
                'url': 'http://localhost:' + port + '/auth/isBusy',
                'form': {
                  'email': '<EMAIL>'
                }
              }, function (err, response, body) {
                if (err) {
                  cb(err);
                } else {
                  r2 = response;
                  b2 = body;
                  cb(null);
                }
              });
            }
          });
        },
        'doCheckDumpEmail': function (cb) {
          request({
            'method': 'POST',
            'url': 'http://localhost:' + port + '/auth/isBusy',
            'form': {
              'email': 'spam2me' + Math.floor(10000 * Math.random()) + '@example.org'
            }
          }, function (err, response, body) {
            if (err) {
              cb(err);
            } else {
              r3 = response;
              b3 = body;
              cb(null);
            }
          });
        }
      }, function (error) {
        if (error) {
          done(error);
        }
      });
    });

    it('have proper response for signing up', function () {
      r1.statusCode.should.be.equal(302);
    });

    it('have proper response for /auth/isBusy with email of existent user', function () {
      r2.statusCode.should.be.equal(200);
      b2 = JSON.parse(b2);
      b2.isBusy.should.be.true;
    });

    it('have proper response for /auth/isBusy with email of nonexistant user', function () {
      r3.statusCode.should.be.equal(200);
      b3 = JSON.parse(b3);
      b3.isBusy.should.be.false;
    });

    it('makes Hunt core emit event of notify:email with proper structure', function () {
      huntKey = evnt.user.huntKey;
      evnt.user.huntKey.should.be.a.String;
      evnt.user.displayName.should.be.equal('spam2me');
      evnt.user.keychain.email.should.be.equal('<EMAIL>');
      evnt.user.accountVerified.should.be.false;
      evnt.user.gravatar100.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=100&d=wavatar&r=g');
      evnt.user.gravatar80.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=80&d=wavatar&r=g');
      evnt.user.gravatar50.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=50&d=wavatar&r=g');
      evnt.user.gravatar30.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=30&d=wavatar&r=g');
      evnt.user.gravatar.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=80&d=wavatar&r=g');

      evnt.message.subject.should.be.equal('Email address verification');
      evnt.message.template.should.be.equal('verifyEmail');
      evnt.message.subject.should.be.equal('Email address verification');


      if (Hunt.config.hostUrl) {
        evnt.message.verifyUrl.should.be.equal(Hunt.config.hostUrl + '/auth/confirm/' + evnt.user.keychain.welcomeLink);
      } else {
        evnt.message.verifyUrl.should.be.equal('http://localhost:' + port + '/auth/confirm/' + evnt.user.keychain.welcomeLink);
      }

      evnt.message.layout.should.be.false;
    });

    it('allows to confirm users account', function (done) {
      request({
        'method': 'GET',
        'url': 'http://localhost:' + port + '/auth/confirm/' + welcomeLink
      }, function (err, response, body) {
        if (err) {
          done(err);
        } else {
          console.log(body);
          Hunt.model.User.findOneByHuntKey(huntKey, function (err1, userFound) {
            if (err1) {
              done(err1);
            } else {
              if (userFound) {
                userFound.accountVerified.should.be.true;
                userFound.remove(done);
              } else {
                done(new Error('Unable to confirm users account!'));
              }
            }<commit_msg>fixing test on heroku<commit_after>'use strict';
/*jshint expr: true*/
var should = require('should'),
  request = require('request'),
  async = require('async'),
  hunt = require('./../index.js'),
  Hunt,
  huntKey,
  port = 3373;


describe('Local strategy test', function () {
  this.timeout(5000);
  //afterEach(function (done) {
  //  setTimeout(done, 1500);
  //});

  before(function (done) {
    Hunt = hunt({
      'port': port,
      'disableCsrf': true,
      'views': __dirname + '/hogan-views',
      'passport': {
        'local': true,
        'signUpByEmail': true,
        'verifyEmail': true,
        'verifyEmailTemplate': 'verifyEmail',
        'resetPasswordEmailTemplate': 'resetEmail',
        'resetPasswordPageTemplate': 'resetPassword',
        'resetPassword': true
      }
    });
    Hunt.once('start', function (payload) {
      payload.type.should.be.equal('webserver');
      payload.port.should.be.equal(port);
      should.not.exist(payload.error);
      Hunt.model.User.remove({}, done);
    });
    Hunt.startWebServer();
  });
//*/
  describe('trying to signup user by POST /auth/signup', function () {
    var
      r1, r2, r3, b1, b2, b3,
      evnt,
      welcomeLink;
    before(function (done) {
      Hunt.once('user:notify:email', function (emailOrdered) {
        evnt = emailOrdered;
        welcomeLink = evnt.user.keychain.welcomeLink;
        setTimeout(done, 500);
      });
      async.parallel({
        'doSignUp': function (cb) {
          request({
            'method': 'POST',
            'url': 'http://localhost:' + port + '/auth/signup',
            'form': {
              'email': '<EMAIL>',
              'password': '<PASSWORD>'
            }
          }, function (err, response, body) {
            if (err) {
              cb(err);
            } else {
              r1 = response;
              b1 = body;

              request({
                'method': 'POST',
                'url': 'http://localhost:' + port + '/auth/isBusy',
                'form': {
                  'email': '<EMAIL>'
                }
              }, function (err, response, body) {
                if (err) {
                  cb(err);
                } else {
                  r2 = response;
                  b2 = body;
                  cb(null);
                }
              });
            }
          });
        },
        'doCheckDumpEmail': function (cb) {
          request({
            'method': 'POST',
            'url': 'http://localhost:' + port + '/auth/isBusy',
            'form': {
              'email': 'spam2me' + Math.floor(10000 * Math.random()) + '@example.org'
            }
          }, function (err, response, body) {
            if (err) {
              cb(err);
            } else {
              r3 = response;
              b3 = body;
              cb(null);
            }
          });
        }
      }, function (error) {
        if (error) {
          done(error);
        }
      });
    });

    it('have proper response for signing up', function () {
      r1.statusCode.should.be.equal(302);
    });

    it('have proper response for /auth/isBusy with email of existent user', function () {
      r2.statusCode.should.be.equal(200);
      b2 = JSON.parse(b2);
      b2.isBusy.should.be.true;
    });

    it('have proper response for /auth/isBusy with email of nonexistant user', function () {
      r3.statusCode.should.be.equal(200);
      b3 = JSON.parse(b3);
      b3.isBusy.should.be.false;
    });

    it('makes Hunt core emit event of notify:email with proper structure', function () {
      huntKey = evnt.user.huntKey;
      evnt.user.huntKey.should.be.a.String;
      evnt.user.displayName.should.be.equal('spam2me');
      evnt.user.keychain.email.should.be.equal('<EMAIL>');
      evnt.user.accountVerified.should.be.false;
      evnt.user.gravatar100.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=100&d=wavatar&r=g');
      evnt.user.gravatar80.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=80&d=wavatar&r=g');
      evnt.user.gravatar50.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=50&d=wavatar&r=g');
      evnt.user.gravatar30.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=30&d=wavatar&r=g');
      evnt.user.gravatar.should.be.equal('https://secure.gravatar.com/avatar/89b53b121018cf8f7b19c3bb97be675b.jpg?s=80&d=wavatar&r=g');

      evnt.message.subject.should.be.equal('Email address verification');
      evnt.message.template.should.be.equal('verifyEmail');
      evnt.message.subject.should.be.equal('Email address verification');


      if (Hunt.config.hostUrl) {
        evnt.message.verifyUrl.should.be.equal(Hunt.config.hostUrl + 'auth/confirm/' + evnt.user.keychain.welcomeLink);
      } else {
        evnt.message.verifyUrl.should.be.equal('http://localhost:' + port + '/auth/confirm/' + evnt.user.keychain.welcomeLink);
      }

      evnt.message.layout.should.be.false;
    });

    it('allows to confirm users account', function (done) {
      request({
        'method': 'GET',
        'url': 'http://localhost:' + port + '/auth/confirm/' + welcomeLink
      }, function (err, response, body) {
        if (err) {
          done(err);
        } else {
          console.log(body);
          Hunt.model.User.findOneByHuntKey(huntKey, function (err1, userFound) {
            if (err1) {
              done(err1);
            } else {
              if (userFound) {
                userFound.accountVerified.should.be.true;
                userFound.remove(done);
              } else {
                done(new Error('Unable to confirm users account!'));
              }
            }
{'fraction_non_alphanumeric': 0.1554328126348494, 'fraction_numerical': 0.03020626564253042, 'mean_word_length': 1.924047438808983, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1331174', 'n_tokens_mistral': 3898, 'n_tokens_neox': 3708, 'n_words': 595}