   user = new User(distinguishedName: dn)
 
   user.save( (err, savedUser) ->
-    if err?
-      console.error err
-      throw new Error(err)
+    return done(err) if err?
 
     assert.strictEqual(
       dn,

  user = new User(password: "password")

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

    assert.notStrictEqual(
      "password",

  ).then( (user) ->
    callback = (err, user) ->
      assert.notOk user, "Expected user to not be returned when authentication fails"
      done()

    user.loginFromLocalDb("ships", callback)
  ).fail(done)
)

test("Usernames must be unique", (done) ->
  helpers.createUser().then( (user) ->
    helpers.createUser()
  ).then( ->
    done(new Error("Expected duplicate user creation to fail"))
  ).fail( (err) ->
    console.error err
    assert.match err, /duplicate key error index/
    done()
  )
)
