Refactor test api