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

@@ -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)
}