Refactor api testing