remove fixed raw citizen and use real current citizen

Fix tests
This commit is contained in:
2019-08-29 14:38:11 +02:00
parent 025153c4cd
commit 201430017e
6 changed files with 14 additions and 32 deletions

View File

@@ -1,26 +1,16 @@
package fr.dcproject.routes
import fr.dcproject.citizen
import fr.dcproject.entity.Citizen
import fr.dcproject.entity.User
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.locations.*
import io.ktor.response.respond
import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.*
import fr.dcproject.entity.Article as ArticleEntity
import fr.dcproject.entity.Follow as FollowEntity
import fr.dcproject.repository.FollowArticle as FollowArticleRepository
// TODO get current citizen
val currentCitizen = Citizen(
id = UUID.fromString("64b7b379-2298-43ec-b428-ba134930cabd"),
name = Citizen.Name("todo", "todo"),
birthday = DateTime.now(),
user = User(username = "plop", plainPassword = "plip")
)
@KtorExperimentalLocationsAPI
object FollowArticlePaths {
@Location("/articles/{article}/follow") class ArticleFollowRequest(val article: ArticleEntity)
@@ -30,12 +20,12 @@ object FollowArticlePaths {
@KtorExperimentalLocationsAPI
fun Route.followArticle(repo: FollowArticleRepository) {
post<FollowArticlePaths.ArticleFollowRequest> {
repo.follow(FollowEntity(target = it.article, createdBy = currentCitizen))
repo.follow(FollowEntity(target = it.article, createdBy = this.citizen))
call.respond(HttpStatusCode.Created)
}
delete<FollowArticlePaths.ArticleFollowRequest> {
repo.unfollow(FollowEntity(target = it.article, createdBy = currentCitizen))
repo.unfollow(FollowEntity(target = it.article, createdBy = this.citizen))
call.respond(HttpStatusCode.NoContent)
}

View File

@@ -1,26 +1,16 @@
package fr.dcproject.routes
import fr.dcproject.citizen
import fr.dcproject.entity.Citizen
import fr.dcproject.entity.User
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.locations.*
import io.ktor.response.respond
import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.*
import fr.dcproject.entity.Constitution as ConstitutionEntity
import fr.dcproject.entity.Follow as FollowEntity
import fr.dcproject.repository.FollowConstitution as FollowConstitutionRepository
// TODO get current citizen
val currentCitizen2 = Citizen(
id = UUID.fromString("64b7b379-2298-43ec-b428-ba134930cabd"),
name = Citizen.Name("todo", "todo"),
birthday = DateTime.now(),
user = User(username = "plop", plainPassword = "plip")
)
@KtorExperimentalLocationsAPI
object FollowConstitutionPaths {
@Location("/constitutions/{constitution}/follow") class ConstitutionFollowRequest(val constitution: ConstitutionEntity)
@@ -30,12 +20,12 @@ object FollowConstitutionPaths {
@KtorExperimentalLocationsAPI
fun Route.followConstitution(repo: FollowConstitutionRepository) {
post<FollowConstitutionPaths.ConstitutionFollowRequest> {
repo.follow(FollowEntity(target = it.constitution, createdBy = currentCitizen2))
repo.follow(FollowEntity(target = it.constitution, createdBy = this.citizen))
call.respond(HttpStatusCode.Created)
}
delete<FollowConstitutionPaths.ConstitutionFollowRequest> {
repo.unfollow(FollowEntity(target = it.constitution, createdBy = currentCitizen2))
repo.unfollow(FollowEntity(target = it.constitution, createdBy = this.citizen))
call.respond(HttpStatusCode.NoContent)
}

View File

@@ -18,7 +18,7 @@ Feature: Auth routes
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.
"""
Scenario: The route for create citizen must response a 200 and return object
Scenario: The route for create citizen must response a 400 and return object
When I send a POST request to "/register" with body:
"""
{

View File

@@ -1,10 +1,12 @@
Feature: citizens routes
Scenario: The route for get citizens must response a 200
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
When I send a GET request to "/citizens"
Then the response status code should be 200
Scenario: The route for get one citizen must response a 200 and return citizen
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
When I send a GET request to "/citizens/6434f4f9-f570-f22a-c134-8668350651ff"
Then the response status code should be 200
And the response should contain object:

View File

@@ -11,7 +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 John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
When I send a POST request to "/constitutions" with body:
"""
{

View File

@@ -2,7 +2,7 @@ Feature: follow Article and Constitution
# Article
Scenario: The route for follow article must response a 201 and return object
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
Given I am authenticated as 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
@@ -15,13 +15,13 @@ Feature: follow Article and Constitution
| limit | 50 |
Scenario: The route for unfollow article must response a 204
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
Given I am authenticated as 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 John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
Given I am authenticated as 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
@@ -34,6 +34,6 @@ Feature: follow Article and Constitution
| limit | 50 |
Scenario: The route for unfollow constitution must response a 204
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
Given I am authenticated as 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