         passwordConfirm : 'anotherPassword'
 
     request.post joinTeamRequestParams, (err, res, body) ->
-      expect(err)             .to.not.exist
-      expect(res.statusCode)  .to.be.equal 400
-      expect(body)            .to.be.equal 'Passwords must match!'
+      expect(err).to.not.exist
+      expect(res.statusCode).to.be.equal 400
+      expect(body).to.be.equal 'Passwords must match!'
       done()
 
 
+beforeTests()
+
 runTests()

        redirect  : 'www.someurl.com'

    request.post postParams, (err, res, body) ->
      expect(err)             .to.not.exist
      expect(res.statusCode)  .to.be.equal 301
      done()


  # joining an unregistered user to the newly created team
  it 'should be able to join unregistered invitee with valid data', (done) ->

    slug                    = generateRandomString()
    token                   = ''
    groupId                 = ''
    accountId               = ''
    inviteeEmail            = generateRandomEmail()
    inviteeUsername         = generateRandomString()

    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 invitation to be created
        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

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

      ->
        joinTeamRequestParams = generateJoinTeamRequestParams
          body       :
            slug     : slug

            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 : [
