Refactoring Follows Tests
Add missing route GET /constitutions/{constitution}/follows
This commit is contained in:
@@ -27,6 +27,10 @@ class ArticleSteps : En, KoinTest {
|
||||
createArticle(extraData)
|
||||
}
|
||||
|
||||
Given("I have article with ID {string}") { id: String ->
|
||||
createArticle(id = UUID.fromString(id))
|
||||
}
|
||||
|
||||
Given("I have comment created by {word} {word} on article {string}:") { firstName: String, lastName: String, articleId: String, extraData: DataTable? ->
|
||||
commentArticle(articleId, firstName, lastName, extraData)
|
||||
}
|
||||
@@ -35,17 +39,17 @@ class ArticleSteps : En, KoinTest {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createArticle(extraData: DataTable? = null) {
|
||||
private fun createArticle(extraData: DataTable? = null, id: UUID? = null) {
|
||||
val params = extraData?.asMap<String, String>(String::class.java, String::class.java)
|
||||
val createdByUsername = params?.get("createdBy")
|
||||
val username = (createdByUsername ?: "username"+UUID.randomUUID().toString())
|
||||
val username = (createdByUsername ?: "username" + UUID.randomUUID().toString())
|
||||
.toLowerCase().replace(' ', '-')
|
||||
|
||||
val createdBy = if (createdByUsername != null) {
|
||||
get<CitizenRepository>().findByUsername(username) ?: error("Citizen not exist")
|
||||
} else {
|
||||
val first = "firstName"+UUID.randomUUID().toString()
|
||||
val last = "lastName"+UUID.randomUUID().toString()
|
||||
val first = "firstName" + UUID.randomUUID().toString()
|
||||
val last = "lastName" + UUID.randomUUID().toString()
|
||||
Citizen(
|
||||
birthday = DateTime.now(),
|
||||
name = CitizenI.Name(
|
||||
@@ -60,7 +64,7 @@ class ArticleSteps : En, KoinTest {
|
||||
}
|
||||
|
||||
val article = ArticleEntity(
|
||||
id = params?.get("id")?.toUUID() ?: UUID.randomUUID(),
|
||||
id = id ?: params?.get("id")?.toUUID() ?: UUID.randomUUID(),
|
||||
title = "hello",
|
||||
content = "bla bla bla",
|
||||
description = "A super article",
|
||||
@@ -74,7 +78,9 @@ class ArticleSteps : En, KoinTest {
|
||||
|
||||
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 citizen = get<CitizenRepository>().findByUsername(
|
||||
("$firstName-$lastName".toLowerCase()).toLowerCase().replace(' ', '-')
|
||||
) ?: error("Citizen not exist")
|
||||
|
||||
val comment: CommentEntity<ArticleRef> = CommentEntity(
|
||||
id = params?.get("id")?.let { UUID.fromString(it) } ?: UUID.randomUUID(),
|
||||
|
||||
@@ -9,11 +9,10 @@ import org.joda.time.DateTime
|
||||
import org.koin.test.KoinTest
|
||||
import org.koin.test.get
|
||||
import java.util.*
|
||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||
import fr.dcproject.entity.Comment as CommentEntity
|
||||
import fr.dcproject.entity.User as UserEntity
|
||||
import fr.dcproject.repository.Constitution as ConstitutionRepository
|
||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||
import fr.dcproject.repository.Constitution as ConstitutionRepository
|
||||
|
||||
class ConstitutionSteps : En, KoinTest {
|
||||
init {
|
||||
@@ -27,6 +26,10 @@ class ConstitutionSteps : En, KoinTest {
|
||||
createConstitution(extraData)
|
||||
}
|
||||
|
||||
Given("I have constitution with ID {string}") { id: String? ->
|
||||
createConstitution(id = UUID.fromString(id))
|
||||
}
|
||||
|
||||
Given("I have comment created by {word} {word} on constitution {string}:") { firstName: String, lastName: String, constitutionId: String, extraData: DataTable? ->
|
||||
commentConstitution(constitutionId, firstName, lastName, extraData)
|
||||
}
|
||||
@@ -35,7 +38,7 @@ class ConstitutionSteps : En, KoinTest {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createConstitution(extraData: DataTable? = null) {
|
||||
private fun createConstitution(extraData: DataTable? = null, id: UUID? = null) {
|
||||
val params = extraData?.asMap<String, String>(String::class.java, String::class.java)
|
||||
val createdByUsername = params?.get("createdBy")
|
||||
val username = (createdByUsername ?: "username"+UUID.randomUUID().toString())
|
||||
@@ -64,7 +67,7 @@ class ConstitutionSteps : En, KoinTest {
|
||||
)
|
||||
|
||||
val constitution = ConstitutionSimple<CitizenSimple, ConstitutionSimple.TitleSimple<ArticleRef>>(
|
||||
id = params?.get("id")?.toUUID() ?: UUID.randomUUID(),
|
||||
id = id ?: params?.get("id")?.toUUID() ?: UUID.randomUUID(),
|
||||
title = "hello",
|
||||
titles = mutableListOf(title1),
|
||||
anonymous = false,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package feature
|
||||
|
||||
import fr.dcproject.entity.ArticleRef
|
||||
import fr.dcproject.entity.ConstitutionRef
|
||||
import fr.dcproject.entity.Follow
|
||||
import fr.dcproject.utils.toUUID
|
||||
import io.cucumber.java8.En
|
||||
@@ -8,14 +9,21 @@ import org.koin.test.KoinTest
|
||||
import org.koin.test.get
|
||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||
import fr.dcproject.repository.FollowArticle as FollowArticleRepository
|
||||
import fr.dcproject.repository.FollowConstitution as FollowConstitutionRepository
|
||||
|
||||
class FollowSteps : En, KoinTest {
|
||||
init {
|
||||
Given("The citizen {word} {word} follow article {string}") { firstName: String, lastName: String, articleId: String ->
|
||||
Given("I have follow of {word} {word} on article {string}") { firstName: String, lastName: String, articleId: String ->
|
||||
val username = "$firstName-$lastName".toLowerCase()
|
||||
val citizen = get<CitizenRepository>().findByUsername(username) ?: error("Citizen not exist")
|
||||
val follow = Follow(createdBy = citizen, target = ArticleRef(articleId.toUUID()))
|
||||
get<FollowArticleRepository>().follow(follow)
|
||||
}
|
||||
Given("I have follow of {word} {word} on constitution {string}") { firstName: String, lastName: String, constitutionId: String ->
|
||||
val username = "$firstName-$lastName".toLowerCase()
|
||||
val citizen = get<CitizenRepository>().findByUsername(username) ?: error("Citizen not exist")
|
||||
val follow = Follow(createdBy = citizen, target = ConstitutionRef(constitutionId.toUUID()))
|
||||
get<FollowConstitutionRepository>().follow(follow)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user