Merge pull request #94 from flecomte/62
#62 if not connected, you not must view the articles draft
This commit was merged in pull request #94.
This commit is contained in:
@@ -170,6 +170,18 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/404'
|
||||
401:
|
||||
description: Unauthorized
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/401'
|
||||
403:
|
||||
description: Forbidden
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/403'
|
||||
|
||||
/articles/{article}/versions:
|
||||
parameters:
|
||||
@@ -2468,7 +2480,20 @@ components:
|
||||
reason:
|
||||
type: string
|
||||
example: 'Cannot be null'
|
||||
|
||||
403:
|
||||
description: Forbiden
|
||||
properties:
|
||||
statusCode:
|
||||
type: integer
|
||||
title:
|
||||
type: string
|
||||
401:
|
||||
description: Unauthorized
|
||||
properties:
|
||||
statusCode:
|
||||
type: integer
|
||||
title:
|
||||
type: string
|
||||
404:
|
||||
description: Not Found
|
||||
required:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package integration
|
||||
|
||||
import fr.dcproject.common.utils.toUUID
|
||||
import fr.dcproject.component.citizen.database.CitizenI.Name
|
||||
import integration.steps.`when`.Validate
|
||||
import integration.steps.`when`.`When I send a GET request`
|
||||
import integration.steps.`when`.`When I send a POST request`
|
||||
@@ -9,6 +10,7 @@ import integration.steps.given.`Given I have article created by workgroup`
|
||||
import integration.steps.given.`Given I have article`
|
||||
import integration.steps.given.`Given I have articles`
|
||||
import integration.steps.given.`Given I have citizen`
|
||||
import integration.steps.given.`Given I have draft article`
|
||||
import integration.steps.given.`Given I have workgroup`
|
||||
import integration.steps.given.`authenticated as`
|
||||
import integration.steps.then.`And have property`
|
||||
@@ -24,6 +26,7 @@ import io.ktor.http.HttpStatusCode.Companion.BadRequest
|
||||
import io.ktor.http.HttpStatusCode.Companion.Forbidden
|
||||
import io.ktor.http.HttpStatusCode.Companion.NotFound
|
||||
import io.ktor.http.HttpStatusCode.Companion.OK
|
||||
import io.ktor.http.HttpStatusCode.Companion.Unauthorized
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Tags
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -94,6 +97,47 @@ class `Article routes` : BaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("draft")
|
||||
fun `I can get my draft article by id`() {
|
||||
withIntegrationApplication {
|
||||
`Given I have citizen`("Neil", "Armstrong")
|
||||
`Given I have draft article`(id = "d946e16f-ca42-4cf9-a711-a0f8cae60a55", createdBy = Name("Neil", "Armstrong"))
|
||||
`When I send a GET request`("/articles/d946e16f-ca42-4cf9-a711-a0f8cae60a55") {
|
||||
`authenticated as`("Neil", "Armstrong")
|
||||
} `Then the response should be` OK and {
|
||||
`And the response should not be null`()
|
||||
`And have property`("$.id") `which contains` "d946e16f-ca42-4cf9-a711-a0f8cae60a55"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("draft")
|
||||
fun `I cannot get draft article by id if not owner`() {
|
||||
withIntegrationApplication {
|
||||
`Given I have citizen`("Thomas", "Pesquet")
|
||||
`Given I have citizen`("Youri", "Gagarine")
|
||||
`Given I have draft article`(id = "bf13c84c-609f-49b9-9d1d-e2e9655ed8ad")
|
||||
`When I send a GET request`("/articles/bf13c84c-609f-49b9-9d1d-e2e9655ed8ad") {
|
||||
`authenticated as`("Youri", "Gagarine")
|
||||
} `Then the response should be` Forbidden and {
|
||||
`And the response should not be null`()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("draft")
|
||||
fun `I cannot get draft article by id if not connected`() {
|
||||
withIntegrationApplication {
|
||||
`Given I have draft article`(id = "bf13c84c-609f-49b9-9d1d-e2e9655ed8ad")
|
||||
`When I send a GET request`("/articles/bf13c84c-609f-49b9-9d1d-e2e9655ed8ad") `Then the response should be` Unauthorized and {
|
||||
`And the response should not be null`()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("BadRequest")
|
||||
fun `I cannot get article by id with wrong id format`() {
|
||||
|
||||
@@ -20,6 +20,14 @@ fun TestApplicationEngine.`Given I have article`(
|
||||
createArticle(id?.toUUID(), workgroup, createCitizen(name = createdBy))
|
||||
}
|
||||
|
||||
fun TestApplicationEngine.`Given I have draft article`(
|
||||
id: String? = null,
|
||||
workgroup: WorkgroupRef? = null,
|
||||
createdBy: Name? = null
|
||||
) {
|
||||
createArticle(id?.toUUID(), workgroup, createCitizen(name = createdBy), draft = true)
|
||||
}
|
||||
|
||||
fun TestApplicationEngine.`Given I have article`(
|
||||
id: String? = null,
|
||||
workgroup: WorkgroupRef? = null,
|
||||
@@ -44,7 +52,8 @@ fun TestApplicationEngine.`Given I have article created by workgroup`(
|
||||
fun createArticle(
|
||||
id: UUID? = null,
|
||||
workgroup: WorkgroupRef? = null,
|
||||
createdBy: CitizenRef = createCitizen()
|
||||
createdBy: CitizenRef = createCitizen(),
|
||||
draft: Boolean = false,
|
||||
): ArticleForView {
|
||||
val articleRepository: ArticleRepository by lazy { GlobalContext.get().get() }
|
||||
|
||||
@@ -55,7 +64,8 @@ fun createArticle(
|
||||
description = LoremIpsum().getParagraphs(1, 2),
|
||||
createdBy = createdBy,
|
||||
workgroup = workgroup,
|
||||
versionId = UUID.randomUUID()
|
||||
versionId = UUID.randomUUID(),
|
||||
draft = draft,
|
||||
)
|
||||
return articleRepository.upsert(article) ?: error("Cannot create article")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user