Refactor unit tests using DRY, add tests for api login