         form = req.form()
         form.append('name', 'Jim')
 
-  it 'preparing test : clears the db first', (done) ->
-    clearModels [User], (err) ->
-      throw err if err
-      done()
-
-  it 'converts the password into a hash', (done) ->
-    unittest.getNormalJoe (user) ->
-      expect(user).toBeTruthy()
-      expect(user.get('password')).toBeUndefined()
-      expect(user?.get('passwordHash')).not.toBeUndefined()
-      if user?.get('passwordHash')?
-        expect(user.get('passwordHash')[..5]).toBe('31dc3d')
-        expect(user.get('permissions').length).toBe(0)
-      done()
-
-  it 'serves the user through /db/user/id', (done) ->
-    unittest.getNormalJoe (user) ->
-      url = getURL(urlUser+'/'+user._id)
-      request.get url, (err, res, body) ->
-        expect(res.statusCode).toBe(200)
-        user = JSON.parse(body)
-        expect(user.email).toBe('normal@jo.com')
-        expect(user.passwordHash).toBeUndefined()
-        done()
-
-  it 'creates admins based on passwords', (done) ->
+  it 'should not allow multiple anonymous users with same name anymore', (done) ->
     request.post getURL('/auth/logout'), ->
-      unittest.getAdmin (user) ->
-        expect(user).not.toBeUndefined()
-        if user
-          expect(user.get('permissions').length).toBe(1)
-          expect(user.get('permissions')[0]).toBe('admin')
-        done()
-
-  it 'does not return the full user object for regular users.', (done) ->
-    loginJoe ->
-      unittest.getAdmin (user) ->
-
-        url = getURL(urlUser+'/'+user._id)
-        request.get url, (err, res, body) ->
-          expect(res.statusCode).toBe(200)
-          user = JSON.parse(body)
-          expect(user.email).toBeUndefined()
-          expect(user.passwordHash).toBeUndefined()
-          done()
-
-  it 'should allow setting anonymous user name', (done) ->
-    createAnonNameUser(done)
-
-  it 'should allow multiple anonymous users with same name', (done) ->
-    createAnonNameUser(done)
-
+      request.get getURL('/auth/whoami'), ->
+        req = request.post(getURL('/db/user'), (err, response) ->
+          expect(response.statusCode).toBe(409)
+          request.get getURL('/auth/whoami'), (request, response, body) ->
+            res = JSON.parse(response.body)
+            expect(res.anonymous).toBeTruthy()
+            expect(res.name).not.toEqual('Jim')
+            done()
+        )
+        form = req.form()
+        form.append('name', 'Jim')
 
   it 'should not allow setting existing user name to anonymous user', (done) ->
 


describe 'POST /db/user', ->

  createAnonNameUser = (done)->
    request.post getURL('/auth/logout'), ->
      request.get getURL('/auth/whoami'), ->
        req = request.post(getURL('/db/user'), (err, response) ->

      expect(response.statusCode).toBe(422)
      done()
    )

  it 'can fetch myself by id completely', (done) ->
    loginSam (sam) ->
      request.get {url: getURL(urlUser + '/' + sam.id)}, (err, response) ->
        expect(err).toBeNull()
        expect(response.statusCode).toBe(200)
        done()

  # TODO Ruben should be able to fetch other users but probably with restricted data access
  # Add to the test case above an extra data check

  it 'can fetch myself by slug completely', (done) ->
    loginSam (sam) ->
      request.get {url: getURL(urlUser + '/sam')}, (err, response) ->
        expect(err).toBeNull()
        expect(response.statusCode).toBe(200)
        guy = JSON.parse response.body
        expect(guy._id).toBe sam.get('_id').toHexString()
        expect(guy.name).toBe sam.get 'name'
        done()







