Test openapi schema response of FindArticlesVersion,GetOneArticle,UpsertArticle
change snack_case to camelCase
This commit is contained in:
@@ -8,7 +8,6 @@ import fr.dcproject.component.article.database.ArticleRef
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
import fr.dcproject.component.follow.database.FollowArticleRepository
|
||||
import fr.dcproject.component.follow.database.FollowForView
|
||||
import fr.dcproject.component.notification.ArticleUpdateNotification
|
||||
@@ -108,7 +107,11 @@ class NotificationConsumerTest {
|
||||
title = "MyTitle",
|
||||
content = "myContent",
|
||||
description = "myDescription",
|
||||
createdBy = CitizenRef()
|
||||
createdBy = CitizenCreator(
|
||||
name = CitizenI.Name(firstName = "", lastName = ""),
|
||||
email = "",
|
||||
user = UserCreator(username = ""),
|
||||
)
|
||||
)
|
||||
)
|
||||
).await()
|
||||
|
||||
@@ -3,7 +3,9 @@ package functional
|
||||
import com.rabbitmq.client.ConnectionFactory
|
||||
import fr.dcproject.application.Configuration
|
||||
import fr.dcproject.component.article.database.ArticleForView
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.notification.ArticleUpdateNotification
|
||||
import fr.dcproject.component.notification.Notification
|
||||
import fr.dcproject.component.notification.NotificationsPush
|
||||
@@ -53,7 +55,11 @@ internal class NotificationsPushTest {
|
||||
every { redisClient.connect().async() } returns asyncCommand
|
||||
|
||||
/* Citizen of notification */
|
||||
val citizen = CitizenRef()
|
||||
val citizen = CitizenCreator(
|
||||
name = CitizenI.Name(firstName = "", lastName = ""),
|
||||
email = "",
|
||||
user = UserCreator(username = ""),
|
||||
)
|
||||
/* Article is the target of the notification */
|
||||
val article = ArticleForView(
|
||||
content = "content..",
|
||||
|
||||
@@ -4,6 +4,9 @@ import fr.dcproject.application.Env.TEST
|
||||
import fr.dcproject.application.module
|
||||
import fr.dcproject.component.article.ArticleViewManager
|
||||
import fr.dcproject.component.article.database.ArticleForView
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.server.testing.withTestApplication
|
||||
@@ -27,9 +30,13 @@ class ViewTest {
|
||||
@Test
|
||||
fun `test View Article`() {
|
||||
val article = ArticleForView(
|
||||
id = UUID.randomUUID(),
|
||||
versionId = UUID.randomUUID(),
|
||||
createdBy = CitizenRef(),
|
||||
createdBy = CitizenCreator(
|
||||
id = UUID.randomUUID(),
|
||||
name = CitizenI.Name(firstName = "", lastName = ""),
|
||||
email = "",
|
||||
user = UserCreator(username = ""),
|
||||
),
|
||||
content = "",
|
||||
description = "",
|
||||
title = ""
|
||||
|
||||
@@ -32,9 +32,9 @@ class `Article routes` : BaseTest() {
|
||||
`Given I have articles`(3)
|
||||
`When I send a GET request`("/articles") `Then the response should be` OK and {
|
||||
`And the response should not be null`()
|
||||
`And the response should contain pattern`("$.result[0].created_by.name.first_name", "firstName.+")
|
||||
`And the response should contain pattern`("$.result[1].created_by.name.first_name", "firstName.+")
|
||||
`And the response should contain pattern`("$.result[2].created_by.name.first_name", "firstName.+")
|
||||
`And the response should contain pattern`("$.result[0].createdBy.name.firstName", "firstName.+")
|
||||
`And the response should contain pattern`("$.result[1].createdBy.name.firstName", "firstName.+")
|
||||
`And the response should contain pattern`("$.result[2].createdBy.name.firstName", "firstName.+")
|
||||
`And the response should not contain`("$.result[3]")
|
||||
`And the response should contain list`("$.result", 3, 3)
|
||||
`And schema must be valid`()
|
||||
@@ -77,6 +77,7 @@ class `Article routes` : BaseTest() {
|
||||
`And the response should not be null`()
|
||||
`And have property`("$.total") `whish contains` 1
|
||||
`And have property`("$.result[0].id") `whish contains` "13e6091c-8fed-4600-b079-a97a6b7a9800"
|
||||
`And schema must be valid`()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,7 +90,7 @@ class `Article routes` : BaseTest() {
|
||||
`authenticated as`("John", "Doe")
|
||||
"""
|
||||
{
|
||||
"version_id": "09c418b6-63ba-448b-b38b-502b41cd500e",
|
||||
"versionId": "09c418b6-63ba-448b-b38b-502b41cd500e",
|
||||
"title": "title2",
|
||||
"anonymous": false,
|
||||
"content": "content2",
|
||||
@@ -101,8 +102,8 @@ class `Article routes` : BaseTest() {
|
||||
"""
|
||||
} `Then the response should be` OK and {
|
||||
`And the response should not be null`()
|
||||
`And have property`("$.version_id") `whish contains` "09c418b6-63ba-448b-b38b-502b41cd500e"
|
||||
`And have property`("$.title") `whish contains` "title2"
|
||||
`And have property`("$.versionId") `whish contains` "09c418b6-63ba-448b-b38b-502b41cd500e"
|
||||
`And schema must be valid`()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@ package unit.security
|
||||
import fr.dcproject.common.security.AccessDecision.DENIED
|
||||
import fr.dcproject.common.security.AccessDecision.GRANTED
|
||||
import fr.dcproject.component.article.ArticleAccessControl
|
||||
import fr.dcproject.component.article.database.ArticleForListing
|
||||
import fr.dcproject.component.article.database.ArticleForView
|
||||
import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import io.mockk.every
|
||||
@@ -26,13 +29,13 @@ import fr.dcproject.component.article.database.ArticleRepository as ArticleRepo
|
||||
@Execution(CONCURRENT)
|
||||
@Tags(Tag("security"), Tag("unit"))
|
||||
internal class `Article Access Control` {
|
||||
private val tesla = CitizenCart(
|
||||
private val tesla = CitizenCreator(
|
||||
id = UUID.fromString("e6efc288-4283-4729-a268-6debb18de1a0"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "nicolas-tesla",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Nicolas", "Tesla")
|
||||
name = CitizenI.Name("Nicolas", "Tesla"),
|
||||
email = "nikola-tesla@volt.com"
|
||||
)
|
||||
private val einstein = CitizenCart(
|
||||
user = User(
|
||||
@@ -42,16 +45,16 @@ internal class `Article Access Control` {
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
)
|
||||
|
||||
private fun getRepo(article: ArticleForView): ArticleRepo {
|
||||
private fun getRepo(article: ArticleForListing): ArticleRepo {
|
||||
return mockk {
|
||||
every { findVersionsByVersionId(1, 1, any()) } returns Paginated(listOf(article), 0, 1, 1)
|
||||
every { find(1, 1, any()) } returns Paginated(listOf(article), 0, 1, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `creator can be view the article`() {
|
||||
val article = getArticle(tesla).copy(draft = true)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(article, tesla)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -59,7 +62,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `other user can be view the article`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(article, einstein)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -69,7 +72,7 @@ internal class `Article Access Control` {
|
||||
val article = getArticle(tesla)
|
||||
val article2 = getArticle(tesla)
|
||||
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(listOf(article, article2), einstein)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -77,7 +80,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `the no creator can not be view the article on draft`() {
|
||||
val article = getArticle(tesla).copy(draft = true)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(article, einstein)
|
||||
.decision `should be` DENIED
|
||||
}
|
||||
@@ -87,7 +90,7 @@ internal class `Article Access Control` {
|
||||
val article = getArticle(tesla)
|
||||
val article2 = getArticle(tesla).copy(draft = true)
|
||||
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(listOf(article, article2), einstein)
|
||||
.decision `should be` DENIED
|
||||
}
|
||||
@@ -95,7 +98,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can not view deleted article`() {
|
||||
val article = getArticle(tesla).copy(deletedAt = DateTime.now())
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(article, tesla)
|
||||
.decision `should be` DENIED
|
||||
}
|
||||
@@ -103,7 +106,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can delete article if owner`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canDelete(article, tesla)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -111,7 +114,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can not delete article if not owner`() {
|
||||
val article = getArticle(tesla).copy(deletedAt = DateTime.now())
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canDelete(article, einstein)
|
||||
.code `should be` "article.delete.notYours"
|
||||
}
|
||||
@@ -119,7 +122,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can create article if logged`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canUpsert(article, tesla)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -127,7 +130,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can not create article if not logged`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canUpsert(article, null)
|
||||
.code `should be` "article.create.notConnected"
|
||||
}
|
||||
@@ -135,7 +138,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can update article if yours`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canUpsert(article, tesla)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -143,12 +146,12 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can not update article if not yours`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canUpsert(article, einstein)
|
||||
.code `should be` "article.update.notYours"
|
||||
}
|
||||
|
||||
private fun getArticle(createdBy: CitizenCart = tesla) = ArticleForView(
|
||||
private fun getArticle(createdBy: CitizenCreator = tesla) = ArticleForView(
|
||||
id = UUID.randomUUID(),
|
||||
title = "Hello world",
|
||||
content = "Super",
|
||||
@@ -158,4 +161,10 @@ internal class `Article Access Control` {
|
||||
versionId = UUID.randomUUID(),
|
||||
versionNumber = 1
|
||||
)
|
||||
|
||||
private fun getArticleForListing(createdBy: CitizenCreator = tesla) = ArticleForListing(
|
||||
id = UUID.randomUUID(),
|
||||
title = "Hello world",
|
||||
createdBy = createdBy,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import fr.dcproject.common.security.AccessDecision.GRANTED
|
||||
import fr.dcproject.component.article.database.ArticleForView
|
||||
import fr.dcproject.component.article.database.ArticleRef
|
||||
import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.Citizen
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.comment.generic.CommentAccessControl
|
||||
import fr.dcproject.component.comment.generic.database.CommentForUpdate
|
||||
@@ -46,13 +47,13 @@ internal class `Comment Access Control` {
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
)
|
||||
|
||||
private val einstein2 = CitizenCart(
|
||||
private val einstein2 = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
email = "albert-einstein@email.com"
|
||||
)
|
||||
|
||||
private val article1 = ArticleForView(
|
||||
|
||||
@@ -7,7 +7,6 @@ import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.Citizen
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.follow.FollowAccessControl
|
||||
@@ -55,13 +54,13 @@ internal class `Follow Access Control` {
|
||||
followAnonymous = true
|
||||
)
|
||||
|
||||
private val einstein2 = CitizenCart(
|
||||
private val einstein2 = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
email = "albert-einstein@email.com"
|
||||
)
|
||||
|
||||
private val einstein3 = Citizen(
|
||||
|
||||
@@ -3,10 +3,7 @@ package unit.security
|
||||
import fr.dcproject.common.security.AccessDecision.DENIED
|
||||
import fr.dcproject.common.security.AccessDecision.GRANTED
|
||||
import fr.dcproject.component.article.database.ArticleForView
|
||||
import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
@@ -39,13 +36,13 @@ internal class `Opinion Access Control` {
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
)
|
||||
|
||||
private val einstein2 = CitizenCart(
|
||||
private val einstein2 = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
email = "albert-einstein@email.com"
|
||||
)
|
||||
|
||||
private val article1 = ArticleForView(
|
||||
|
||||
@@ -7,7 +7,6 @@ import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.Citizen
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.vote.VoteAccessControl
|
||||
@@ -60,13 +59,13 @@ internal class `Vote Access Control` {
|
||||
followAnonymous = true
|
||||
)
|
||||
|
||||
private val einstein2 = CitizenCart(
|
||||
private val einstein2 = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
email = "albert-einstein@email.com"
|
||||
)
|
||||
|
||||
private val article1 = ArticleForView(
|
||||
|
||||
Reference in New Issue
Block a user