<commit_before>var request = require('superagent')
    , app = require('../../index')
    , models = require('../../app/models')
    , funcTestHelper = require('./functional_test_helper')

describe("PasswordsController", function() {
  beforeEach(funcTestHelper.flushDb())

  describe("#create()", function() {
    var authToken
      , luna
      , oldEmail = '<EMAIL>'

    beforeEach(funcTestHelper.createUser('Luna', 'password', { 'email': oldEmail }, function(token, luna) {
      authToken = token
      user = luna
    }))

    it('should generate resetToken by email', function(done) {
      var email = "<EMAIL>"

      request
        .post(app.config.host + '/v1/users/' + user.id)
        .send({ authToken: authToken,
                user: { email: email },
                '_method': 'put' })
        .end(function(err, res) {
          request
            .post(app.config.host + '/v1/passwords')
            .send({ email: email })
            .end(function(err, res) {
              res.body.should.not.be.empty
              res.body.should.have.property('message')
              res.body.message.should.eql('We will send a password reset link to ' + email + ' in a moment')
              done()
            })
        })
    })

    it('should generate resetToken by email for a new user', function(done) {
      request
        .post(app.config.host + '/v1/passwords')
        .send({ email: oldEmail })
        .end(function(err, res) {
          res.body.should.not.be.empty
          res.body.should.have.property('message')
          res.body.message.should.eql('We will send a password reset link to ' + oldEmail + ' in a moment')
          done()
        })
    })

    it('should require email', function(done) {
      var email = "<EMAIL>"

      request
        .post(app.config.host + '/v1/users/' + user.id)
        .send({ authToken: authToken,
                user: { email: email },
                '_method': 'put' })
        .end(function(err, res) {
          request
            .post(app.config.host + '/v1/passwords')
            .end(function(err, res) {
              res.body.should.not.be.empty
              res.body.should.have.property('err')
              res.body.err.should.eql('Email cannot be blank')
              done()
            })
        })
    })
  })

  describe('#update()', function() {
    var authToken
      , luna

    beforeEach(funcTestHelper.createUser('Luna', 'password', function(token, luna) {
      authToken = token
      user = luna
    }))

    beforeEach(function(done) {
      var email = "<EMAIL>"

      request
        .post(app.config.host + '/v1/users/' + user.id)
        .send({ authToken: authToken,
                user: { email: email },
                '_method': 'put' })
        .end(function(err, res) {
          request
            .post(app.config.host + '/v1/passwords')
            .send({ email: email })
            .end(function(err, res) {
              done()
            })
        })
    })

    it('should not reset password by invalid resetToken', function(done) {
      request
        .post(app.config.host + '/v1/passwords/token')
        .send({ '_method': 'put' })
        .end(function(err, res) {
          res.body.should.not.be.empty
          res.body.should.have.property('err')
          res.body.err.should.eql('Record not found')
          done()
        })
    })
  })
})
<commit_msg>added missed var<commit_after>var request = require('superagent')
    , app = require('../../index')
    , models = require('../../app/models')
    , funcTestHelper = require('./functional_test_helper')

describe("PasswordsController", function() {
  beforeEach(funcTestHelper.flushDb())

  describe("#create()", function() {
    var authToken
      , luna
      , user
      , oldEmail = '<EMAIL>'

    beforeEach(funcTestHelper.createUser('Luna', 'password', { 'email': oldEmail }, function(token, luna) {
      authToken = token
      user = luna
    }))

    it('should generate resetToken by email', function(done) {
      var email = "<EMAIL>"

      request
        .post(app.config.host + '/v1/users/' + user.id)
        .send({ authToken: authToken,
                user: { email: email },
                '_method': 'put' })
        .end(function(err, res) {
          request
            .post(app.config.host + '/v1/passwords')
            .send({ email: email })
            .end(function(err, res) {
              res.body.should.not.be.empty
              res.body.should.have.property('message')
              res.body.message.should.eql('We will send a password reset link to ' + email + ' in a moment')
              done()
            })
        })
    })

    it('should generate resetToken by email for a new user', function(done) {
      request
        .post(app.config.host + '/v1/passwords')
        .send({ email: oldEmail })
        .end(function(err, res) {
          res.body.should.not.be.empty
          res.body.should.have.property('message')
          res.body.message.should.eql('We will send a password reset link to ' + oldEmail + ' in a moment')
          done()
        })
    })

    it('should require email', function(done) {
      var email = "<EMAIL>"

      request
        .post(app.config.host + '/v1/users/' + user.id)
        .send({ authToken: authToken,
                user: { email: email },
                '_method': 'put' })
        .end(function(err, res) {
          request
            .post(app.config.host + '/v1/passwords')
            .end(function(err, res) {
              res.body.should.not.be.empty
              res.body.should.have.property('err')
              res.body.err.should.eql('Email cannot be blank')
              done()
            })
        })
    })
  })

  describe('#update()', function() {
    var authToken
      , user
      , luna

    beforeEach(funcTestHelper.createUser('Luna', 'password', function(token, luna) {
      authToken = token
      user = luna
    }))

    beforeEach(function(done) {
      var email = "<EMAIL>"

      request
        .post(app.config.host + '/v1/users/' + user.id)
        .send({ authToken: authToken,
                user: { email: email },
                '_method': 'put' })
        .end(function(err, res) {
          request
            .post(app.config.host + '/v1/passwords')
            .send({ email: email })
            .end(function(err, res) {
              done()
            })
        })
    })

    it('should not reset password by invalid resetToken', function(done) {
      request
        .post(app.config.host + '/v1/passwords/token')
        .send({ '_method': 'put' })
        .end(function(err, res) {
          res.body.should.not.be.empty
          res.body.should.have.property('err')
          res.body.err.should.eql('Record not found')
          done()
        })
    })
  })
})

{'fraction_non_alphanumeric': 0.15260926765092822, 'fraction_numerical': 0.00233883935097208, 'mean_word_length': 1.7466880770774789, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6692022', 'n_tokens_mistral': 2047, 'n_tokens_neox': 2002, 'n_words': 412}