Minor refactoring of cucumber steps
This commit is contained in:
24
.idea/runConfigurations/Follow_Tests.xml
generated
Normal file
24
.idea/runConfigurations/Follow_Tests.xml
generated
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Follow Tests" type="JUnit" factoryName="JUnit" show_console_on_std_err="true">
|
||||||
|
<output_file path="$PROJECT_DIR$/var/log/test/out.log" is_save="true" />
|
||||||
|
<module name="dcproject.test" />
|
||||||
|
<useClassPathOnly />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="RunCucumberTest" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea -Dcucumber.filter.tags="@follow" -Dstrict" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="wholeProject" />
|
||||||
|
</option>
|
||||||
|
<envs>
|
||||||
|
<env name="SEND_GRID_KEY" value="$SEND_GRID_KEY$" />
|
||||||
|
</envs>
|
||||||
|
<dir value="$PROJECT_DIR$" />
|
||||||
|
<tag value="!online" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
24
.idea/runConfigurations/Mark_as__error.xml
generated
Normal file
24
.idea/runConfigurations/Mark_as__error.xml
generated
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Mark as @error" type="JUnit" factoryName="JUnit" show_console_on_std_err="true">
|
||||||
|
<output_file path="$PROJECT_DIR$/var/log/test/out.log" is_save="true" />
|
||||||
|
<module name="dcproject.test" />
|
||||||
|
<useClassPathOnly />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="RunCucumberTest" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea -Dcucumber.filter.tags="@error" -Dstrict" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="wholeProject" />
|
||||||
|
</option>
|
||||||
|
<envs>
|
||||||
|
<env name="SEND_GRID_KEY" value="$SEND_GRID_KEY$" />
|
||||||
|
</envs>
|
||||||
|
<dir value="$PROJECT_DIR$" />
|
||||||
|
<tag value="!online" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
24
.idea/runConfigurations/Opinion_Tests.xml
generated
Normal file
24
.idea/runConfigurations/Opinion_Tests.xml
generated
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Opinion Tests" type="JUnit" factoryName="JUnit" show_console_on_std_err="true">
|
||||||
|
<output_file path="$PROJECT_DIR$/var/log/test/out.log" is_save="true" />
|
||||||
|
<module name="dcproject.test" />
|
||||||
|
<useClassPathOnly />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="RunCucumberTest" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea -Dcucumber.filter.tags="@opinion" -Dstrict" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="wholeProject" />
|
||||||
|
</option>
|
||||||
|
<envs>
|
||||||
|
<env name="SEND_GRID_KEY" value="$SEND_GRID_KEY$" />
|
||||||
|
</envs>
|
||||||
|
<dir value="$PROJECT_DIR$" />
|
||||||
|
<tag value="!online" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -5,7 +5,6 @@ import fr.dcproject.JwtConfig
|
|||||||
import fr.dcproject.entity.Citizen
|
import fr.dcproject.entity.Citizen
|
||||||
import fr.dcproject.entity.CitizenI
|
import fr.dcproject.entity.CitizenI
|
||||||
import fr.dcproject.entity.User
|
import fr.dcproject.entity.User
|
||||||
import fr.dcproject.utils.toUUID
|
|
||||||
import fr.postgresjson.connexion.Requester
|
import fr.postgresjson.connexion.Requester
|
||||||
import io.cucumber.datatable.DataTable
|
import io.cucumber.datatable.DataTable
|
||||||
import io.cucumber.java8.En
|
import io.cucumber.java8.En
|
||||||
@@ -16,29 +15,27 @@ import org.koin.test.get
|
|||||||
import org.koin.test.inject
|
import org.koin.test.inject
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.CompletionException
|
import java.util.concurrent.CompletionException
|
||||||
import kotlin.random.Random
|
|
||||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||||
|
|
||||||
class KtorServerAuthSteps : En, KoinTest {
|
class KtorServerAuthSteps : En, KoinTest {
|
||||||
private val requester: Requester by inject()
|
private val requester: Requester by inject()
|
||||||
init {
|
init {
|
||||||
When("I have citizen:") { body: DataTable ->
|
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 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(
|
val citizen = Citizen(
|
||||||
id = UUID.fromString(data["id"]),
|
id = UUID.fromString(data["id"]),
|
||||||
name = CitizenI.Name(data["firstName"]!!, data["lastName"]!!),
|
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(),
|
birthday = DateTime.now(),
|
||||||
user = user
|
user = user
|
||||||
)
|
)
|
||||||
requester
|
|
||||||
.getFunction("upsert_citizen")
|
get<CitizenRepository>().insertWithUser(citizen)
|
||||||
.selectOne(citizen)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Given("I am authenticated as {word} {word} with id {string}") { firstName: String, lastName: String, id: String ->
|
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? ->
|
Given("I have citizen {word} {word}") { firstName: String, lastName: String ->
|
||||||
val id: UUID = extraInfo?.asMap<String, String>(String::class.java, String::class.java)?.get("id")?.toUUID() ?: UUID.randomUUID()
|
val id: UUID = UUID.randomUUID()
|
||||||
|
|
||||||
val user = User(
|
val user = User(
|
||||||
id = id,
|
id = id,
|
||||||
@@ -95,7 +92,7 @@ class KtorServerAuthSteps : En, KoinTest {
|
|||||||
val citizen = get<CitizenRepository>().findByUsername(username) ?: error("Cititzen not exist with username $username")
|
val citizen = get<CitizenRepository>().findByUsername(username) ?: error("Cititzen not exist with username $username")
|
||||||
val jwtAsString: String = JWT.create()
|
val jwtAsString: String = JWT.create()
|
||||||
.withIssuer("dc-project.fr")
|
.withIssuer("dc-project.fr")
|
||||||
.withClaim("id", citizen.id.toString())
|
.withClaim("id", citizen.user.id.toString())
|
||||||
.sign(JwtConfig.algorithm)
|
.sign(JwtConfig.algorithm)
|
||||||
|
|
||||||
KtorServerContext.defaultServer.addPreRequestSetup {
|
KtorServerContext.defaultServer.addPreRequestSetup {
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ Feature: Opinion
|
|||||||
| [0]name | Opinion1 |
|
| [0]name | Opinion1 |
|
||||||
|
|
||||||
Scenario: Can create opinion on article
|
Scenario: Can create opinion on article
|
||||||
Given I have citizen Isaac Newton
|
Given I have citizen:
|
||||||
| id | 2f414045-95d9-42ca-a3a9-8cdde52ad253 |
|
| id | 2f414045-95d9-42ca-a3a9-8cdde52ad253 |
|
||||||
|
| firstName | Isaac |
|
||||||
|
| lastName | Newton |
|
||||||
And I am authenticated as Isaac Newton
|
And I am authenticated as Isaac Newton
|
||||||
And I have article
|
And I have article
|
||||||
| id | 9226c1a3-8091-c3fa-7d0d-c2e98c9bee7 |
|
| id | 9226c1a3-8091-c3fa-7d0d-c2e98c9bee7 |
|
||||||
@@ -45,8 +47,10 @@ Feature: Opinion
|
|||||||
| opinions.Opinion2 | 1 |
|
| opinions.Opinion2 | 1 |
|
||||||
|
|
||||||
Scenario: Can get all opinion of one citizen
|
Scenario: Can get all opinion of one citizen
|
||||||
Given I have citizen Albert Einstein
|
Given I have citizen:
|
||||||
| id | c1542096-3431-432d-8e35-9dc071d4c818 |
|
| id | c1542096-3431-432d-8e35-9dc071d4c818 |
|
||||||
|
| firstName | Albert |
|
||||||
|
| lastName | Einstein |
|
||||||
And I am authenticated as Albert Einstein
|
And I am authenticated as Albert Einstein
|
||||||
And I have an opinion
|
And I have an opinion
|
||||||
| opinion | Opinion1 |
|
| opinion | Opinion1 |
|
||||||
|
|||||||
Reference in New Issue
Block a user