diff --git a/.idea/runConfigurations/Citizen_Tests.xml b/.idea/runConfigurations/Citizen_Tests.xml
new file mode 100644
index 0000000..eb19d1e
--- /dev/null
+++ b/.idea/runConfigurations/Citizen_Tests.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/Comment_Tests.xml b/.idea/runConfigurations/Comment_Tests.xml
new file mode 100644
index 0000000..6ae0bd4
--- /dev/null
+++ b/.idea/runConfigurations/Comment_Tests.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/kotlin/feature/ArticleSteps.kt b/src/test/kotlin/feature/ArticleSteps.kt
index f0b33e0..aa91800 100644
--- a/src/test/kotlin/feature/ArticleSteps.kt
+++ b/src/test/kotlin/feature/ArticleSteps.kt
@@ -9,7 +9,6 @@ import org.joda.time.DateTime
import org.koin.test.KoinTest
import org.koin.test.get
import java.util.*
-import java.util.concurrent.CompletionException
import fr.dcproject.entity.Article as ArticleEntity
import fr.dcproject.entity.Comment as CommentEntity
import fr.dcproject.entity.User as UserEntity
@@ -28,36 +27,11 @@ class ArticleSteps : En, KoinTest {
createArticle(extraData)
}
- Given("I have comment {string} on article {string}") { commentId: String, articleId: String ->
- var citizen = Citizen(
- name = CitizenI.Name("John", "Doe"),
- email = "john.doe@gmail.com",
- birthday = DateTime.now(),
- user = UserEntity(username = "john-doe", plainPassword = "azerty")
- )
-
- try {
- get().insertWithUser(citizen)
- } catch (e: CompletionException) {
- citizen = get().findByUsername("john-doe")!!
- }
-
- val article = ArticleEntity(
- id = UUID.fromString(articleId),
- title = "hello",
- content = "bla bla bla",
- description = "A super article",
- createdBy = citizen
- )
- get().upsert(article)
-
- val comment: CommentEntity = CommentEntity(
- id = UUID.fromString(commentId),
- createdBy = citizen,
- target = article,
- content = "hello"
- )
- get().comment(comment)
+ Given("I have comment created by {word} {word} on article {string}:") { firstName: String, lastName: String, articleId: String, extraData: DataTable? ->
+ commentArticle(articleId, firstName, lastName, extraData)
+ }
+ Given("I have comment created by {word} {word} on article {string}") { firstName: String, lastName: String, articleId: String ->
+ commentArticle(articleId, firstName, lastName)
}
}
@@ -94,4 +68,20 @@ class ArticleSteps : En, KoinTest {
)
get().upsert(article)
}
+
+ private fun commentArticle(articleId: String, firstName: String, lastName: String, extraData: DataTable? = null) {
+ val params = extraData?.asMap(String::class.java, String::class.java)
+
+ val article = get().findById(UUID.fromString(articleId)) ?: error("Article not exist")
+
+ 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(),
+ createdBy = citizen,
+ target = article,
+ content = params?.get("content") ?: "hello"
+ )
+ get().comment(comment)
+ }
}
\ No newline at end of file
diff --git a/src/test/resources/feature/comment.feature b/src/test/resources/feature/comment.feature
index 77d607d..f4fcc2e 100644
--- a/src/test/resources/feature/comment.feature
+++ b/src/test/resources/feature/comment.feature
@@ -1,7 +1,11 @@
+@comment
Feature: comment
Scenario: Can comment childrens
- 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 "/comments/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/children"
+ Given I have citizen John Dalton
+ And I am authenticated as John Dalton
+ And I have article
+ | id | 4c948e8f-eada-4e10-8d7d-7192affe1313 |
+ And I have comment created by John Dalton on article "4c948e8f-eada-4e10-8d7d-7192affe1313"
+ When I send a GET request to "/comments/4c948e8f-eada-4e10-8d7d-7192affe1313/children"
Then the response status code should be 200
\ No newline at end of file