Skip to content

Instantly share code, notes, and snippets.

@manjotmona
Last active June 10, 2018 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manjotmona/ec9ce256a6ae55844ac4986f047af3a9 to your computer and use it in GitHub Desktop.
Save manjotmona/ec9ce256a6ae55844ac4986f047af3a9 to your computer and use it in GitHub Desktop.
class RestSpec extends WordSpec with Matchers with ScalatestRouteTest with MockitoSugar {
val mockUserImpl = mock[UserImpl]
object TestObject extends RestService {
val userImpl = mockUserImpl
}
"The service" should {
"return user added as response for a Post request to /adduser" in {
when(mockUserImpl.addUser(User(2, "test"))).thenReturn(Future.successful(Done))
val jsonRequest = ByteString(
s"""
|{
| "id":2,
| "name":"test"
|}
""".stripMargin)
val postRequest = HttpRequest(
HttpMethods.POST,
uri = "/adduser",
entity = HttpEntity(MediaTypes.`application/json`, jsonRequest))
postRequest ~> Route.seal(TestObject.route) ~> check {
status.isSuccess() shouldEqual true
responseAs[String] shouldEqual "user added"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment