#42 Improve VoteVoter
This commit is contained in:
@@ -48,6 +48,23 @@ internal class CommentVoterTest {
|
||||
target = article1
|
||||
)
|
||||
|
||||
private val commentTargetDeleted = Comment(
|
||||
content = "Hello",
|
||||
createdBy = tesla,
|
||||
target = Article(
|
||||
content = "Hi",
|
||||
createdBy = einstein,
|
||||
description = "blablabla",
|
||||
title = "Super article"
|
||||
).apply { deletedAt = DateTime.now() }
|
||||
)
|
||||
|
||||
private val commentTargetNoUser = Comment(
|
||||
content = "Hello",
|
||||
createdBy = tesla,
|
||||
target = ArticleRef()
|
||||
)
|
||||
|
||||
init {
|
||||
mockkStatic("fr.dcproject.security.voter.VoterKt")
|
||||
}
|
||||
@@ -65,7 +82,7 @@ internal class CommentVoterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can be view the comment`() = listOf(CommentVoter()).run {
|
||||
fun `can be view the comment`() = listOf(CommentVoter(), ArticleVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { user } returns tesla.user
|
||||
}.let {
|
||||
@@ -110,7 +127,7 @@ internal class CommentVoterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can be create a comment`() = listOf(CommentVoter()).run {
|
||||
fun `can be create a comment`() = listOf(CommentVoter(), ArticleVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { user } returns tesla.user
|
||||
}.let {
|
||||
@@ -118,6 +135,24 @@ internal class CommentVoterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can not be create a comment if target is deleted`() = listOf(CommentVoter(), ArticleVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { user } returns tesla.user
|
||||
}.let {
|
||||
can(CommentVoter.Action.CREATE, it, commentTargetDeleted) `should be` false
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can not be create a comment if target has no user`() = listOf(CommentVoter(), ArticleVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { user } returns tesla.user
|
||||
}.let {
|
||||
can(CommentVoter.Action.CREATE, it, commentTargetNoUser) `should be` false
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can not be create a comment with other creator`() = listOf(CommentVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
|
||||
@@ -52,6 +52,23 @@ internal class VoteVoterTest {
|
||||
note = 1
|
||||
)
|
||||
|
||||
private val voteOnDeleted = VoteEntity(
|
||||
createdBy = tesla,
|
||||
target = Article(
|
||||
content = "Hi",
|
||||
createdBy = einstein,
|
||||
description = "blablabla",
|
||||
title = "Super article"
|
||||
).apply { deletedAt = DateTime.now() },
|
||||
note = 1
|
||||
)
|
||||
|
||||
private val voteWithoutUser = VoteEntity(
|
||||
createdBy = tesla,
|
||||
target = ArticleRef(),
|
||||
note = 1
|
||||
)
|
||||
|
||||
init {
|
||||
mockkStatic("fr.dcproject.security.voter.VoterKt")
|
||||
}
|
||||
@@ -105,7 +122,7 @@ internal class VoteVoterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can be vote an article`() = listOf(VoteVoter()).run {
|
||||
fun `can be vote an article`() = listOf(VoteVoter(), ArticleVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { user } returns tesla.user
|
||||
}.let {
|
||||
@@ -121,4 +138,31 @@ internal class VoteVoterTest {
|
||||
can(VoteVoter.Action.CREATE, it, vote1) `should be` false
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can not be vote an article if article is deleted`() = listOf(VoteVoter(), ArticleVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { user } returns tesla.user
|
||||
}.let {
|
||||
can(VoteVoter.Action.CREATE, it, voteOnDeleted) `should be` false
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can not be vote an article if article have no user`() = listOf(VoteVoter(), ArticleVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { user } returns tesla.user
|
||||
}.let {
|
||||
can(VoteVoter.Action.CREATE, it, voteWithoutUser) `should be` false
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can not be comment an article if article is deleted`() = listOf(VoteVoter(), ArticleVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { user } returns tesla.user
|
||||
}.let {
|
||||
can(CommentVoter.Action.CREATE, it, voteOnDeleted) `should be` false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user