From fe11384ad284c834aa5acd55828a57dd3773ac6f Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Tue, 6 Apr 2021 23:04:02 +0200 Subject: [PATCH] Add validation on route GetOneArticle --- .../fr/dcproject/application/Converters.kt | 2 +- src/main/resources/openapi.yaml | 6 ++++++ src/test/kotlin/integration/Article routes.kt | 19 ++++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/fr/dcproject/application/Converters.kt b/src/main/kotlin/fr/dcproject/application/Converters.kt index 3226ffd..4a67f2e 100644 --- a/src/main/kotlin/fr/dcproject/application/Converters.kt +++ b/src/main/kotlin/fr/dcproject/application/Converters.kt @@ -31,7 +31,7 @@ val converters: ConverterDeclaration = { invalidParams = listOf( InvalidParam( "ID", - "ID must be UUID" + "must be UUID" ) ) ) diff --git a/src/main/resources/openapi.yaml b/src/main/resources/openapi.yaml index 1013e31..4706131 100644 --- a/src/main/resources/openapi.yaml +++ b/src/main/resources/openapi.yaml @@ -147,6 +147,12 @@ paths: application/json: schema: $ref: '#/components/schemas/ArticleResponse' + 400: + description: BadReqest + content: + application/json: + schema: + $ref: '#/components/schemas/400' /articles/{article}/versions: parameters: - $ref: '#/components/parameters/article' diff --git a/src/test/kotlin/integration/Article routes.kt b/src/test/kotlin/integration/Article routes.kt index ce3e2c8..5b12bf0 100644 --- a/src/test/kotlin/integration/Article routes.kt +++ b/src/test/kotlin/integration/Article routes.kt @@ -46,7 +46,7 @@ class `Article routes` : BaseTest() { } @Test - @Tag("Validation") + @Tag("BadRequest") fun `I cannot get article list`() { withIntegrationApplication { `Given I have articles`(3) @@ -82,6 +82,19 @@ class `Article routes` : BaseTest() { } } + @Test + @Tag("BadRequest") + fun `I cannot get article by id with wrong id format`() { + withIntegrationApplication { + `Given I have article`(id = "65cda9f3-8991-4420-8d41-1da9da72c9bb") + `When I send a GET request`("/articles/abcd") `Then the response should be` BadRequest and { + `And the response should not be null`() + `And the response should contain`("$.invalidParams[0].name", "ID") + `And the response should contain`("$.invalidParams[0].reason", "must be UUID") + } + } + } + @Test fun `I can get versions of article by the id`() { withIntegrationApplication { @@ -95,7 +108,7 @@ class `Article routes` : BaseTest() { } @Test - @Tag("Validation") + @Tag("BadRequest") fun `I cannot get versions of article by the id with wrong id`() { withIntegrationApplication { `Given I have article`(id = "13e6091c-8fed-4600-b079-a97a6b7a9800") @@ -108,7 +121,7 @@ class `Article routes` : BaseTest() { } @Test - @Tag("Validation") + @Tag("BadRequest") fun `I cannot get versions of article by the id with wrong request`() { withIntegrationApplication { `Given I have article`(id = "13e6091c-8fed-4600-b079-a97a6b7a9800")