Skip to content

Commit

Permalink
Enable moderators to delete posts
Browse files Browse the repository at this point in the history
  • Loading branch information
FelberMartin committed Nov 19, 2024
1 parent 313d711 commit 6f9b29b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun rememberPostActions(

PostActions(
requestEditPost = if (doesPostExistOnServer && hasEditPostRights) onRequestEdit else null,
requestDeletePost = if (hasEditPostRights) onRequestDelete else null,
requestDeletePost = if (hasModerationRights) onRequestDelete else null,
onClickReaction = if (doesPostExistOnServer) onClickReaction else null,
onCopyText = {
clipboardManager.setText(AnnotatedString(post.content.orEmpty()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.junit.runner.RunWith
class PostActionsTest : BaseComposeTest() {

private val EDIT_POST = {}
private val DELETE_POST = {}

private val author = User(id = 1)
private val instructor = User(id = 2)
Expand All @@ -31,7 +32,7 @@ class PostActionsTest : BaseComposeTest() {
fun `test GIVEN a post WHEN calling rememberPostActions as the post author THEN onRequestEditPost is not null`() {
composeTestRule.setContent {
val postActions = createPostActions(
editorId = author.id,
requestorId = author.id,
hasModerationRights = false
)

Expand All @@ -45,27 +46,40 @@ class PostActionsTest : BaseComposeTest() {
fun `test GIVEN a user with moderation-rights WHEN calling rememberPostActions THEN onRequestEditPost is null`() {
composeTestRule.setContent {
val postActions = createPostActions(
editorId = instructor.id,
requestorId = instructor.id,
hasModerationRights = true
)

assertNull(postActions.requestEditPost)
}
}

@Test
fun `test GIVEN a user with moderation-rights WHEN calling rememberPostActions THEN onRequestDeletePost is not null`() {
composeTestRule.setContent {
val postActions = createPostActions(
requestorId = instructor.id,
hasModerationRights = true
)

assertNotNull(postActions.requestDeletePost)
assertEquals(DELETE_POST, postActions.requestDeletePost)
}
}


@Composable
private fun createPostActions(
editorId: Long,
requestorId: Long,
hasModerationRights: Boolean = false,
): PostActions {
val postActions = rememberPostActions(
post = post,
hasModerationRights = hasModerationRights,
isAtLeastTutorInCourse = false,
clientId = editorId,
clientId = requestorId,
onRequestEdit = EDIT_POST,
onRequestDelete = {},
onRequestDelete = DELETE_POST,
onClickReaction = { _, _ -> },
onReplyInThread = {},
onResolvePost = {},
Expand Down

0 comments on commit 6f9b29b

Please sign in to comment.