Refactoring Comment Tests

This commit is contained in:
2020-03-16 15:02:43 +01:00
parent 561905f7ab
commit 74503c9d3a
4 changed files with 76 additions and 34 deletions

View File

@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Citizen Tests" type="JUnit" factoryName="JUnit" show_console_on_std_err="true">
<output_file path="$PROJECT_DIR$/var/log/test/out.log" is_save="true" />
<module name="dcproject.test" />
<useClassPathOnly />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="RunCucumberTest" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea -Dcucumber.filter.tags=&quot;@citizen&quot;" />
<option name="PARAMETERS" value="" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="wholeProject" />
</option>
<envs>
<env name="SEND_GRID_KEY" value="$SEND_GRID_KEY$" />
</envs>
<dir value="$PROJECT_DIR$" />
<tag value="!online" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Comment Tests" type="JUnit" factoryName="JUnit" show_console_on_std_err="true">
<output_file path="$PROJECT_DIR$/var/log/test/out.log" is_save="true" />
<module name="dcproject.test" />
<useClassPathOnly />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="RunCucumberTest" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea -Dcucumber.filter.tags=&quot;@comment&quot;" />
<option name="PARAMETERS" value="" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="wholeProject" />
</option>
<envs>
<env name="SEND_GRID_KEY" value="$SEND_GRID_KEY$" />
</envs>
<dir value="$PROJECT_DIR$" />
<tag value="!online" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@@ -9,7 +9,6 @@ import org.joda.time.DateTime
import org.koin.test.KoinTest import org.koin.test.KoinTest
import org.koin.test.get import org.koin.test.get
import java.util.* import java.util.*
import java.util.concurrent.CompletionException
import fr.dcproject.entity.Article as ArticleEntity import fr.dcproject.entity.Article as ArticleEntity
import fr.dcproject.entity.Comment as CommentEntity import fr.dcproject.entity.Comment as CommentEntity
import fr.dcproject.entity.User as UserEntity import fr.dcproject.entity.User as UserEntity
@@ -28,36 +27,11 @@ class ArticleSteps : En, KoinTest {
createArticle(extraData) createArticle(extraData)
} }
Given("I have comment {string} on article {string}") { commentId: String, articleId: String -> Given("I have comment created by {word} {word} on article {string}:") { firstName: String, lastName: String, articleId: String, extraData: DataTable? ->
var citizen = Citizen( commentArticle(articleId, firstName, lastName, extraData)
name = CitizenI.Name("John", "Doe"),
email = "john.doe@gmail.com",
birthday = DateTime.now(),
user = UserEntity(username = "john-doe", plainPassword = "azerty")
)
try {
get<CitizenRepository>().insertWithUser(citizen)
} catch (e: CompletionException) {
citizen = get<CitizenRepository>().findByUsername("john-doe")!!
} }
Given("I have comment created by {word} {word} on article {string}") { firstName: String, lastName: String, articleId: String ->
val article = ArticleEntity( commentArticle(articleId, firstName, lastName)
id = UUID.fromString(articleId),
title = "hello",
content = "bla bla bla",
description = "A super article",
createdBy = citizen
)
get<ArticleRepository>().upsert(article)
val comment: CommentEntity<ArticleRef> = CommentEntity(
id = UUID.fromString(commentId),
createdBy = citizen,
target = article,
content = "hello"
)
get<CommentArticle>().comment(comment)
} }
} }
@@ -94,4 +68,20 @@ class ArticleSteps : En, KoinTest {
) )
get<ArticleRepository>().upsert(article) get<ArticleRepository>().upsert(article)
} }
private fun commentArticle(articleId: String, firstName: String, lastName: String, extraData: DataTable? = null) {
val params = extraData?.asMap<String, String>(String::class.java, String::class.java)
val article = get<ArticleRepository>().findById(UUID.fromString(articleId)) ?: error("Article not exist")
val citizen = get<CitizenRepository>().findByUsername(("$firstName-$lastName".toLowerCase()).toLowerCase().replace(' ', '-')) ?: error("Citizen not exist")
val comment: CommentEntity<ArticleRef> = CommentEntity(
id = params?.get("commentId")?.let { UUID.fromString(it) } ?: UUID.randomUUID(),
createdBy = citizen,
target = article,
content = params?.get("content") ?: "hello"
)
get<CommentArticle>().comment(comment)
}
} }

View File

@@ -1,7 +1,11 @@
@comment
Feature: comment Feature: comment
Scenario: Can comment childrens Scenario: Can comment childrens
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" Given I have citizen John Dalton
And I have article with id "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b" And I am authenticated as John Dalton
When I send a GET request to "/comments/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/children" 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 Then the response status code should be 200