Add Integration test for vote routes

This commit is contained in:
2021-02-24 00:16:54 +01:00
parent 9fb2262107
commit 7b4066b928
10 changed files with 198 additions and 34 deletions

View File

@@ -1,5 +1,6 @@
package integration package integration
import fr.dcproject.component.citizen.CitizenI.Name
import integration.steps.`And the response should contain` import integration.steps.`And the response should contain`
import integration.steps.`And the response should not be null` import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be` import integration.steps.`Then the response should be`
@@ -47,7 +48,7 @@ class `Comment articles routes` : BaseTest() {
withIntegrationApplication { withIntegrationApplication {
`Given I have citizen`("Enrico", "Fermi") `Given I have citizen`("Enrico", "Fermi")
`Given I have article`(id = "6166c078-ca97-4366-b0aa-2a5cd558c78a") `Given I have article`(id = "6166c078-ca97-4366-b0aa-2a5cd558c78a")
`Given I have comment on article`(article = "6166c078-ca97-4366-b0aa-2a5cd558c78a", createdByUsername = "enrico-fermi") `Given I have comment on article`(article = "6166c078-ca97-4366-b0aa-2a5cd558c78a", createdBy = Name("Enrico", "Fermi"))
`When I send a GET request`("/articles/6166c078-ca97-4366-b0aa-2a5cd558c78a/comments") { `When I send a GET request`("/articles/6166c078-ca97-4366-b0aa-2a5cd558c78a/comments") {
`authenticated as`("Enrico", "Fermi") `authenticated as`("Enrico", "Fermi")
} `Then the response should be` OK and { } `Then the response should be` OK and {
@@ -63,7 +64,7 @@ class `Comment articles routes` : BaseTest() {
withIntegrationApplication { withIntegrationApplication {
`Given I have citizen`("Pierre", "Curie") `Given I have citizen`("Pierre", "Curie")
`Given I have article`(id = "5e209f63-57ce-43ca-922a-273b0d62f567") `Given I have article`(id = "5e209f63-57ce-43ca-922a-273b0d62f567")
`Given I have comment on article`(article = "5e209f63-57ce-43ca-922a-273b0d62f567", createdByUsername = "pierre-curie") `Given I have comment on article`(article = "5e209f63-57ce-43ca-922a-273b0d62f567", createdBy = Name("Pierre", "Curie"))
`When I send a GET request`("/articles/5e209f63-57ce-43ca-922a-273b0d62f567/comments?sort=votes") { `When I send a GET request`("/articles/5e209f63-57ce-43ca-922a-273b0d62f567/comments?sort=votes") {
`authenticated as`("Pierre", "Curie") `authenticated as`("Pierre", "Curie")
} `Then the response should be` OK and { } `Then the response should be` OK and {
@@ -77,8 +78,8 @@ class `Comment articles routes` : BaseTest() {
fun `I can get comments on articles of the current citizen`() { fun `I can get comments on articles of the current citizen`() {
withIntegrationApplication { withIntegrationApplication {
`Given I have citizen`("Erwin", "Schrodinger", id = "292a20cc-4a60-489e-9866-a95d38ffaf47") `Given I have citizen`("Erwin", "Schrodinger", id = "292a20cc-4a60-489e-9866-a95d38ffaf47")
`Given I have article`(id = "17df7fb9-b388-4e20-ab19-29c29972da01", createdByUsername = "erwin-schrodinger") `Given I have article`(id = "17df7fb9-b388-4e20-ab19-29c29972da01", createdBy = Name("Erwin", "Schrodinger"))
`Given I have comment on article`(article = "17df7fb9-b388-4e20-ab19-29c29972da01", createdByUsername = "erwin-schrodinger") `Given I have comment on article`(article = "17df7fb9-b388-4e20-ab19-29c29972da01", createdBy = Name("Erwin", "Schrodinger"))
`When I send a GET request`("/citizens/292a20cc-4a60-489e-9866-a95d38ffaf47/comments/articles") { `When I send a GET request`("/citizens/292a20cc-4a60-489e-9866-a95d38ffaf47/comments/articles") {
} `Then the response should be` OK and { } `Then the response should be` OK and {
`And the response should not be null`() `And the response should not be null`()
@@ -94,7 +95,7 @@ class `Comment articles routes` : BaseTest() {
withIntegrationApplication { withIntegrationApplication {
`Given I have citizen`("Hubert", "Reeves") `Given I have citizen`("Hubert", "Reeves")
`Given I have article`(id = "bb05e4a3-55a1-4088-85e7-8d8c23be29b1") `Given I have article`(id = "bb05e4a3-55a1-4088-85e7-8d8c23be29b1")
`Given I have comment on article`(article = "bb05e4a3-55a1-4088-85e7-8d8c23be29b1", createdByUsername = "hubert-reeves", id = "fd30d20f-656c-42c6-8955-f61c04537464") `Given I have comment on article`(article = "bb05e4a3-55a1-4088-85e7-8d8c23be29b1", createdBy = Name("Hubert", "Reeves"), id = "fd30d20f-656c-42c6-8955-f61c04537464")
`When I send a PUT request`("/comments/fd30d20f-656c-42c6-8955-f61c04537464") { `When I send a PUT request`("/comments/fd30d20f-656c-42c6-8955-f61c04537464") {
`authenticated as`("Hubert", "Reeves") `authenticated as`("Hubert", "Reeves")
""" """
@@ -114,7 +115,7 @@ class `Comment articles routes` : BaseTest() {
`Given I have article`(id = "3897465b-19d2-43a0-86ea-1e29dbb11ec9") `Given I have article`(id = "3897465b-19d2-43a0-86ea-1e29dbb11ec9")
`Given I have comment on article`( `Given I have comment on article`(
article = "3897465b-19d2-43a0-86ea-1e29dbb11ec9", article = "3897465b-19d2-43a0-86ea-1e29dbb11ec9",
createdByUsername = "alfred-kastler", createdBy = Name("Alfred", "Kastler"),
id = "edd296a8-fc7a-4717-a2bb-9f035ceca3c2", id = "edd296a8-fc7a-4717-a2bb-9f035ceca3c2",
content = "Hello boy" content = "Hello boy"
) )

View File

@@ -1,5 +1,6 @@
package integration package integration
import fr.dcproject.component.citizen.CitizenI.Name
import integration.steps.`And the response should contain list` import integration.steps.`And the response should contain list`
import integration.steps.`And the response should contain` import integration.steps.`And the response should contain`
import integration.steps.`And the response should not be null` import integration.steps.`And the response should not be null`
@@ -43,8 +44,8 @@ class `Comment constitutions routes` : BaseTest() {
fun `I can get comments on constitutions of the current citizen`() { fun `I can get comments on constitutions of the current citizen`() {
withIntegrationApplication { withIntegrationApplication {
`Given I have citizen`("Charles", "Darwin", id = "46e0bda9-ca6a-4c65-a58b-7e7267a0bbc5") `Given I have citizen`("Charles", "Darwin", id = "46e0bda9-ca6a-4c65-a58b-7e7267a0bbc5")
`Given I have constitution`(id = "34ddd50a-da00-4a90-a869-08baa2a121be", createdByUsername = "charles-darwin") `Given I have constitution`(id = "34ddd50a-da00-4a90-a869-08baa2a121be", createdBy = Name("Charles", "Darwin"))
`Given I have comment on constitution`(constitution = "34ddd50a-da00-4a90-a869-08baa2a121be", createdByUsername = "charles-darwin") `Given I have comment on constitution`(constitution = "34ddd50a-da00-4a90-a869-08baa2a121be", createdBy = Name("Charles", "Darwin"))
`When I send a GET request`("/citizens/46e0bda9-ca6a-4c65-a58b-7e7267a0bbc5/comments/constitutions") { `When I send a GET request`("/citizens/46e0bda9-ca6a-4c65-a58b-7e7267a0bbc5/comments/constitutions") {
} `Then the response should be` OK and { } `Then the response should be` OK and {
`And the response should not be null`() `And the response should not be null`()

View File

@@ -51,7 +51,7 @@ class `Opinion routes` : BaseTest() {
withIntegrationApplication { withIntegrationApplication {
`Given I have citizen`("Isaac", "Newton", id = "2f414045-95d9-42ca-a3a9-8cdde52ad253") `Given I have citizen`("Isaac", "Newton", id = "2f414045-95d9-42ca-a3a9-8cdde52ad253")
`Given I have an opinion choice`("Opinion4", id = "0f4f1721-3136-44f1-9f31-1459f3317b15") `Given I have an opinion choice`("Opinion4", id = "0f4f1721-3136-44f1-9f31-1459f3317b15")
`Given I have article`(id = "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b", createdByUsername = "isaac-newton") `Given I have article`(id = "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b", createdBy = Name("Isaac", "Newton"))
`When I send a PUT request`("/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/opinions") { `When I send a PUT request`("/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/opinions") {
`authenticated as`("Isaac", "Newton") `authenticated as`("Isaac", "Newton")
""" """

View File

@@ -0,0 +1,114 @@
package integration
import fr.dcproject.component.citizen.CitizenI.Name
import integration.steps.`And the response should contain`
import integration.steps.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a PUT request`
import integration.steps.and
import integration.steps.given.`Given I have article`
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have comment on article`
import integration.steps.given.`Given I have constitution`
import integration.steps.given.`Given I have vote +1 on article`
import integration.steps.given.`Given I have vote -1 on article`
import integration.steps.given.`authenticated as`
import io.ktor.http.HttpStatusCode.Companion.Created
import io.ktor.http.HttpStatusCode.Companion.OK
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Tags
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Tags(Tag("integration"), Tag("vote"))
class `Vote routes` : BaseTest() {
@Test
fun `I can vote article`() {
withIntegrationApplication {
`Given I have citizen`("Thalès", "Milet")
`Given I have article`(id = "835c5101-ca39-4038-a4e6-da6ee62ca6d5")
`When I send a PUT request`("/articles/835c5101-ca39-4038-a4e6-da6ee62ca6d5/vote") {
`authenticated as`("Thalès", "Milet")
"""
{
"note": 1
}
"""
} `Then the response should be` Created
}
}
@Test
fun `I can vote constitution`() {
withIntegrationApplication {
`Given I have citizen`("Gregor", "Mendel")
`Given I have constitution`(id = "76e79c89-efc1-492d-9e8f-dc9717363a11")
`When I send a PUT request`("/constitutions/76e79c89-efc1-492d-9e8f-dc9717363a11/vote") {
`authenticated as`("Gregor", "Mendel")
"""
{
"note": 1
}
"""
} `Then the response should be` Created
}
}
@Test
fun `I can get votes of current citizen`() {
withIntegrationApplication {
`Given I have citizen`("Carl", "Gauss", id = "c044823d-e778-4256-9016-b1334bf933d3")
`Given I have article`("7c9286db-470d-448c-aab1-3f0b072213b1")
`Given I have vote +1 on article`("7c9286db-470d-448c-aab1-3f0b072213b1", Name("Carl", "Gauss"))
`When I send a GET request`("/citizens/c044823d-e778-4256-9016-b1334bf933d3/votes/articles") {
`authenticated as`("Carl", "Gauss")
} `Then the response should be` OK and {
`And the response should contain`("$.current_page", 1)
`And the response should contain`("$.limit", 50)
`And the response should contain`("$.total", 1)
`And the response should contain`("$.result[0].note", 1)
}
}
}
@Test
fun `I can get votes of current citizen by target ids`() {
withIntegrationApplication {
`Given I have citizen`("Rosalind", "Franklin", id = "ab3269f0-877b-46b2-ae1a-e7e7d1c12132")
`Given I have article`("4d457f53-b937-4622-9542-d5f689d3716b")
`Given I have vote +1 on article`("4d457f53-b937-4622-9542-d5f689d3716b", Name("Rosalind", "Franklin"))
`Given I have article`("117ef3e6-a740-4d04-9a4a-a800a5f274b4")
`Given I have vote -1 on article`("117ef3e6-a740-4d04-9a4a-a800a5f274b4", Name("Rosalind", "Franklin"))
`When I send a GET request`("/citizens/ab3269f0-877b-46b2-ae1a-e7e7d1c12132/votes?id=4d457f53-b937-4622-9542-d5f689d3716b&id=117ef3e6-a740-4d04-9a4a-a800a5f274b4") {
`authenticated as`("Rosalind", "Franklin")
} `Then the response should be` OK and {
`And the response should contain`("$[0].note", -1)
`And the response should contain`("$[1].note", 1)
}
}
}
@Test
fun `I can vote a comment`() {
withIntegrationApplication {
`Given I have citizen`("Antoine", "Lavoisier", id = "ab3269f0-877b-46b2-ae1a-e7e7d1c12132")
`Given I have article`("54428366-e71e-4961-876c-8a13df5e4b41")
`Given I have comment on article`(
createdBy = Name("Antoine", "Lavoisier"),
article = "54428366-e71e-4961-876c-8a13df5e4b41",
id = "e793eccc-456b-4450-a292-46d592229b74",
)
`When I send a PUT request`("/comments/e793eccc-456b-4450-a292-46d592229b74/vote") {
`authenticated as`("Antoine", "Lavoisier")
"""
{
"note": -1
}
"""
} `Then the response should be` Created and {
`And the response should contain`("$.down", 1)
}
}
}
}

View File

@@ -5,6 +5,7 @@ import fr.dcproject.common.utils.toUUID
import fr.dcproject.component.article.ArticleForUpdate import fr.dcproject.component.article.ArticleForUpdate
import fr.dcproject.component.article.ArticleForView import fr.dcproject.component.article.ArticleForView
import fr.dcproject.component.article.ArticleRepository import fr.dcproject.component.article.ArticleRepository
import fr.dcproject.component.citizen.CitizenI.Name
import fr.dcproject.component.workgroup.WorkgroupRef import fr.dcproject.component.workgroup.WorkgroupRef
import io.ktor.server.testing.TestApplicationEngine import io.ktor.server.testing.TestApplicationEngine
import org.koin.core.context.GlobalContext import org.koin.core.context.GlobalContext
@@ -13,9 +14,9 @@ import java.util.UUID
fun TestApplicationEngine.`Given I have article`( fun TestApplicationEngine.`Given I have article`(
id: String? = null, id: String? = null,
workgroup: WorkgroupRef? = null, workgroup: WorkgroupRef? = null,
createdByUsername: String? = null createdBy: Name? = null
) { ) {
createArticle(id?.toUUID(), workgroup, createdByUsername) createArticle(id?.toUUID(), workgroup, createdBy)
} }
fun TestApplicationEngine.`Given I have articles`( fun TestApplicationEngine.`Given I have articles`(
@@ -34,18 +35,18 @@ fun TestApplicationEngine.`Given I have article created by workgroup`(
fun createArticle( fun createArticle(
id: UUID? = null, id: UUID? = null,
workgroup: WorkgroupRef? = null, workgroup: WorkgroupRef? = null,
createdByUsername: String? = null createdBy: Name? = null
): ArticleForView { ): ArticleForView {
val articleRepository: ArticleRepository by lazy { GlobalContext.get().koin.get() } val articleRepository: ArticleRepository by lazy { GlobalContext.get().koin.get() }
val createdBy = createCitizen(createdByUsername) val citizen = createCitizen(createdBy)
val article = ArticleForUpdate( val article = ArticleForUpdate(
id = id ?: UUID.randomUUID(), id = id ?: UUID.randomUUID(),
title = LoremIpsum().getTitle(3), title = LoremIpsum().getTitle(3),
content = LoremIpsum().getParagraphs(1, 2), content = LoremIpsum().getParagraphs(1, 2),
description = LoremIpsum().getParagraphs(1, 2), description = LoremIpsum().getParagraphs(1, 2),
createdBy = createdBy, createdBy = citizen,
workgroup = workgroup, workgroup = workgroup,
versionId = UUID.randomUUID() versionId = UUID.randomUUID()
) )

View File

@@ -36,17 +36,15 @@ fun TestApplicationEngine.`Given I have citizen`(
return repo.insertWithUser(citizen)?.also { callback(it) } return repo.insertWithUser(citizen)?.also { callback(it) }
} }
fun createCitizen(createdByUsername: String? = null): Citizen { fun createCitizen(createdBy: CitizenI.Name? = null): Citizen {
val citizenRepository: CitizenRepository by lazy { GlobalContext.get().koin.get() } val citizenRepository: CitizenRepository by lazy { GlobalContext.get().koin.get() }
val username = (createdByUsername ?: "username" + UUID.randomUUID().toString()) return if (createdBy != null) {
.toLowerCase().replace(' ', '-') citizenRepository.findByName(createdBy) ?: error("Citizen not exist")
return if (createdByUsername != null) {
citizenRepository.findByUsername(createdByUsername) ?: error("Citizen not exist")
} else { } else {
val first = "firstName" + UUID.randomUUID().toString() val first = "firstName" + UUID.randomUUID().toString()
val last = "lastName" + UUID.randomUUID().toString() val last = "lastName" + UUID.randomUUID().toString()
val username = ("username" + UUID.randomUUID().toString())
CitizenForCreate( CitizenForCreate(
birthday = DateTime.now(), birthday = DateTime.now(),
name = CitizenI.Name( name = CitizenI.Name(

View File

@@ -5,6 +5,7 @@ import fr.dcproject.common.entity.TargetI
import fr.dcproject.common.utils.toUUID import fr.dcproject.common.utils.toUUID
import fr.dcproject.component.article.ArticleRef import fr.dcproject.component.article.ArticleRef
import fr.dcproject.component.article.ArticleRepository import fr.dcproject.component.article.ArticleRepository
import fr.dcproject.component.citizen.CitizenI.Name
import fr.dcproject.component.comment.generic.CommentForUpdate import fr.dcproject.component.comment.generic.CommentForUpdate
import fr.dcproject.component.comment.generic.CommentRepository import fr.dcproject.component.comment.generic.CommentRepository
import fr.dcproject.component.constitution.ConstitutionRef import fr.dcproject.component.constitution.ConstitutionRef
@@ -16,10 +17,10 @@ import java.util.UUID
fun TestApplicationEngine.`Given I have comment on article`( fun TestApplicationEngine.`Given I have comment on article`(
id: String? = null, id: String? = null,
article: String? = null, article: String? = null,
createdByUsername: String? = null, createdBy: Name? = null,
content: String? = null, content: String? = null,
) { ) {
createComment(id?.toUUID(), ArticleRef(article?.toUUID()), createdByUsername, content) createComment(id?.toUUID(), ArticleRef(article?.toUUID()), createdBy, content)
} }
fun TestApplicationEngine.`Given I have comments on article`( fun TestApplicationEngine.`Given I have comments on article`(
@@ -34,14 +35,14 @@ fun TestApplicationEngine.`Given I have comments on article`(
fun createComment( fun createComment(
id: UUID? = null, id: UUID? = null,
article: ArticleRef? = null, article: ArticleRef? = null,
createdByUsername: String? = null, createdBy: Name? = null,
content: String? = null content: String? = null
) { ) {
val articleRepository: ArticleRepository by lazy { GlobalContext.get().koin.get() } val articleRepository: ArticleRepository by lazy { GlobalContext.get().koin.get() }
createCommentOnTarget( createCommentOnTarget(
id, id,
article?.id?.let { articleRepository.findById(article.id) } ?: createArticle(article?.id), article?.id?.let { articleRepository.findById(article.id) } ?: createArticle(article?.id),
createdByUsername, createdBy,
content content
) )
} }
@@ -49,23 +50,23 @@ fun createComment(
fun TestApplicationEngine.`Given I have comment on constitution`( fun TestApplicationEngine.`Given I have comment on constitution`(
id: String? = null, id: String? = null,
constitution: String? = null, constitution: String? = null,
createdByUsername: String? = null, createdBy: Name? = null,
content: String? = null, content: String? = null,
) { ) {
createComment(id?.toUUID(), ConstitutionRef(constitution?.toUUID()), createdByUsername, content) createComment(id?.toUUID(), ConstitutionRef(constitution?.toUUID()), createdBy, content)
} }
fun createComment( fun createComment(
id: UUID? = null, id: UUID? = null,
constitution: ConstitutionRef? = null, constitution: ConstitutionRef? = null,
createdByUsername: String? = null, createdBy: Name? = null,
content: String? = null content: String? = null
) { ) {
val constitutionRepository: ConstitutionRepository by lazy { GlobalContext.get().koin.get() } val constitutionRepository: ConstitutionRepository by lazy { GlobalContext.get().koin.get() }
createCommentOnTarget( createCommentOnTarget(
id, id,
constitution?.id?.let { constitutionRepository.findById(constitution.id) } ?: createConstitution(constitution?.id), constitution?.id?.let { constitutionRepository.findById(constitution.id) } ?: createConstitution(constitution?.id),
createdByUsername, createdBy,
content content
) )
} }
@@ -73,11 +74,11 @@ fun createComment(
fun createCommentOnTarget( fun createCommentOnTarget(
id: UUID? = null, id: UUID? = null,
target: TargetI, target: TargetI,
createdByUsername: String? = null, createdBy: Name? = null,
content: String? = null content: String? = null
) { ) {
val commentRepository: CommentRepository by lazy { GlobalContext.get().koin.get() } val commentRepository: CommentRepository by lazy { GlobalContext.get().koin.get() }
val createdBy = createCitizen(createdByUsername) val createdBy = createCitizen(createdBy)
val comment = CommentForUpdate( val comment = CommentForUpdate(
id = id ?: UUID.randomUUID(), id = id ?: UUID.randomUUID(),
createdBy = createdBy, createdBy = createdBy,

View File

@@ -3,6 +3,7 @@ package integration.steps.given
import com.thedeanda.lorem.LoremIpsum import com.thedeanda.lorem.LoremIpsum
import fr.dcproject.common.utils.toUUID import fr.dcproject.common.utils.toUUID
import fr.dcproject.component.article.ArticleRef import fr.dcproject.component.article.ArticleRef
import fr.dcproject.component.citizen.CitizenI.Name
import fr.dcproject.component.citizen.CitizenWithUserI import fr.dcproject.component.citizen.CitizenWithUserI
import fr.dcproject.component.constitution.Constitution import fr.dcproject.component.constitution.Constitution
import fr.dcproject.component.constitution.ConstitutionRepository import fr.dcproject.component.constitution.ConstitutionRepository
@@ -15,9 +16,9 @@ import java.util.UUID
fun TestApplicationEngine.`Given I have constitution`( fun TestApplicationEngine.`Given I have constitution`(
id: String? = null, id: String? = null,
titles: List<TitleSimple<ArticleRef>>? = null, titles: List<TitleSimple<ArticleRef>>? = null,
createdByUsername: String? = null createdBy: Name? = null
) { ) {
createConstitution(id?.toUUID(), titles, createdByUsername) createConstitution(id?.toUUID(), titles, createdBy)
} }
fun TestApplicationEngine.`Given I have constitutions`( fun TestApplicationEngine.`Given I have constitutions`(
@@ -41,11 +42,11 @@ fun createTitle(): TitleSimple<ArticleRef> {
fun createConstitution( fun createConstitution(
id: UUID? = null, id: UUID? = null,
titles: List<TitleSimple<ArticleRef>>? = null, titles: List<TitleSimple<ArticleRef>>? = null,
createdByUsername: String? = null createdBy: Name? = null
): Constitution { ): Constitution {
val constitutionRepository: ConstitutionRepository by lazy { GlobalContext.get().koin.get() } val constitutionRepository: ConstitutionRepository by lazy { GlobalContext.get().koin.get() }
val createdBy: CitizenWithUserI = createCitizen(createdByUsername) val createdBy: CitizenWithUserI = createCitizen(createdBy)
val constitution = ConstitutionSimple( val constitution = ConstitutionSimple(
id = id ?: UUID.randomUUID(), id = id ?: UUID.randomUUID(),

View File

@@ -0,0 +1,46 @@
package integration.steps.given
import fr.dcproject.common.utils.toUUID
import fr.dcproject.component.article.ArticleRepository
import fr.dcproject.component.citizen.CitizenI.Name
import fr.dcproject.component.citizen.CitizenRepository
import fr.dcproject.component.vote.VoteArticleRepository
import fr.dcproject.component.vote.entity.VoteAggregation
import fr.dcproject.component.vote.entity.VoteForUpdate
import io.ktor.server.testing.TestApplicationEngine
import org.koin.core.context.GlobalContext
import java.util.UUID
fun TestApplicationEngine.`Given I have vote +1 on article`(
article: String,
name: Name,
id: String? = null,
) {
createVote(article, name, 1, id?.toUUID())
}
fun TestApplicationEngine.`Given I have vote -1 on article`(
article: String,
name: Name,
id: String? = null,
) {
createVote(article, name, -1, id?.toUUID())
}
fun createVote(
article: String,
name: Name,
note: Int,
id: UUID? = null,
): VoteAggregation {
val voteArticleRepository: VoteArticleRepository by lazy { GlobalContext.get().koin.get() }
val articleRepository: ArticleRepository by lazy { GlobalContext.get().koin.get() }
val citizenRepository: CitizenRepository by lazy { GlobalContext.get().koin.get() }
val vote = VoteForUpdate(
id = id ?: UUID.randomUUID(),
note = note,
target = articleRepository.findById(article.toUUID()) ?: error("Article not exist"),
createdBy = citizenRepository.findByName(name) ?: error("Citizen not exist")
)
return voteArticleRepository.vote(vote)
}

View File

@@ -1,4 +1,5 @@
@vote @vote
@disable
Feature: vote Article Feature: vote Article
Scenario: Can Vote article Scenario: Can Vote article