refactor test to have less duplicated code