 
     expectedBody = JSON.stringify { kodingUser : false, forbidden : true }
     request.post validateUsernameRequestParams, (err, res, body) ->
-      expect(err)             .to.not.exist
-      expect(res.statusCode)  .to.be.equal 400
-      expect(body)            .to.be.equal expectedBody
+      expect(err).to.not.exist
+      expect(res.statusCode).to.be.equal 400
+      expect(body).to.be.equal expectedBody
       done()
 
 
   it 'should send HTTP 400 if username is in use', (done) ->
 
-    username                      = generateRandomUsername()
+    username = generateRandomUsername()
 
     validateUsernameRequestParams = generateValidateUsernameRequestParams
       body       :
         username : username
 
-    registerRequestParams         = generateRegisterRequestParams
+    registerRequestParams = generateRegisterRequestParams
       body       :
         username : username
 
     queue = [
 
-      ->
+      (next) ->
         # registering a new user
         request.post registerRequestParams, (err, res, body) ->
-          expect(err)             .to.not.exist
-          expect(res.statusCode)  .to.be.equal 200
-          expect(body)            .to.be.equal ''
-          queue.next()
+          expect(err).to.not.exist
+          expect(res.statusCode).to.be.equal 200
+          expect(body).to.be.equal ''
+          next()
 
-      ->
+      (next) ->
         # expecting existing username to return 400
         expectedBody = JSON.stringify { kodingUser : true, forbidden : false }
         request.post validateUsernameRequestParams, (err, res, body) ->
-          expect(err)             .to.not.exist
-          expect(res.statusCode)  .to.be.equal 400
-          expect(body)            .to.be.equal expectedBody
-          queue.next()
-
-      -> done()
+          expect(err).to.not.exist
+          expect(res.statusCode).to.be.equal 400
+          expect(body).to.be.equal expectedBody
+          next()
 
     ]
 
-    daisy queue
+    async.series queue, done
 
 
   it 'should send HTTP 400 if username does not have valid character length', (done) ->

Bongo                                     = require 'bongo'
koding                                    = require './../bongo'
request                                   = require 'request'

{ daisy }                                 = Bongo
{ expect }                                = require 'chai'
{ generateRandomString
  generateRandomUsername }                = require '../../../testhelper'
{ generateRegisterRequestParams }         = require '../../../testhelper/handler/registerhelper'
{ generateValidateUsernameRequestParams } = require '../../../testhelper/handler/validateusernamehelper'

JUser                                     = null


# here we have actual tests
runTests = -> describe 'server.handlers.validateusername', ->

  beforeEach (done) ->

    # including models before each test case, requiring them outside of
    # tests suite is causing undefined errors
    { JUser } = koding.models

    done()


  it 'should send HTTP 404 if request method is not POST', (done) ->



    queue = [

      (next) ->
        # expecting username that has average character length to return 200
        validateUsernameRequestParams = generateValidateUsernameRequestParams
          body       :
            username : generateRandomString Math.round (maxLength + minLength) / 2

        request.post validateUsernameRequestParams, (err, res, body) ->
          expect(err).to.not.exist
          expect(res.statusCode).to.be.equal 200
          expect(body).to.be.equal expectedBody
          next()

      (next) ->
        # expecting username that has minimum character length to return 200
        validateUsernameRequestParams = generateValidateUsernameRequestParams
          body       :
            username : generateRandomString minLength

        request.post validateUsernameRequestParams, (err, res, body) ->
          expect(err).to.not.exist
          expect(res.statusCode).to.be.equal 200
          expect(body).to.be.equal expectedBody
          next()

      (next) ->
        # expecting username that has maximum character length to return 200
        validateUsernameRequestParams = generateValidateUsernameRequestParams
          body       :
