add category controller test and refactor some code