Skip to content

Commit

Permalink
Merge b5936d0 into 0e0d6d9
Browse files Browse the repository at this point in the history
  • Loading branch information
David Shiga committed May 8, 2015
2 parents 0e0d6d9 + b5936d0 commit a2bc197
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,48 @@ class ApiServiceSpec extends FlatSpec with Matchers with Directives with Scalate
Get(ApiUtil.Methods.withLeadingSlash + "/" + namespace1 + "/" + name1 + "/"
+ insertedEntity.id.get) ~> methodsService.queryByNamespaceNameIdRoute ~> check {
val rawResponse = responseAs[String]
val response = grater[AgoraEntity].fromJSONArray(rawResponse)
response === insertedEntity
val response = grater[AgoraEntity].fromJSONArray(rawResponse).head
assert(response === insertedEntity)
}
}

"Agora" should "return methods matching the query" in {
agoraDao.insert(testEntity2)
agoraDao.insert(testEntity3)
agoraDao.insert(testEntity4)
Get(ApiUtil.Methods.withLeadingSlash + "?namespace=" + namespace1 + "&owner=" + owner1) ~> methodsService.queryRoute ~> check {
Get(ApiUtil.Methods.withLeadingSlash + "?namespace=" + namespace1 + "&name=" + name1) ~> methodsService.queryRoute ~> check {
val rawResponse = responseAs[String]
val response = grater[AgoraEntity].fromJSONArray(rawResponse)
response === Seq(testEntity1, testEntity2)
assert(response === Seq(testEntity1, testEntity4))
}
}

"Agora" should "create and return a method" in {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testAddRequest)) ~> methodsService.postRoute ~> check {
val rawResponse = responseAs[String]
val response = grater[AgoraEntity].fromJSON(rawResponse)
response.namespace === namespace1
response.name === name1
response.synopsis === synopsis
response.documentation === documentation
response.owner === owner1
response.payload === payload
response.id === 1
response.createDate != null
assert(response.namespace.get === namespace1)
assert(response.name.get === name1)
assert(response.synopsis.get === synopsis)
assert(response.documentation.get === documentation)
assert(response.owner.get === owner1)
assert(response.payload.get === payload)
assert(response.id.get !== None)
assert(response.createDate.get != null)
}
}

"Agora" should "return a 400 bad request when posting a malformed payload" in {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testBadAddRequest)) ~> methodsService.postRoute ~> check {
status === BadRequest
responseAs[String] != null
assert(status === BadRequest)
assert(responseAs[String] != null)
}
}

"Agora" should "store 10kb of github markdown as method documentation and return it without alteration" in {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testAddRequest)) ~> methodsService.postRoute ~> check {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testAddRequestBigDoc)) ~> methodsService.postRoute ~> check {
val rawResponse = responseAs[String]
grater[AgoraEntity].fromJSON(rawResponse).documentation === bigDocumentation
assert(grater[AgoraEntity].fromJSON(rawResponse).documentation.get === bigDocumentation)
}
}
}

0 comments on commit a2bc197

Please sign in to comment.