From bbe54c31159551ffe369d898102a53d9ac661c92 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Mon, 16 Mar 2020 20:27:20 +0100 Subject: [PATCH] Refactoring CommentArticle Tests --- src/test/kotlin/feature/ArticleSteps.kt | 4 +- .../resources/feature/commentArticle.feature | 61 ++++++++++++++----- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/test/kotlin/feature/ArticleSteps.kt b/src/test/kotlin/feature/ArticleSteps.kt index aa91800..cf3b539 100644 --- a/src/test/kotlin/feature/ArticleSteps.kt +++ b/src/test/kotlin/feature/ArticleSteps.kt @@ -38,7 +38,7 @@ class ArticleSteps : En, KoinTest { private fun createArticle(extraData: DataTable? = null) { val params = extraData?.asMap(String::class.java, String::class.java) val createdByUsername = params?.get("createdBy") - val username = (createdByUsername ?: UUID.randomUUID().toString()) + val username = (createdByUsername ?: "username"+UUID.randomUUID().toString()) .toLowerCase().replace(' ', '-') val createdBy = if (createdByUsername != null) { @@ -77,7 +77,7 @@ class ArticleSteps : En, KoinTest { val citizen = get().findByUsername(("$firstName-$lastName".toLowerCase()).toLowerCase().replace(' ', '-')) ?: error("Citizen not exist") val comment: CommentEntity = CommentEntity( - id = params?.get("commentId")?.let { UUID.fromString(it) } ?: UUID.randomUUID(), + id = params?.get("id")?.let { UUID.fromString(it) } ?: UUID.randomUUID(), createdBy = citizen, target = article, content = params?.get("content") ?: "hello" diff --git a/src/test/resources/feature/commentArticle.feature b/src/test/resources/feature/commentArticle.feature index 7016ed1..5a1ead1 100644 --- a/src/test/resources/feature/commentArticle.feature +++ b/src/test/resources/feature/commentArticle.feature @@ -1,9 +1,12 @@ +@comment Feature: comment Article Scenario: Can comment an article - Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" - And I have article with id "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b" - When I send a POST request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/comments" with body: + Given I have citizen Michael Faraday + And I am authenticated as Michael Faraday + And I have article + | id | aa16c635-28da-46f0-9a89-934eef88c7ca | + When I send a POST request to "/articles/aa16c635-28da-46f0-9a89-934eef88c7ca/comments" with body: """ { "content": "Hello mister" @@ -11,32 +14,52 @@ Feature: comment Article """ Then the response status code should be 201 + # TODO add more comment on article Scenario: Can get all comment on article - Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" - And I have article with id "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b" - When I send a GET request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/comments" + Given I have citizen Enrico Fermi + And I am authenticated as Enrico Fermi + And I have article + | id | 6166c078-ca97-4366-b0aa-2a5cd558c78a | + And I have comment created by Enrico Fermi on article "6166c078-ca97-4366-b0aa-2a5cd558c78a" + When I send a GET request to "/articles/6166c078-ca97-4366-b0aa-2a5cd558c78a/comments" Then the response status code should be 200 + # TODO add votes Scenario: Can get all comment on article sorted by votes - Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" - And I have article with id "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b" - When I send a GET request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/comments?sort=votes" + Given I have citizen Pierre Curie + And I am authenticated as Pierre Curie + And I have article + | id | 5e209f63-57ce-43ca-922a-273b0d62f567 | + And I have comment created by Enrico Fermi on article "5e209f63-57ce-43ca-922a-273b0d62f567" + When I send a GET request to "/articles/5e209f63-57ce-43ca-922a-273b0d62f567/comments?sort=votes" Then the response status code should be 200 And the response should contain object: - | result[1].votes.up | 1 | + | $.result[0].votes.up | 0 | Scenario: Can get comments on articles of the current citizen - Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" - And I have article with id "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b" - When I send a GET request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/comments/articles" + Given I have citizen Erwin Schrodinger with ID "292a20cc-4a60-489e-9866-a95d38ffaf47" + And I have article + | id | 17df7fb9-b388-4e20-ab19-29c29972da01 | + | createdBy | Erwin Schrodinger | + And I have comment created by Erwin Schrodinger on article "17df7fb9-b388-4e20-ab19-29c29972da01" + When I send a GET request to "/citizens/292a20cc-4a60-489e-9866-a95d38ffaf47/comments/articles" Then the response status code should be 200 And the response should contain object: | current_page | 1 | | limit | 50 | + And the Response should contain: + """ + 292a20cc-4a60-489e-9866-a95d38ffaf47 + """ Scenario: Can edit a comment - Given I am authenticated as username 3 with id "92877af7-0a45-fd6a-2ed7-fe81e1236b78" - When I send a PUT request to "/comments/2f01c257-cf20-3466-fb10-a3b8eff12a97" with body: + Given I have citizen Hubert Reeves + And I have article + | id | bb05e4a3-55a1-4088-85e7-8d8c23be29b1 | + And I am authenticated as Hubert Reeves + And I have comment created by Hubert Reeves on article "bb05e4a3-55a1-4088-85e7-8d8c23be29b1": + | id | fd30d20f-656c-42c6-8955-f61c04537464 | + When I send a PUT request to "/comments/fd30d20f-656c-42c6-8955-f61c04537464" with body: """ Hello boy """ @@ -45,7 +68,13 @@ Feature: comment Article | content | Hello boy | Scenario: Can get comment by its ID - When I send a GET request to "/comments/2f01c257-cf20-3466-fb10-a3b8eff12a97" + Given I have citizen Alfred Kastler + And I have article + | id | 3897465b-19d2-43a0-86ea-1e29dbb11ec9 | + And I have comment created by Alfred Kastler on article "3897465b-19d2-43a0-86ea-1e29dbb11ec9": + | id | edd296a8-fc7a-4717-a2bb-9f035ceca3c2 | + | content | Hello boy | + When I send a GET request to "/comments/edd296a8-fc7a-4717-a2bb-9f035ceca3c2" Then the response status code should be 200 And the JSON should contain: | content | Hello boy |