Refactoring Vote Tests

This commit is contained in:
2020-03-17 01:11:04 +01:00
parent 8c7e5bdf9b
commit 0932da452b
4 changed files with 88 additions and 14 deletions

24
.idea/runConfigurations/Vote_Tests.xml generated Normal file
View File

@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Vote 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;@vote&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

@@ -73,7 +73,7 @@ class ArticleSteps : En, KoinTest {
get<ArticleRepository>().upsert(article) get<ArticleRepository>().upsert(article)
} }
private fun commentArticle(articleId: String, firstName: String, lastName: String, extraData: DataTable? = null) { private fun commentArticle(articleId: String, firstName: String, lastName: String, extraData: DataTable? = null, id: UUID? = null) {
val params = extraData?.asMap<String, String>(String::class.java, String::class.java) 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 article = get<ArticleRepository>().findById(UUID.fromString(articleId)) ?: error("Article not exist")
@@ -83,7 +83,7 @@ class ArticleSteps : En, KoinTest {
) ?: error("Citizen not exist") ) ?: error("Citizen not exist")
val comment: CommentEntity<ArticleRef> = CommentEntity( val comment: CommentEntity<ArticleRef> = CommentEntity(
id = params?.get("id")?.let { UUID.fromString(it) } ?: UUID.randomUUID(), id = id ?: params?.get("id")?.let { UUID.fromString(it) } ?: UUID.randomUUID(),
createdBy = citizen, createdBy = citizen,
target = article, target = article,
content = params?.get("content") ?: "hello" content = params?.get("content") ?: "hello"

View File

@@ -0,0 +1,33 @@
package feature
import fr.dcproject.entity.Vote
import fr.dcproject.utils.toUUID
import io.cucumber.java8.En
import org.koin.test.KoinTest
import org.koin.test.get
import java.util.*
import fr.dcproject.repository.Article as ArticleRepository
import fr.dcproject.repository.Citizen as CitizenRepository
import fr.dcproject.repository.VoteArticle as VoteRepository
class VoteSteps : En, KoinTest {
init {
Given("I have an vote {int} on article {string} created by {word} {word}") { note: Int, articleId: String, firstName: String, lastName: String ->
createVote(note, articleId, firstName, lastName)
}
Given("I have an vote {int} on article {string} created by {word} {word} with ID {string}") { note: Int, articleId: String, firstName: String, lastName: String, id: String ->
createVote(note, articleId, firstName, lastName, id)
}
}
private fun createVote(note: Int, articleId: String, firstName: String, lastName: String, id: String? = null) {
val vote = Vote(
id = id?.toUUID() ?: UUID.randomUUID(),
note = note,
target = get<ArticleRepository>().findById(articleId.toUUID()) ?: error("Article not exist"),
createdBy = get<CitizenRepository>().findByUsername("$firstName-$lastName".toLowerCase().replace(' ', '-')) ?: error("Citizen not exist")
)
get<VoteRepository>().vote(vote)
}
}

View File

@@ -1,8 +1,11 @@
@vote
Feature: vote Article Feature: vote Article
Scenario: Can Vote article Scenario: Can Vote article
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" Given I have citizen Thalès Milet
When I send a PUT request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/vote" with body: And I am authenticated as Thalès Milet
And I have article with ID "835c5101-ca39-4038-a4e6-da6ee62ca6d5"
When I send a PUT request to "/articles/835c5101-ca39-4038-a4e6-da6ee62ca6d5/vote" with body:
""" """
{ {
"note": 1 "note": 1
@@ -11,8 +14,10 @@ Feature: vote Article
Then the response status code should be 201 Then the response status code should be 201
Scenario: Can Vote constitution Scenario: Can Vote constitution
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" Given I have citizen Gregor Mendel
When I send a PUT request to "/constitutions/64b1f265-bfb3-332b-eef9-d00f63a3beaa/vote" with body: And I am authenticated as Gregor Mendel
And I have constitution with ID "76e79c89-efc1-492d-9e8f-dc9717363a11"
When I send a PUT request to "/constitutions/76e79c89-efc1-492d-9e8f-dc9717363a11/vote" with body:
""" """
{ {
"note": -1 "note": -1
@@ -21,8 +26,11 @@ Feature: vote Article
Then the response status code should be 201 Then the response status code should be 201
Scenario: Can get votes of current citizen Scenario: Can get votes of current citizen
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" Given I have citizen Carl Gauss with ID "c044823d-e778-4256-9016-b1334bf933d3"
When I send a GET request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/votes/articles" And I am authenticated as Carl Gauss
And I have article with ID "7c9286db-470d-448c-aab1-3f0b072213b1"
And I have an vote 1 on article "7c9286db-470d-448c-aab1-3f0b072213b1" created by Carl Gauss
When I send a GET request to "/citizens/c044823d-e778-4256-9016-b1334bf933d3/votes/articles"
Then the response status code should be 200 Then the response status code should be 200
And the response should contain object: And the response should contain object:
| current_page | 1 | | current_page | 1 |
@@ -31,16 +39,25 @@ Feature: vote Article
| result[0].note | 1 | | result[0].note | 1 |
Scenario: Can get votes of current citizen by target ids Scenario: Can get votes of current citizen by target ids
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" Given I have citizen Rosalind Franklin with ID "ab3269f0-877b-46b2-ae1a-e7e7d1c12132"
When I send a GET request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/votes?id=9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b&id=64b1f265-bfb3-332b-eef9-d00f63a3beaa" And I am authenticated as Rosalind Franklin
And I have article with ID "4d457f53-b937-4622-9542-d5f689d3716b"
And I have an vote 1 on article "4d457f53-b937-4622-9542-d5f689d3716b" created by Rosalind Franklin
And I have article with ID "117ef3e6-a740-4d04-9a4a-a800a5f274b4"
And I have an vote -1 on article "117ef3e6-a740-4d04-9a4a-a800a5f274b4" created by Rosalind Franklin
When I send a GET request to "/citizens/ab3269f0-877b-46b2-ae1a-e7e7d1c12132/votes?id=4d457f53-b937-4622-9542-d5f689d3716b&id=117ef3e6-a740-4d04-9a4a-a800a5f274b4"
Then the response status code should be 200 Then the response status code should be 200
And the response should contain object: And the response should contain object:
| [0].note | 1 | | [0].note | -1 |
| [1].note | 1 |
Scenario: Can vote a comment Scenario: Can vote a comment
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" Given I have citizen Antoine Lavoisier
And I have comment "ea5c9e87-c99e-4646-a381-2910219e077f" on article "cc9c624e-a27e-42de-af78-ae821c657a68" And I am authenticated as Antoine Lavoisier
When I send a PUT request to "/comments/ea5c9e87-c99e-4646-a381-2910219e077f/vote" with body: And I have article with ID "54428366-e71e-4961-876c-8a13df5e4b41"
And I have comment created by Antoine Lavoisier on article "54428366-e71e-4961-876c-8a13df5e4b41":
| id | e793eccc-456b-4450-a292-46d592229b74 |
When I send a PUT request to "/comments/e793eccc-456b-4450-a292-46d592229b74/vote" with body:
""" """
{ {
"note": -1 "note": -1