           done()
 
 
+    it 'should fail to create required managed vm data if plan limit has been reached', (done) ->
+
+      withConvertedUser { createGroup: 'yes' }, ({ client, account, user, group }) ->
+
+        async.series [
+
+          (next) ->
+            withConvertedUser { role: 'admin' }, (data) ->
+              _client = data.client
+              group.setPlan _client, plan: 'default', (err) ->
+                expect(err).to.not.exist
+                next()
+
+          (next) ->
+            ComputeProvider.updateGroupInstanceUsage group, 'increment', 1, (err) ->
+              expect(err).to.not.exist
+              next()
+
+          (next) ->
+            client.r = { account, user, group }
+            Managed.create client, options, (err) ->
+              expect(err).to.exist
+              expect(err.message).to.be.equal 'Provided limit has been reached'
+
+              next()
+
+        ], done
+
+
   describe '#postCreate()', ->
 
     it 'should update machine and create workspace', (done) ->

{ withConvertedUserAnd } = require \
  '../../../../testhelper/models/computeproviders/computeproviderhelper'

Managed    = require './managed'
JMachine   = require './machine'
JWorkspace = require '../workspace'

# this function will be called once before running any test
beforeTests = -> before (done) ->


  describe '#create()', ->

    options             =
      label             : generateRandomString()
      ipAddress         : '127.0.0.1'
      queryString       : '1/2/3/4/5/6/7/8'

    expectedQueryString = "///////#{options.queryString.split('/').reverse()[0]}"

    it 'should be able to create required managed vm data', (done) ->

      withConvertedUser ({ client, account, user, group }) ->
        client.r = { account, user, group }

        Managed.create client, options, (err, managedVm) ->
          expect(err).to.not.exist
