Created
January 23, 2016 15:48
-
-
Save NTCoding/8b673c16001af0a0a33f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RecommendAFriendSpecs extends FreeSpec with Matchers with FutureAwaits with DefaultAwaitTimeout { | |
| val repo = mock(classOf[UserRepository]) | |
| val validator = mock(classOf[NewAccountValidator]) | |
| val policy = mock(classOf[ReferralPolicy]) | |
| val userId = "12345" | |
| val user = User(userId) | |
| val friend = User("friendId") | |
| val friendsDetails = NewAccountDetails("abc@mailinator.com", "abb", 1) | |
| val results = Seq(PromoteToGoldStatus(userId)) | |
| "When an existing user" - { | |
| when(repo.find(userId)).thenReturn(Future.successful(Some(user))) | |
| "recommends a friend using details that validate" - { | |
| when(validator.validate(friendsDetails)).thenReturn(None) | |
| "the friend is created and the referral policy's decision is returned" in { | |
| when(repo.create(friendsDetails)).thenReturn(Future.successful(friend)) | |
| when(policy.apply(user, friend)).thenReturn(results) | |
| val f = new FriendRecommender(validator, repo, policy).recommendAFriend(userId, friendsDetails) | |
| assert(await(f) === Right(results)) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment