     authenticationCallback = (err, user) ->
       assert.ok user, "Expected user to be returned when authentication successful"
       assert.strictEqual "hats", user.email
-
       done()
 
     user.loginFromLocalDb("boats", authenticationCallback)
-  ).fail( (err) ->
-    console.error err
-    throw err
-  )
+  ).fail(done)
 )
 
 test(".loginFromLocalDb fails if the user's password is incorrect", (done) ->

  user = new User(distinguishedName: dn)

  user.save( (err, savedUser) ->
    if err?
      console.error err
      throw new Error(err)

    assert.strictEqual(
      dn,

  ).fail(done)
)

test(".isValidPassword returns false if bcrypt(password)
 does not match stored password", (done) ->
  user = new User(password: "password")

  user.save( (err, savedUser) ->
    return done(err) if err?

    savedUser.isValidPassword('password').then( (isValid) ->
      assert.isTrue(
        isValid,
        "Expected password 'password' for user to be valid"
      )

      done()
    ).fail(done)
  )
)

test(".isValidPassword returns true if bcrypt(password)
 matches stored password", (done) ->
  user = new User(password: "password")

  user.save( (err, savedUser) ->
    return done(err) if err?

    savedUser.isValidPassword('hats').then( (isValid) ->
      assert.isFalse(
        isValid,
        "Expected password 'hats' for user to be invalid"
      )

      done()
    ).fail(done)
  )
)

