Skip to content

Commit c145805

Browse files
committed
Add unit tests for backend controller.
1 parent 41fcb1c commit c145805

File tree

2 files changed

+48
-46
lines changed

2 files changed

+48
-46
lines changed

test/FunctionalSpec.scala

Lines changed: 0 additions & 46 deletions
This file was deleted.

test/HomeControllerSpec.scala

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package controllers
2+
3+
import org.scalatestplus.play._
4+
import org.scalatestplus.play.guice._
5+
import play.api.test._
6+
import play.api.test.Helpers._
7+
8+
/**
9+
* Add your spec here.
10+
* You can mock out a whole application including requests, plugins etc.
11+
*
12+
* For more information, see https://www.playframework.com/documentation/latest/ScalaTestingWithScalaTest
13+
*/
14+
class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting {
15+
16+
"HomeController GET" should {
17+
18+
"render the appSummary page from a new instance of controller" in {
19+
val controller = new HomeController(stubControllerComponents())
20+
val home = controller.appSummary().apply(FakeRequest(GET, "/summary"))
21+
22+
status(home) mustBe OK
23+
contentType(home) mustBe Some("application/json")
24+
val resultJson = contentAsJson(home)
25+
resultJson.toString() mustBe """{"content":"Scala Play Angular Seed"}"""
26+
}
27+
28+
"render the appSummary page from the application" in {
29+
val controller = inject[HomeController]
30+
val home = controller.appSummary().apply(FakeRequest(GET, "/summary"))
31+
32+
status(home) mustBe OK
33+
contentType(home) mustBe Some("application/json")
34+
val resultJson = contentAsJson(home)
35+
resultJson.toString() mustBe """{"content":"Scala Play Angular Seed"}"""
36+
}
37+
38+
"render the appSummary page from the router" in {
39+
val request = FakeRequest(GET, "/summary")
40+
val home = route(app, request).get
41+
42+
status(home) mustBe OK
43+
contentType(home) mustBe Some("application/json")
44+
val resultJson = contentAsJson(home)
45+
resultJson.toString() mustBe """{"content":"Scala Play Angular Seed"}"""
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)