 
     # expecting HTTP 400 sending wrong alreadyMember value
     request.post joinTeamRequestParams, (err, res, body) ->
-      expect(err)             .to.not.exist
-      expect(res.statusCode)  .to.be.equal 400
-      expect(body)            .to.be.equal 'Unknown user name'
+      expect(err).to.not.exist
+      expect(res.statusCode).to.be.equal 400
+      expect(body).to.be.equal 'Unknown user name'
       done()
 
 
   it 'should send HTTP 400 if username is not set', (done) ->
 
     joinTeamRequestParams = generateJoinTeamRequestParams
-      body         :
-        username   : ''
+      body       :
+        username : ''
 
     expectedBody = 'Errors were encountered during validation: username'
     request.post joinTeamRequestParams, (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()
 
 

            alreadyMember : 'true'

        request.post joinTeamRequestParams, (err, res, body) ->
          expect(err)             .to.not.exist
          expect(res.statusCode)  .to.be.equal 400
          expect(body)            .to.be.equal 'Access denied!'
          queue.next()

      -> done()

    ]

    daisy queue


  it 'should send HTTP 400 if user email is not in allowedDomains', (done) ->

    slug                    = generateRandomString()
    domains                 = 'gmail.com, koding.com'
    domainsArray            = convertToArray domains

    queue = [

      ->
        options = { body : { slug, domains } }
        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()

      ->
        joinTeamRequestParams = generateJoinTeamRequestParams
          body       :
            slug     : slug
            email    : 'notinallowed@domains.com'

        expectedBody = 'Your email domain is not in allowed domains for this group'
        request.post joinTeamRequestParams, (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


  it 'should send HTTP 400 if invitee token is invalid', (done) ->

    slug                    = generateRandomString()
    inviteeEmail            = generateRandomEmail()

    joinTeamRequestParams = generateJoinTeamRequestParams
      body       :
        slug     : slug
        token    : 'someInvalidToken'

    queue = [

      ->
        options = { body : { slug, companyName : slug, invitees : inviteeEmail } }
        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 HTTP 400 using invalid token
        request.post joinTeamRequestParams, (err, res, body) ->
          expect(err)             .to.not.exist
          expect(res.statusCode)  .to.be.equal 400
          expect(body)            .to.be.equal 'Invalid invitation code!'
          queue.next()

      -> done()

    ]

    daisy queue


  it 'should send HTTP 400 if alreadyMember sent with wrong value', (done) ->

            username : inviteeUsername

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

      (next) ->
        # expecting invitation status to be changed after invitee joins
        params = { email : inviteeEmail }

        JInvitation.one params, (err, invitation) ->
          expect(err).to.not.exist
          expect(invitation).to.exist
          expect(invitation.status).to.be.equal 'accepted'

          # saving user invitation token
          token = invitation.code
          next()

      (next) ->
        # expecting session to be created
        params = { username : inviteeUsername }

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

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

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

      (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
          next()

      (next) ->
        # expecting account also to be saved as a group member
        params =
          $and : [
