add tests for handle_chat_message + refactoring