Skip to content

Commit

Permalink
#8 first test list in template controller
Browse files Browse the repository at this point in the history
  • Loading branch information
FRosner committed Jun 28, 2016
1 parent 5bfcd73 commit 98256f0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/de/frosner/broccoli/controllers/TemplateControllerSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.frosner.broccoli.controllers

import de.frosner.broccoli.models.Template
import de.frosner.broccoli.services.TemplateService
import org.specs2.mutable.Specification
import play.api.test.{FakeRequest, PlaySpecification}
import org.mockito.Mockito._
import play.api.libs.json.{JsArray, JsObject, JsString}
import org.specs2.concurrent.ExecutionEnv
import play.api.mvc.BodyParsers

class TemplateControllerSpec extends PlaySpecification {

"/templates" should {

"list all available templates" in { implicit ee: ExecutionEnv =>
val templateService = mock(classOf[TemplateService])
val template = Template(
id = "id",
template = "template {{name}}",
description = "description"
)
when(templateService.templates).thenReturn(Seq(template))
val controller = new TemplateController(templateService)

val result = controller.list.apply(FakeRequest())
status(result) must be equalTo 200
contentAsJson(result) must be equalTo JsArray(Seq(
JsObject(Map(
"id" -> JsString(template.id),
"parameters" -> JsArray(Seq(JsString("name"))),
"description" -> JsString(template.description)
))
))
}

}

}

0 comments on commit 98256f0

Please sign in to comment.