Add tests to user controller and refactor controller