From 875d0bfffac5cd6cbdd1973677344f32726a4688 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Fri, 9 Apr 2021 01:40:22 +0200 Subject: [PATCH] Add test 404 for GetArticle route --- .../application/http/HttpStatusError.kt | 4 +--- src/main/resources/openapi.yaml | 23 ++++++++++++++++++- src/test/kotlin/integration/Article routes.kt | 12 ++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/fr/dcproject/application/http/HttpStatusError.kt b/src/main/kotlin/fr/dcproject/application/http/HttpStatusError.kt index 2d4f1f2..d515f24 100644 --- a/src/main/kotlin/fr/dcproject/application/http/HttpStatusError.kt +++ b/src/main/kotlin/fr/dcproject/application/http/HttpStatusError.kt @@ -14,10 +14,8 @@ import java.util.concurrent.CompletionException class HttpError( statusCode: HttpStatusCode, - val cause: Throwable? = null, - val type: String? = null, + cause: Throwable? = null, val title: String = cause?.message ?: statusCode.description, - val detail: String? = null, ) { val statusCode: Int = statusCode.value } diff --git a/src/main/resources/openapi.yaml b/src/main/resources/openapi.yaml index 810cb48..6df61e5 100644 --- a/src/main/resources/openapi.yaml +++ b/src/main/resources/openapi.yaml @@ -164,6 +164,13 @@ paths: application/json: schema: $ref: '#/components/schemas/400' + 404: + description: BadReqest + content: + application/json: + schema: + $ref: '#/components/schemas/404' + /articles/{article}/versions: parameters: - $ref: '#/components/parameters/article' @@ -2278,7 +2285,7 @@ components: example: MASTER 400: - description: noting + description: Bad Request required: - title - invalidParams @@ -2304,6 +2311,20 @@ components: type: string example: 'Cannot be null' + 404: + description: Not Found + required: + - title + - statusCode + additionalProperties: false + properties: + statusCode: + type: integer + example: 404 + title: + type: string + example: Bad Request + securitySchemes: JWTAuth: type: http diff --git a/src/test/kotlin/integration/Article routes.kt b/src/test/kotlin/integration/Article routes.kt index fa0cc82..96e6d60 100644 --- a/src/test/kotlin/integration/Article routes.kt +++ b/src/test/kotlin/integration/Article routes.kt @@ -22,6 +22,7 @@ import integration.steps.then.`which contains` import integration.steps.then.and import io.ktor.http.HttpStatusCode.Companion.BadRequest import io.ktor.http.HttpStatusCode.Companion.Forbidden +import io.ktor.http.HttpStatusCode.Companion.NotFound import io.ktor.http.HttpStatusCode.Companion.OK import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Tags @@ -82,6 +83,17 @@ class `Article routes` : BaseTest() { } } + @Test + fun `I cannot get article with id doesn't exist`() { + withIntegrationApplication { + `When I send a GET request`("/articles/635fe2e8-2dbc-4c80-b306-101d38a4ab23") `Then the response should be` NotFound and { + `And the response should not be null`() + `And the response should contain`("$.title", "Article 635fe2e8-2dbc-4c80-b306-101d38a4ab23 not found") + `And the response should contain`("$.statusCode", 404) + } + } + } + @Test @Tag("BadRequest") fun `I cannot get article by id with wrong id format`() {