                 expect(data).true
                 done()
 
-      describe 'Other', ->
+      describe 'Hooks', ->
+
+        it 'should restore user state from onConnect hook', (done) ->
+          userName = 'user'
+          onConnect = (server, socket, cb) ->
+            cb null, userName, { whitelistOnly : true }
+          chatServer = new ChatService { port : port }
+          , { onConnect : onConnect }
+          , state
+          socket1 = ioClient.connect url1, makeParams(user1)
+          socket1.on 'loginConfirmed', (u) ->
+            expect(u).equal(userName)
+            chatServer.chatState.getOnlineUser userName, (error, u) ->
+              expect(u.username).equal(userName)
+              u.directMessagingState.whitelistOnlyGet (error, data) ->
+                expect(data).true
+                done()
+
+        it 'should restore room state from onStart hook', (done) ->
+          room = null
+          msg1 = { author : user1, textMessage : "message", timestamp : 0 }
+          fn = ->
+            chatServer.chatState.getRoom 'roomName', (error, r) ->
+              expect(r.name).equal(room.name)
+              r.roomState.getList 'whitelist', (error, list) ->
+                expect(list).include(user1)
+                r.roomState.messagesGet (error, data) ->
+                  expect(data).instanceof(Array)
+                  expect(data[0]).deep.equal(msg1)
+                  done()
+          onStart = (server, cb) ->
+            expect(server).instanceof(ChatService)
+            room = new Room server, 'roomName'
+            room.initState { whitelist : [ user1 ]
+              , owner : user2
+              , lastMessages : [ msg1 ] }
+            , ->
+              server.chatState.addRoom room, ->
+                cb null, room
+                fn()
+          chatServer = new ChatService { port : port }
+          , { onStart : onStart }, state
+
+        it 'should exectute onClose hook', (done) ->
+          err = 'error'
+          closeHook = (server, error, cb) ->
+            expect(server).instanceof(ChatService)
+            expect(error).equal(err)
+            cb()
+          chatServer1 = new ChatService { port : port }
+          , { onClose : closeHook }, state
+          chatServer1.close done, err
 
         it 'should execute before and after messages hooks', (done) ->
           someData = 'data'

            socket1.on 'loginConfirmed', ->
              socket1.emit 'roomJoin', roomName1, (error, data) ->
                socket1.emit 'roomAddToList', roomName1, 'adminlist', [user2]
                , (error, data) ->
                  expect(error).ok
                  done()

          socket1.on 'loginConfirmed', ->
            socket2 = ioClient.connect url1, makeParams(user2)
            socket2.on 'loginConfirmed', ->
              chatServer.chatState.getOnlineUser user2, (error, user) ->
                user.directMessagingState.whitelistOnlySet true, ->
                  user.directMessagingState.addToList 'whitelist', [user1], ->
                    socket1.emit 'directMessage', user2, message
                    , (error, data) ->
                      expect(error).not.ok
                      expect(data.textMessage).equal(txt)
                      user.directMessagingState.removeFromList 'whitelist'
                      , [user1], ->
                        socket1.emit 'directMessage', user2, message
                        ,(error, data) ->
                          expect(error).ok
                          done()

        it 'should allow user to modify own lists', (done) ->
          chatServer = new ChatService { port : port
