     generateCreateTeamRequestParams options, (createTeamRequestParams) ->
 
       request.post createTeamRequestParams, (err, res, body) ->
-        expect(err)             .to.not.exist
-        expect(res.statusCode)  .to.be.equal 400
+        expect(err).to.not.exist
+        expect(res.statusCode).to.be.equal 400
         done()
 
 
   it 'should send HTTP 400 when email is in use and username is not in use', (done) ->
 
-    email                   = generateRandomEmail()
-    username                = generateRandomString()
-    anotherUsername         = generateRandomString()
-
-    registerRequestParams   = generateRegisterRequestParams
+    email           = generateRandomEmail()
+    username        = generateRandomString()
+    anotherUsername = generateRandomString()
+
+    registerRequestParams = generateRegisterRequestParams
       body        :
         email     : email
         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
-          queue.next()
-
-      ->
+          expect(err).to.not.exist
+          expect(res.statusCode).to.be.equal 200
+          next()
+
+      (next) ->
         options = { body : { email, username : anotherUsername } }
         generateCreateTeamRequestParams options, (createTeamRequestParams) ->
         #
           # expecting HTTP 400 from juser.convert
           expectedBody = 'Email is already in use!'
           request.post createTeamRequestParams, (err, res, body) ->
-            expect(err)             .to.not.exist
-            expect(res.statusCode)  .to.be.equal 400
-            expect(body)            .to.be.equal expectedBody
-            queue.next()
-
-      -> done()
-
-    ]
-
-    daisy queue
+            expect(err).to.not.exist
+            expect(res.statusCode).to.be.equal 400
+            expect(body).to.be.equal expectedBody
+            next()
+
+    ]
+
+    async.series queue, done
 
 
   it 'should send HTTP 400 when username is not set', (done) ->
 
-    expectedBody            = 'Errors were encountered during validation: username'
+    expectedBody = 'Errors were encountered during validation: username'
 
     options = { body : { username : '' } }
     generateCreateTeamRequestParams options, (createTeamRequestParams) ->
 
       request.post createTeamRequestParams, (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()
 
 


    createTeamRequestParams = null

    companyName = "testcompany#{generateRandomString(10)}"

    slug               = companyName
    email              = generateRandomEmail()
    domains            = 'koding.com, gmail.com'
    username           = generateRandomUsername()
    inviteeEmail       = generateRandomEmail()
    invitees           = inviteeEmail
    companyName        = companyName

    queue = [

      ->
        options = { body : { slug, email, domains, username, invitees, companyName } }
        generateCreateTeamRequestParams options, (createTeamRequestParams) ->

          # expecting HTTP 200 status code on team create request
          request.post createTeamRequestParams, (err, res, body) ->
            expect(err)             .to.not.exist
            expect(res.statusCode)  .to.be.equal 200
            queue.next()

      ->
        # expecting user to be saved
        params = { username }

        JUser.one params, (err, user) ->
          expect(err)                  .to.not.exist
          expect(user.email)           .to.be.equal email
          expect(user.passwordStatus)  .to.be.equal 'valid'
          queue.next()

      ->
        # expecting group to be saved
        allowedDomains = convertToArray domains

        JGroup.one { slug }, (err, group) ->
          expect(err)         .to.not.exist
          expect(group.title) .to.be.equal companyName

          allowedDomains.forEach (domain) ->
            expect(group.allowedDomains).to.include domain
          queue.next()

      ->
        # expecting account to be saved
        params = { 'profile.nickname' : username }

        JAccount.one params, (err, account) ->
          expect(err)     .to.not.exist
          expect(account) .to.exist
          queue.next()

      ->
        # expecting domainAlias to be saved
        params = { domain : "#{username}.dev.koding.io" }

        JDomainAlias.one params, (err, domainAlias) ->
          expect(err)         .to.not.exist
          expect(domainAlias) .to.exist
          queue.next()

      ->
        # expecting name to be saved
        params = { name : username }

        JName.one params, (err, jname) ->
          expect(err)   .to.not.exist
          expect(jname) .to.exist
          queue.next()

      ->
        # expecting invitation to be created with correct data
        params = { email : inviteeEmail }

        JInvitation.one params, (err, invitation) ->
          expect(err)                   .to.not.exist
          expect(invitation)            .to.exist
          expect(invitation.code)       .to.exist
          expect(invitation.email)      .to.be.equal inviteeEmail
          expect(invitation.status)     .to.be.equal 'pending'
          expect(invitation.groupName)  .to.be.equal slug
          queue.next()

      ->
        # expecting session to be created
        params = { username }

        JSession.one params, (err, session) ->
          expect(err)               .to.not.exist
          expect(session)           .to.exist
          expect(session.username)  .to.be.equal username
          queue.next()

      -> done()

    ]

    daisy queue


  it 'should save relationships correctly', (done) ->

    slug                    = generateRandomString()
    userId                  = ''
    groupId                 = ''
    username                = generateRandomString()
    accountId               = ''

    queue = [

      ->
        options = { body : { username, slug } }
        generateCreateTeamRequestParams options, (createTeamRequestParams) ->

          # expecting HTTP 200 status code
          request.post createTeamRequestParams, (err, res, body) ->
            expect(err)             .to.not.exist
            expect(res.statusCode)  .to.be.equal 200
            queue.next()

      ->
        # expecting user to be saved and holding userId
        params = { username }

        JUser.one params, (err, user) ->
          expect(err)   .to.not.exist
          expect(user)  .to.exist
          userId = user._id
          queue.next()

      ->
        # expecting account to be saved and holding accountId
        params = { 'profile.nickname' : username }

        JAccount.one params, (err, account) ->
          expect(err)     .to.not.exist
          expect(account) .to.exist
          accountId = account._id
          queue.next()

      ->
        # expecting group to be saved and holding groupId
        params = { slug }

        JGroup.one params, (err, group) ->
          expect(err)     .to.not.exist
          expect(group)   .to.exist
          groupId = group._id
          queue.next()

      ->
        # expecting owner account of the group to be saved
        params =
          $and : [

          ]

        Relationship.one params, (err, relationship) ->
          expect(err).to.not.exist
          expect(relationship).to.exist
          next()

      (next) ->
        # expecting user to be saved as the owner of the account
        params =
          $and : [
