Minor refactoring of cucumber steps
This commit is contained in:
@@ -5,7 +5,6 @@ import fr.dcproject.JwtConfig
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.entity.CitizenI
|
||||
import fr.dcproject.entity.User
|
||||
import fr.dcproject.utils.toUUID
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import io.cucumber.datatable.DataTable
|
||||
import io.cucumber.java8.En
|
||||
@@ -16,29 +15,27 @@ import org.koin.test.get
|
||||
import org.koin.test.inject
|
||||
import java.util.*
|
||||
import java.util.concurrent.CompletionException
|
||||
import kotlin.random.Random
|
||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||
|
||||
class KtorServerAuthSteps : En, KoinTest {
|
||||
private val requester: Requester by inject()
|
||||
init {
|
||||
When("I have citizen:") { body: DataTable ->
|
||||
val user = User(username = "jaque_${Random.nextInt(0, 10000)}", plainPassword = "azerty")
|
||||
requester
|
||||
.getFunction("insert_user")
|
||||
.selectOne(user)
|
||||
|
||||
val data = body.asMap<String, String>(String::class.java, String::class.java)
|
||||
val username = (data["firstName"] + "-" + data["lastName"]).toLowerCase()
|
||||
val user = User(
|
||||
username = username,
|
||||
plainPassword = "azerty"
|
||||
)
|
||||
val citizen = Citizen(
|
||||
id = UUID.fromString(data["id"]),
|
||||
name = CitizenI.Name(data["firstName"]!!, data["lastName"]!!),
|
||||
email = data["email"] ?: ((data["firstName"] + "-" + data["lastName"]).toLowerCase()) + "@dc-project.com",
|
||||
email = data["email"] ?: "$username@dc-project.com",
|
||||
birthday = DateTime.now(),
|
||||
user = user
|
||||
)
|
||||
requester
|
||||
.getFunction("upsert_citizen")
|
||||
.selectOne(citizen)
|
||||
|
||||
get<CitizenRepository>().insertWithUser(citizen)
|
||||
}
|
||||
|
||||
Given("I am authenticated as {word} {word} with id {string}") { firstName: String, lastName: String, id: String ->
|
||||
@@ -71,8 +68,8 @@ class KtorServerAuthSteps : En, KoinTest {
|
||||
}
|
||||
}
|
||||
|
||||
Given("I have citizen {word} {word}") { firstName: String, lastName: String, extraInfo: DataTable? ->
|
||||
val id: UUID = extraInfo?.asMap<String, String>(String::class.java, String::class.java)?.get("id")?.toUUID() ?: UUID.randomUUID()
|
||||
Given("I have citizen {word} {word}") { firstName: String, lastName: String ->
|
||||
val id: UUID = UUID.randomUUID()
|
||||
|
||||
val user = User(
|
||||
id = id,
|
||||
@@ -95,7 +92,7 @@ class KtorServerAuthSteps : En, KoinTest {
|
||||
val citizen = get<CitizenRepository>().findByUsername(username) ?: error("Cititzen not exist with username $username")
|
||||
val jwtAsString: String = JWT.create()
|
||||
.withIssuer("dc-project.fr")
|
||||
.withClaim("id", citizen.id.toString())
|
||||
.withClaim("id", citizen.user.id.toString())
|
||||
.sign(JwtConfig.algorithm)
|
||||
|
||||
KtorServerContext.defaultServer.addPreRequestSetup {
|
||||
|
||||
@@ -14,8 +14,10 @@ Feature: Opinion
|
||||
| [0]name | Opinion1 |
|
||||
|
||||
Scenario: Can create opinion on article
|
||||
Given I have citizen Isaac Newton
|
||||
| id | 2f414045-95d9-42ca-a3a9-8cdde52ad253 |
|
||||
Given I have citizen:
|
||||
| id | 2f414045-95d9-42ca-a3a9-8cdde52ad253 |
|
||||
| firstName | Isaac |
|
||||
| lastName | Newton |
|
||||
And I am authenticated as Isaac Newton
|
||||
And I have article
|
||||
| id | 9226c1a3-8091-c3fa-7d0d-c2e98c9bee7 |
|
||||
@@ -45,8 +47,10 @@ Feature: Opinion
|
||||
| opinions.Opinion2 | 1 |
|
||||
|
||||
Scenario: Can get all opinion of one citizen
|
||||
Given I have citizen Albert Einstein
|
||||
| id | c1542096-3431-432d-8e35-9dc071d4c818 |
|
||||
Given I have citizen:
|
||||
| id | c1542096-3431-432d-8e35-9dc071d4c818 |
|
||||
| firstName | Albert |
|
||||
| lastName | Einstein |
|
||||
And I am authenticated as Albert Einstein
|
||||
And I have an opinion
|
||||
| opinion | Opinion1 |
|
||||
|
||||
Reference in New Issue
Block a user