Minor refactoring of cucumber steps

This commit is contained in:
2020-02-27 20:34:29 +01:00
parent cd13f9a010
commit 5d26497cdb
5 changed files with 91 additions and 18 deletions

24
.idea/runConfigurations/Follow_Tests.xml generated Normal file
View 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=&quot;@follow&quot; -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>

View 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=&quot;@error&quot; -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>

View 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=&quot;@opinion&quot; -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>

View File

@@ -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 {

View File

@@ -14,8 +14,10 @@ Feature: Opinion
| [0]name | Opinion1 |
Scenario: Can create opinion on article
Given I have citizen Isaac Newton
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
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 |