           done()
 
 
-    it 'should be able to create api token with valid request', (done) ->
+    describe 'when request is valid', ->
 
-      group     = generateRandomString()
-      groupData = { isApiEnabled : yes }
-      options   = { context : { group }, createGroup : yes, groupData }
+      it 'should be able to create api token with valid request', (done) ->
 
-      withConvertedUser options, ({ client, account }) ->
+        group     = generateRandomString()
+        groupData = { isApiEnabled : yes }
+        options   = { context : { group }, createGroup : yes, groupData }
 
-        data = { group, account }
-        JApiToken.create data, (err, token) ->
-          expect(err).to.not.exist
-          expect(token.code).to.be.a 'string'
-          expect(token.createdAt).to.exist
-          expect(token.modifiedAt).to.exist
-          expect(token.group).to.equal group
-          expect(token.originId).to.deep.equal account._id
-          done()
+        withConvertedUser options, ({ client, account }) ->
+
+          data = { group, account }
+          JApiToken.create data, (err, token) ->
+            expect(err).to.not.exist
+            expect(token.code).to.be.a 'string'
+            expect(token.createdAt).to.exist
+            expect(token.modifiedAt).to.exist
+            expect(token.group).to.equal group
+            expect(token.originId).to.deep.equal account._id
+            done()
+
+
+      it 'should fail if group exceeds api token count limit', (done) ->
+
+        group     = generateRandomString()
+        groupData = { isApiEnabled : yes }
+        options   = { context : { group }, createGroup : yes, groupData }
+
+        withConvertedUser options, ({ client, account }) ->
+
+          data  = { group, account }
+          queue = []
+
+          for i in [0...JGroup.API_TOKEN_LIMIT]
+            queue.push ->
+              JApiToken.create data, (err, token) ->
+                expect(err).to.not.exist
+                expect(token).to.exist
+                queue.next()
+
+          queue.push ->
+            expectedError = "You can't have more than #{JGroup.API_TOKEN_LIMIT} api tokens"
+            JApiToken.create data, (err, token) ->
+              expect(err?.message).to.be.equal expectedError
+              expect(token).to.not.exist
+              queue.next()
+
+          queue.push -> done()
+
+          daisy queue
 
 
   describe '#create$()', ->

  generateRandomString
  checkBongoConnectivity } = require '../../../testhelper'

JApiToken = require './apitoken'

# making sure we have db connection before tests

      group         = generateRandomString()
      groupData     = {}
      options       = { context : { group }, createGroup : yes, groupData }
      expectedError = 'API usage is not enabled for this group.'

      withConvertedUser options, ({ client, account }) ->

