#60 Can follow citizen

This commit is contained in:
2021-04-17 01:37:32 +02:00
parent 4871e7d780
commit 1c33c026f0
17 changed files with 463 additions and 8 deletions

View File

@@ -0,0 +1,96 @@
package integration
import integration.steps.`when`.`When I send a DELETE request`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.given.`And follow citizen`
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`authenticated as`
import integration.steps.given.`with no content`
import integration.steps.then.`And the response should be null`
import integration.steps.then.`And the response should contain`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.then.and
import io.ktor.http.HttpStatusCode.Companion.Created
import io.ktor.http.HttpStatusCode.Companion.NoContent
import io.ktor.http.HttpStatusCode.Companion.OK
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Tags
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Tags(Tag("integration"), Tag("article"), Tag("follow"))
class `Follow citizen routes` : BaseTest() {
@Test
fun `I can follow citizen`() {
withIntegrationApplication {
/* Followed user */
`Given I have citizen`("John", "Glenn", id = "7e1580c5-05b7-4557-84f4-faac9f0a9441")
/* Current user */
`Given I have citizen`("Valentina", "Terechkova")
`When I send a POST request`("/citizens/7e1580c5-05b7-4557-84f4-faac9f0a9441/follows") {
`authenticated as`("Valentina", "Terechkova")
`with no content`()
} `Then the response should be` Created
}
}
@Test
fun `I can get my follow citizen`() {
withIntegrationApplication {
/* Followed user */
`Given I have citizen`("Jean-Loup", "Chrétien", id = "c2432b94-a509-4116-a8b6-9774bc963372")
/* Current user */
`Given I have citizen`("John", "Young", id = "6d41ce65-9df7-47e0-af46-8da4a909490b") {
`And follow citizen`("c2432b94-a509-4116-a8b6-9774bc963372")
}
/* Get my all follows */
`When I send a GET request`("/citizens/6d41ce65-9df7-47e0-af46-8da4a909490b/follows/citizens") {
`authenticated as`("John", "Young")
} `Then the response should be` OK and {
`And the response should not be null`()
`And the response should contain`("$.currentPage", 1)
`And the response should contain`("$.limit", 50)
}
}
}
@Test
fun `I can unfollow citizen`() {
withIntegrationApplication {
/* Followed user */
`Given I have citizen`("Bruce", "McCandless", id = "680c7af7-d2de-4249-bfcb-47007ef546fe")
/* Current user */
`Given I have citizen`("Jean-François", "Clervoy", id = "a12455ae-1047-43ff-826d-0d826dbe90f7") {
`And follow citizen`("680c7af7-d2de-4249-bfcb-47007ef546fe")
}
`When I send a DELETE request`("/citizens/680c7af7-d2de-4249-bfcb-47007ef546fe/follows") {
`authenticated as`("Jean-François", "Clervoy")
`with no content`()
} `Then the response should be` NoContent and {
`And the response should be null`()
}
}
}
@Test
fun `I can know if I follow an citizen`() {
withIntegrationApplication {
/* Followed user */
`Given I have citizen`("Eugene", "Cernan", id = "c755788f-7f48-4cde-8ff0-e75bcffdafc2")
/* Current user */
`Given I have citizen`("Buzz", "Aldrin", id = "39e2915a-e96f-43ea-babd-bd339d8bf197") {
`And follow citizen`("c755788f-7f48-4cde-8ff0-e75bcffdafc2")
}
`When I send a GET request`("/citizens/c755788f-7f48-4cde-8ff0-e75bcffdafc2/follows") {
`authenticated as`("Buzz", "Aldrin")
`with no content`()
} `Then the response should be` OK and {
`And the response should not be null`()
`And the response should contain`("$.target.id", "c755788f-7f48-4cde-8ff0-e75bcffdafc2")
}
}
}
}

View File

@@ -8,6 +8,7 @@ import fr.dcproject.component.citizen.database.CitizenRef
import fr.dcproject.component.citizen.database.CitizenRepository
import fr.dcproject.component.constitution.database.ConstitutionRef
import fr.dcproject.component.follow.database.FollowArticleRepository
import fr.dcproject.component.follow.database.FollowCitizenRepository
import fr.dcproject.component.follow.database.FollowConstitutionRepository
import fr.dcproject.component.follow.database.FollowForUpdate
import io.ktor.server.testing.TestApplicationEngine
@@ -24,6 +25,11 @@ fun Citizen.`And follow constitution`(
) {
createFollow(this, ConstitutionRef(constitution.toUUID()))
}
fun Citizen.`And follow citizen`(
citizen: String,
) {
createFollow(this, CitizenRef(citizen.toUUID()))
}
fun TestApplicationEngine.`Given I have follow on article`(
firstName: String,
@@ -56,3 +62,9 @@ fun createFollow(citizen: CitizenRef, constitution: ConstitutionRef) {
val follow = FollowForUpdate(createdBy = citizen, target = constitution)
followConstitutionRepository.follow(follow)
}
fun createFollow(createdBy: CitizenRef, target: CitizenRef) {
val followCitizenRepository: FollowCitizenRepository by lazy { GlobalContext.get().get() }
val follow = FollowForUpdate(createdBy = createdBy, target = target)
followCitizenRepository.follow(follow)
}