some refactoring and unit test for simulate promise