-JUser            = null
-JAccount         = null
-
-Bongo            = require 'bongo'
-koding           = require './../bongo'
-request          = require 'request'
-
-{ daisy }        = Bongo
-{ expect }       = require 'chai'
-
-{ generateRandomEmail
+{ async
+  expect
+  request
+  generateRandomEmail
   generateRandomString }            = require '../../../testhelper'
 { generateRegisterRequestParams }   = require '../../../testhelper/handler/registerhelper'
 { generateGetProfileRequestParams } = require '../../../testhelper/handler/getprofilehelper'
 
+JUser    = require '../../../models/user'
+JAccount = require '../../../models/account'
+
 # begin tests
 describe 'server.handlers.getprofile', ->
-
-  beforeEach (done) ->
-
-    # including models before each test case, requiring them outside of
-    # tests suite is causing undefined errors
-    {
-      JUser
-      JAccount
-    } = koding.models
-
-    done()
-
 
   it 'should send HTTP 404 if user is not found for the given email.', (done) ->
 


    methods.forEach (method) ->
      requestParams = generateGetProfileRequestParams { email, method }
      queue.push ->
        request requestParams, (err, res, body) ->
          expect(err)             .to.not.exist
          expect(res.statusCode)  .to.be.equal 404
          expect(body)            .to.be.equal 'no user found'
          queue.next()

    queue.push -> done()

    daisy queue


  it 'should send HTTP 200 if user is found for the given email.', (done) ->


    profileRequestParams  = generateGetProfileRequestParams { email, method : 'post' }

    queue.push (next) ->

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

    queue.push (next) ->

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

    async.series queue, done
