write more tests for users controller api and refactor some code