Skip to content

Commit

Permalink
fixed tests and changed pin function in metis modification service
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-wls committed Nov 27, 2024
1 parent 436c2bc commit d755c7e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.se
import de.tum.informatics.www1.artemis.native_app.core.data.NetworkResponse
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.MetisContext
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.AnswerPost
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.DisplayPriority
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.Reaction
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.StandalonePost

Expand All @@ -28,7 +27,6 @@ interface MetisModificationService {
suspend fun updatePostDisplayPriority(
context: MetisContext,
post: StandalonePost,
displayPriority: DisplayPriority,
serverUrl: String,
authToken: String
): NetworkResponse<StandalonePost>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.ser
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.network.RESOURCE_PATH_SEGMENTS
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.MetisContext
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.AnswerPost
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.DisplayPriority
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.Reaction
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.StandalonePost
import io.ktor.client.call.body
Expand Down Expand Up @@ -102,7 +101,6 @@ internal class MetisModificationServiceImpl(
override suspend fun updatePostDisplayPriority(
context: MetisContext,
post: StandalonePost,
displayPriority: DisplayPriority,
serverUrl: String,
authToken: String
): NetworkResponse<StandalonePost> {
Expand All @@ -119,7 +117,7 @@ internal class MetisModificationServiceImpl(
}

contentType(ContentType.Application.Json)
parameter("displayPriority", displayPriority)
parameter("displayPriority", post.displayPriority)
cookieAuth(authToken)
}.body()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ internal open class ConversationViewModel(
metisModificationService.updatePostDisplayPriority(
context = metisContext,
post = newPost,
displayPriority = newDisplayPriority,
serverUrl = serverConfigurationService.serverUrl.first(),
authToken = accountService.authToken.first(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import de.tum.informatics.www1.artemis.native_app.core.test.BaseComposeTest
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.MetisModificationFailure
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.impl.EmojiServiceStub
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.ui.thread.MetisThreadUi
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.DisplayPriority
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.IBasePost
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.UserRole
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.conversation.OneToOneChat
Expand Down Expand Up @@ -62,7 +63,8 @@ abstract class BaseThreadUITest : BaseComposeTest() {
courseWideContext = null,
tags = emptyList(),
answers = if (index == 0) answers else emptyList(),
reactions = emptyList()
reactions = emptyList(),
displayPriority = DisplayPriority.NONE
)
}

Expand All @@ -86,6 +88,7 @@ abstract class BaseThreadUITest : BaseComposeTest() {
onCreatePost = { CompletableDeferred() },
onEditPost = { _, _ -> CompletableDeferred() },
onResolvePost = onResolvePost,
onPinPost = { CompletableDeferred() },
onDeletePost = { CompletableDeferred() },
onRequestReactWithEmoji = { _, _, _ -> CompletableDeferred() },
onRequestReload = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package de.tum.informatics.www1.artemis.native_app.feature.metis.conversation

import de.tum.informatics.www1.artemis.native_app.core.common.test.DefaultTestTimeoutMillis
import de.tum.informatics.www1.artemis.native_app.core.common.test.EndToEndTest
import de.tum.informatics.www1.artemis.native_app.core.common.test.testServerUrl
import de.tum.informatics.www1.artemis.native_app.core.data.NetworkResponse
import de.tum.informatics.www1.artemis.native_app.core.common.test.DefaultTestTimeoutMillis
import de.tum.informatics.www1.artemis.native_app.core.test.test_setup.DefaultTimeoutMillis
import de.tum.informatics.www1.artemis.native_app.core.common.test.testServerUrl
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.MetisSortingStrategy
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.network.MetisModificationService
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.network.MetisService
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.ui.post.predefinedEmojiIds
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.MetisSortingStrategy
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.DisplayPriority
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.StandalonePost
import kotlinx.coroutines.test.runTest
import org.junit.Test
Expand Down Expand Up @@ -224,4 +225,24 @@ class ConversationMessagesE2eTest : ConversationMessagesBaseTest() {
assertEquals(newText, editedPost.content, "Edited post does not have the updated text content")
}
}

@Test
fun `can pin message`() {
runTest(timeout = DefaultTimeoutMillis.milliseconds * 4) {
val basePost = postDefaultMessage()

metisModificationService.updatePostDisplayPriority(
metisContext,
basePost.copy(displayPriority = DisplayPriority.PINNED),
testServerUrl,
accessToken
).orThrow("Could not pin message")

val editedPost = metisService
.getPost(metisContext, basePost.serverPostId!!, testServerUrl, accessToken)
.orThrow("Could not download pinned post")

assertEquals(DisplayPriority.PINNED, editedPost.displayPriority, "Edited post does not have the updated display priority")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import de.tum.informatics.www1.artemis.native_app.core.common.test.UnitTest
import de.tum.informatics.www1.artemis.native_app.core.model.account.User
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.MetisContext
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.AnswerPost
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.DisplayPriority
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.StandalonePost
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.UserRole
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.dto.conversation.OneToOneChat
Expand Down Expand Up @@ -73,7 +74,8 @@ class MetisStorageServiceImplUpgradeLocalAnswerPostTest {
courseWideContext = null,
tags = emptyList(),
answers = emptyList(),
reactions = emptyList()
reactions = emptyList(),
displayPriority = DisplayPriority.NONE
)

private val basePost = StandalonePost(basePostPojo, conversation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import de.tum.informatics.www1.artemis.native_app.core.common.test.EndToEndTest
import de.tum.informatics.www1.artemis.native_app.core.common.test.UnitTest
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.BaseThreadUITest
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.TestInitialReplyTextProvider
Expand Down Expand Up @@ -74,6 +73,7 @@ class ReplyTextFieldVisibilityUITest : BaseThreadUITest() {
isReplyEnabled = true,
onCreatePost = { CompletableDeferred() },
onEditPost = { _, _ -> CompletableDeferred() },
onPinPost = { CompletableDeferred() },
onDeletePost = { CompletableDeferred() },
onRequestReactWithEmoji = { _, _, _ -> CompletableDeferred() },
onClickViewPost = {},
Expand Down

0 comments on commit d755c7e

Please sign in to comment.