Refactor cucumber steps
This commit is contained in:
@@ -14,8 +14,9 @@ import org.koin.test.KoinTest
|
||||
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.User as UserRepository
|
||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||
|
||||
class KtorServerAuthSteps: En, KoinTest {
|
||||
private val requester: Requester by inject()
|
||||
@@ -38,19 +39,53 @@ class KtorServerAuthSteps: En, KoinTest {
|
||||
.selectOne(citizen)
|
||||
}
|
||||
|
||||
Given("I am authenticated as an user") {
|
||||
val id = UUID.randomUUID()
|
||||
Given("I am authenticated as {word} {word} with id {string}") { firstName: String, lastName: String, id: String ->
|
||||
val jwtAsString: String = JWT.create()
|
||||
.withIssuer("dc-project.fr")
|
||||
.withClaim("id", id.toString())
|
||||
.withClaim("id", id)
|
||||
.sign(Algorithm.HMAC512(JwtConfig.secret))
|
||||
|
||||
val user = User(id = id, username = "user", plainPassword = "azerty")
|
||||
get<UserRepository>().insert(user)
|
||||
val user = User(
|
||||
id = UUID.fromString(id),
|
||||
username = "$firstName-$lastName".toLowerCase(),
|
||||
plainPassword = "azerty"
|
||||
)
|
||||
val citizen = Citizen(
|
||||
id = UUID.fromString(id),
|
||||
name = Citizen.Name(firstName, lastName),
|
||||
birthday = DateTime.now(),
|
||||
user = user
|
||||
)
|
||||
|
||||
try {
|
||||
get<CitizenRepository>().insertWithUser(citizen)
|
||||
} catch (e: CompletionException) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
KtorServerContext.defaultServer.addPreRequestSetup {
|
||||
addHeader(HttpHeaders.Authorization, "Bearer $jwtAsString")
|
||||
}
|
||||
}
|
||||
|
||||
Given("I have citizen {word} {word} with id {string}") { firstName: String, lastName: String, id: String ->
|
||||
val user = User(
|
||||
id = UUID.randomUUID(),
|
||||
username = "$firstName-$lastName".toLowerCase(),
|
||||
plainPassword = "azerty"
|
||||
)
|
||||
val citizen = Citizen(
|
||||
id = UUID.fromString(id),
|
||||
name = Citizen.Name(firstName, lastName),
|
||||
birthday = DateTime.now(),
|
||||
user = user
|
||||
)
|
||||
|
||||
try {
|
||||
get<CitizenRepository>().insertWithUser(citizen)
|
||||
} catch (e: CompletionException) {
|
||||
// Nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,7 @@ Feature: articles routes
|
||||
| id | 9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b |
|
||||
|
||||
Scenario: The route for create article must response a 200 and return object
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
And I am authenticated as an user
|
||||
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||
When I send a POST request to "/articles" with body:
|
||||
"""
|
||||
{
|
||||
|
||||
@@ -11,10 +11,7 @@ Feature: constitution routes
|
||||
| id | 0ca489a6-ef68-8bd5-2355-5793d4b3d66c |
|
||||
|
||||
Scenario: The route for create constitution must response a 200 and return object
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||
When I send a POST request to "/constitutions" with body:
|
||||
"""
|
||||
{
|
||||
|
||||
@@ -2,18 +2,12 @@ Feature: follow Article and Constitution
|
||||
|
||||
# Article
|
||||
Scenario: The route for follow article must response a 201 and return object
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||
When I send a POST request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/follow"
|
||||
Then the response status code should be 201
|
||||
|
||||
Scenario: The route for get follows of articles must response a 200 and return objects
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||
When I send a GET request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/follows/articles"
|
||||
Then the response status code should be 200
|
||||
And the response should contain object:
|
||||
@@ -21,27 +15,18 @@ Feature: follow Article and Constitution
|
||||
| limit | 50 |
|
||||
|
||||
Scenario: The route for unfollow article must response a 204
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||
When I send a DELETE request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/follow"
|
||||
Then the response status code should be 204
|
||||
|
||||
# Constitution
|
||||
Scenario: The route for follow constitution must response a 201 and return object
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||
When I send a POST request to "/constitutions/72aa1ee1-4963-eb44-c9e0-5ce6e0f18f00/follow"
|
||||
Then the response status code should be 201
|
||||
|
||||
Scenario: The route for get follows of constitutions must response a 200 and return objects
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||
When I send a GET request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/follows/constitutions"
|
||||
Then the response status code should be 200
|
||||
And the response should contain object:
|
||||
@@ -49,9 +34,6 @@ Feature: follow Article and Constitution
|
||||
| limit | 50 |
|
||||
|
||||
Scenario: The route for unfollow constitution must response a 204
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||
When I send a DELETE request to "/constitutions/72aa1ee1-4963-eb44-c9e0-5ce6e0f18f00/follow"
|
||||
Then the response status code should be 204
|
||||
|
||||
Reference in New Issue
Block a user