Last active
September 16, 2015 12:21
-
-
Save PuppetmasterDK/96bf1e5c3d202540aa03 to your computer and use it in GitHub Desktop.
This file contains 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
import acolyte.reactivemongo.AcolyteDSL.{handleQuery, withFlatCollection} | |
import acolyte.reactivemongo.{AcolyteDSL, QueryResponse, Request} | |
import org.specs2.concurrent.ExecutionEnv | |
import org.specs2.mutable.Specification | |
import org.specs2.specification.core.Fragments | |
import org.specs2.specification.create.DefaultFragmentFactory | |
import reactivemongo.bson.{BSONDocument, BSONObjectID} | |
import repositories.Users | |
import scala.concurrent.duration._ | |
sealed trait AcolyteDriver { | |
specs: Specification => | |
implicit lazy val driver = AcolyteDSL.driver | |
override def map(fs: ⇒ Fragments) = fs ^ DefaultFragmentFactory.step(driver.close()) | |
} | |
class UserServiceMongoSpec extends Specification with AcolyteDriver { | |
val john = models.User(BSONObjectID.generate, "John", "Doe", "joe@example", Some("password"), "email-not-verified") | |
"User Mongo" title | |
"List specific users" should { | |
val userFixtures = QueryResponse.successful(BSONDocument("_id" -> john.id.stringify, "firstName" -> john.firstName, "lastName" -> john.lastName, "email" -> john.email, "password" -> john.password.get, "state" -> john.state)) | |
val withFixtures = handleQuery { r: Request => userFixtures } | |
val withEmptyFixtures = handleQuery { r: Request => QueryResponse.successful() } | |
"return None if the ID is invalid formatted" in { implicit ee: ExecutionEnv => | |
withFlatCollection(withFixtures, "users") { implicit col => | |
val mongo = new Users(col) | |
mongo.details("not an id") | |
} aka "user information" must beEqualTo(None).awaitFor(5 seconds) | |
} | |
"return None if the ID is valid but empty collection" in { implicit ee: ExecutionEnv => | |
withFlatCollection(withEmptyFixtures, "users") { implicit col => | |
val mongo = new Users(col) | |
mongo.details(BSONObjectID.generate.stringify) | |
} aka "user information" must beEqualTo(None).awaitFor(5 seconds) | |
} | |
"be able to fetch a user" in { implicit ee: ExecutionEnv => | |
withFlatCollection(withFixtures, "users") { implicit col => | |
val mongo = new Users(col) | |
mongo.details(john.id.stringify) | |
} aka "user information" must beEqualTo(Some(john)).awaitFor(5 seconds) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment