Skip to content

Instantly share code, notes, and snippets.

@NTCoding
Created January 23, 2016 15:48
Show Gist options
  • Select an option

  • Save NTCoding/8b673c16001af0a0a33f to your computer and use it in GitHub Desktop.

Select an option

Save NTCoding/8b673c16001af0a0a33f to your computer and use it in GitHub Desktop.
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