diff --git a/src/main/kotlin/fr/dcproject/routes/FollowArticle.kt b/src/main/kotlin/fr/dcproject/routes/FollowArticle.kt index cbc4be8..8af9417 100644 --- a/src/main/kotlin/fr/dcproject/routes/FollowArticle.kt +++ b/src/main/kotlin/fr/dcproject/routes/FollowArticle.kt @@ -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 { - repo.follow(FollowEntity(target = it.article, createdBy = currentCitizen)) + repo.follow(FollowEntity(target = it.article, createdBy = this.citizen)) call.respond(HttpStatusCode.Created) } delete { - repo.unfollow(FollowEntity(target = it.article, createdBy = currentCitizen)) + repo.unfollow(FollowEntity(target = it.article, createdBy = this.citizen)) call.respond(HttpStatusCode.NoContent) } diff --git a/src/main/kotlin/fr/dcproject/routes/FollowConstitution.kt b/src/main/kotlin/fr/dcproject/routes/FollowConstitution.kt index 07f0330..b4f2fe9 100644 --- a/src/main/kotlin/fr/dcproject/routes/FollowConstitution.kt +++ b/src/main/kotlin/fr/dcproject/routes/FollowConstitution.kt @@ -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 { - repo.follow(FollowEntity(target = it.constitution, createdBy = currentCitizen2)) + repo.follow(FollowEntity(target = it.constitution, createdBy = this.citizen)) call.respond(HttpStatusCode.Created) } delete { - repo.unfollow(FollowEntity(target = it.constitution, createdBy = currentCitizen2)) + repo.unfollow(FollowEntity(target = it.constitution, createdBy = this.citizen)) call.respond(HttpStatusCode.NoContent) } diff --git a/src/test/resources/feature/auth.feature b/src/test/resources/feature/auth.feature index 5df7f2c..4fd762c 100644 --- a/src/test/resources/feature/auth.feature +++ b/src/test/resources/feature/auth.feature @@ -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: """ { diff --git a/src/test/resources/feature/citizen.feature b/src/test/resources/feature/citizen.feature index 26bbff4..407c13e 100644 --- a/src/test/resources/feature/citizen.feature +++ b/src/test/resources/feature/citizen.feature @@ -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: diff --git a/src/test/resources/feature/constitution.feature b/src/test/resources/feature/constitution.feature index 02bc72c..4b7c6b8 100644 --- a/src/test/resources/feature/constitution.feature +++ b/src/test/resources/feature/constitution.feature @@ -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: """ { diff --git a/src/test/resources/feature/follow.feature b/src/test/resources/feature/follow.feature index 96aba76..17551f9 100644 --- a/src/test/resources/feature/follow.feature +++ b/src/test/resources/feature/follow.feature @@ -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