Refactor api test