move createCitizen of Integration test
This commit is contained in:
@@ -3,13 +3,8 @@ package integration.steps.given
|
|||||||
import fr.dcproject.common.utils.toUUID
|
import fr.dcproject.common.utils.toUUID
|
||||||
import fr.dcproject.component.article.ArticleForUpdate
|
import fr.dcproject.component.article.ArticleForUpdate
|
||||||
import fr.dcproject.component.article.ArticleRepository
|
import fr.dcproject.component.article.ArticleRepository
|
||||||
import fr.dcproject.component.auth.UserForCreate
|
|
||||||
import fr.dcproject.component.citizen.CitizenForCreate
|
|
||||||
import fr.dcproject.component.citizen.CitizenI
|
|
||||||
import fr.dcproject.component.citizen.CitizenRepository
|
|
||||||
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.joda.time.DateTime
|
|
||||||
import org.koin.core.context.GlobalContext
|
import org.koin.core.context.GlobalContext
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@@ -34,34 +29,14 @@ fun TestApplicationEngine.`Given I have article created by workgroup`(
|
|||||||
createArticle(workgroup = WorkgroupRef(workgroupId.toUUID()))
|
createArticle(workgroup = WorkgroupRef(workgroupId.toUUID()))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createArticle(
|
fun createArticle(
|
||||||
id: UUID? = null,
|
id: UUID? = null,
|
||||||
workgroup: WorkgroupRef? = null,
|
workgroup: WorkgroupRef? = null,
|
||||||
createdByUsername: String? = null
|
createdByUsername: String? = null
|
||||||
) {
|
) {
|
||||||
val username = (createdByUsername ?: "username" + UUID.randomUUID().toString())
|
|
||||||
.toLowerCase().replace(' ', '-')
|
|
||||||
|
|
||||||
val citizenRepository: CitizenRepository by lazy<CitizenRepository> { GlobalContext.get().koin.get() }
|
|
||||||
val articleRepository: ArticleRepository by lazy<ArticleRepository> { GlobalContext.get().koin.get() }
|
val articleRepository: ArticleRepository by lazy<ArticleRepository> { GlobalContext.get().koin.get() }
|
||||||
|
|
||||||
val createdBy = if (createdByUsername != null) {
|
val createdBy = createCitizen(createdByUsername)
|
||||||
citizenRepository.findByUsername(username) ?: error("Citizen not exist")
|
|
||||||
} else {
|
|
||||||
val first = "firstName" + UUID.randomUUID().toString()
|
|
||||||
val last = "lastName" + UUID.randomUUID().toString()
|
|
||||||
CitizenForCreate(
|
|
||||||
birthday = DateTime.now(),
|
|
||||||
name = CitizenI.Name(
|
|
||||||
first,
|
|
||||||
last
|
|
||||||
),
|
|
||||||
email = "$first@fakeemail.com",
|
|
||||||
user = UserForCreate(username = username, password = "azerty")
|
|
||||||
).let {
|
|
||||||
citizenRepository.insertWithUser(it) ?: error("Unable to create User")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val article = ArticleForUpdate(
|
val article = ArticleForUpdate(
|
||||||
id = id ?: UUID.randomUUID(),
|
id = id ?: UUID.randomUUID(),
|
||||||
|
|||||||
@@ -34,3 +34,28 @@ fun TestApplicationEngine.`Given I have citizen`(
|
|||||||
|
|
||||||
return repo.insertWithUser(citizen)
|
return repo.insertWithUser(citizen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createCitizen(createdByUsername: String? = null): Citizen {
|
||||||
|
val citizenRepository: CitizenRepository by lazy<CitizenRepository> { GlobalContext.get().koin.get() }
|
||||||
|
|
||||||
|
val username = (createdByUsername ?: "username" + UUID.randomUUID().toString())
|
||||||
|
.toLowerCase().replace(' ', '-')
|
||||||
|
|
||||||
|
return if (createdByUsername != null) {
|
||||||
|
citizenRepository.findByUsername(createdByUsername) ?: error("Citizen not exist")
|
||||||
|
} else {
|
||||||
|
val first = "firstName" + UUID.randomUUID().toString()
|
||||||
|
val last = "lastName" + UUID.randomUUID().toString()
|
||||||
|
CitizenForCreate(
|
||||||
|
birthday = DateTime.now(),
|
||||||
|
name = CitizenI.Name(
|
||||||
|
first,
|
||||||
|
last
|
||||||
|
),
|
||||||
|
email = "$first@fakeemail.com",
|
||||||
|
user = UserForCreate(username = username, password = "azerty")
|
||||||
|
).let {
|
||||||
|
citizenRepository.insertWithUser(it) ?: error("Unable to create User")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@article
|
@article
|
||||||
|
@disable
|
||||||
Feature: articles routes
|
Feature: articles routes
|
||||||
|
|
||||||
Scenario: The route for get articles must response a 200
|
Scenario: The route for get articles must response a 200
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@auth
|
@auth
|
||||||
|
@disable
|
||||||
Feature: Auth routes
|
Feature: Auth routes
|
||||||
|
|
||||||
Scenario: I can resiter
|
Scenario: I can resiter
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@citizen
|
@citizen
|
||||||
|
@disable
|
||||||
Feature: citizens routes
|
Feature: citizens routes
|
||||||
|
|
||||||
Scenario: I can get Citizens informations
|
Scenario: I can get Citizens informations
|
||||||
|
|||||||
Reference in New Issue
Block a user