feature #6: Add simple test for article routes

This commit is contained in:
2019-07-31 23:42:46 +02:00
parent 61da1df9d0
commit 7acb2b3e40
4 changed files with 65 additions and 23 deletions

View File

@@ -16,7 +16,7 @@ begin
a.*,
find_citizen_by_id(a.created_by_id) as created_by
from article as a
where title ilike '%'||"search"||'%'
where "search" is null or title ilike '%'||"search"||'%'
order by
case direction when 'asc' then
case sort

View File

@@ -65,14 +65,14 @@ begin
into generated_number
from article as t
where t.version_id = _version_id
order by version_number
order by version_number desc
limit 1;
elseif tablename = 'constitution'::regclass then
select version_number + 1
into generated_number
from constitution as t
where t.version_id = _version_id
order by version_number
order by version_number desc
limit 1;
else
raise exception '% is not implemented', tablename::text;

View File

@@ -1,20 +0,0 @@
package fr.dcproject
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.withTestApplication
import kotlin.test.Test
import kotlin.test.assertEquals
class ApplicationTest {
@Test
fun testRoot() {
withTestApplication({ module() }) {
handleRequest(HttpMethod.Get, "/articles").apply {
assertEquals(HttpStatusCode.OK, response.status())
assertEquals("todo", response.content)
}
}
}
}

62
test/ArticleRouteTest.kt Normal file
View File

@@ -0,0 +1,62 @@
package fr.dcproject
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.setBody
import io.ktor.server.testing.withTestApplication
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class ArticleRouteTest {
private val article: String = """{
"id" : "8e8dd0aa-2b2b-41e1-bff5-ea613c988774",
"version_id" : "e3ec9ea8-87ac-46ac-8321-8f2bc8c687bc",
"version_number" : 1,
"title" : "title13",
"annonymous" : false,
"content" : "content13",
"description" : "description13",
"tags" : [ "sky", "nuclear" ],
"created_at" : "2019-07-30T14:08:51.420Z",
"created_by" : {
"id" : "d821a211-10d6-4d65-b0db-e0bd33d21761",
"name" : {
"civility" : "m",
"last_name" : "LAST NAME13",
"first_name" : "first name13"
},
"birthday" : "1994-07-30",
"user_id" : "127b9979-1474-4da1-8453-1e10462ae593",
"vote_annonymous" : false,
"follow_annonymous" : false,
"user" : null,
"created_at" : "2019-07-30T14:08:49.742Z"
}
}"""
@Test
fun testRoot() {
withTestApplication({ module() }) {
handleRequest(HttpMethod.Get, "/articles").apply {
assertEquals(HttpStatusCode.OK, response.status())
}
handleRequest(HttpMethod.Post, "/articles") {
this.setBody(article)
this.addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString())
}.apply {
assertEquals(HttpStatusCode.OK, response.status())
}
handleRequest(HttpMethod.Get, "/articles/8e8dd0aa-2b2b-41e1-bff5-ea613c988774").apply {
assertEquals(HttpStatusCode.OK, response.status())
assertTrue(response.content!!.contains("8e8dd0aa-2b2b-41e1-bff5-ea613c988774"))
}
}
}
}