-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAppSpec.scala
127 lines (108 loc) · 3.43 KB
/
AppSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package example
import skinny.jackson.JSONStringOps
import skinny.test.SkinnyFunSpec
import scala.util._
class AppSpec extends SkinnyFunSpec with JSONStringOps {
addFilter(App, "/*")
describe("Usage example app") {
it("renders HTML body with Scalate") {
get("/") {
status should equal(200)
body.startsWith("<html>") should equal(true)
header("Content-Type") should equal("text/html;charset=utf-8")
}
}
it("supports various HTTP methods") {
get("/method") { status should equal(200) }
post("/method") { status should equal(200) }
put("/method") { status should equal(200) }
patch("/method") { status should equal(200) }
delete("/method") { status should equal(200) }
head("/method") { status should equal(200) }
options("/method") { status should equal(200) }
}
it("renders text/plain body by default") {
get("/text") {
status should equal(200)
body should equal("Hello, world!")
}
}
it("returns any HTTP response status code") {
get("/status/200") { status should equal(200) }
get("/status/201") { status should equal(201) }
}
it("returns Set-Cookie headers") {
get("/cookies") {
status should equal(200)
response.headers("Set-Cookie") should equal(Seq("foo=bar", "foo=bar;Domain=localhost"))
}
get("/cookies-2") {
status should equal(200)
response.headers("Set-Cookie") should equal(Seq("foo=bar", "foo=bar;Domain=localhost"))
}
}
it("renders JSON body") {
get("/sample.json") {
status should equal(200)
body should equal("""{"name":"Martin","id":123}""")
}
}
it("accepts params") {
post("/params.json?baz=123", Map("foo" -> "bar")) {
status should equal(200)
body should equal("""{"baz":"123","foo":"bar"}""")
}
get("/query-params.json", Map("foo" -> "bar")) {
status should equal(200)
body should equal("""{"foo":"bar"}""")
}
post("/form-params.json?baz=123", Map("foo" -> "bar")) {
status should equal(200)
body should equal("""{"foo":"bar"}""")
}
}
it("accepts json body params") {
post("/json-params", """{"name":"Alice","age":"18"}""".getBytes, Map("Content-Type" -> "application/json")) {
status should equal(200)
body should equal("""Map(age -> 18, name -> Alice)""")
}
}
it("accepts path params") {
get("/path-params/foo-bar") {
status should equal(200)
body should equal("foo-bar")
}
}
it("accepts splat params") {
get("/say/hello/to/world") {
status should equal(200)
body should equal("""Vector(hello, world)""")
}
get("/download/path/to/file.xml") {
status should equal(200)
body should equal("""Vector(path/to/file, xml)""")
}
}
it("accepts captured path params") {
get("/foo/bar") {
status should equal(200)
body should equal("""List(oo, ar)""")
}
}
it("Future values") {
get("/future") {
status should equal(200)
body should equal("ok after 100ms")
}
post("/future/params.json?baz=123", Map("foo" -> "bar")) {
status should equal(200)
body should equal("""{"baz":"123","foo":"bar"}""")
}
}
it("returns 500 error") {
get("/error") {
status should equal(500)
}
}
}
}