From d755c7e75c7fe670d6c53dc7a8612ef1d06d9681 Mon Sep 17 00:00:00 2001 From: Julian Waluschyk Date: Wed, 27 Nov 2024 17:30:21 +0100 Subject: [PATCH] fixed tests and changed pin function in metis modification service --- .../network/MetisModificationService.kt | 2 -- .../impl/MetisModificationServiceImpl.kt | 4 +-- .../conversation/ui/ConversationViewModel.kt | 1 - .../metis/conversation/BaseThreadUITest.kt | 5 +++- .../ConversationMessagesE2eTest.kt | 27 ++++++++++++++++--- ...geServiceImplTestUpgradeLocalAnswerPost.kt | 4 ++- .../reply/ReplyTextFieldVisibilityUITest.kt | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/network/MetisModificationService.kt b/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/network/MetisModificationService.kt index e8c125573..84abc498f 100644 --- a/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/network/MetisModificationService.kt +++ b/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/network/MetisModificationService.kt @@ -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 @@ -28,7 +27,6 @@ interface MetisModificationService { suspend fun updatePostDisplayPriority( context: MetisContext, post: StandalonePost, - displayPriority: DisplayPriority, serverUrl: String, authToken: String ): NetworkResponse diff --git a/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/network/impl/MetisModificationServiceImpl.kt b/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/network/impl/MetisModificationServiceImpl.kt index c78a8272c..5d44502c5 100644 --- a/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/network/impl/MetisModificationServiceImpl.kt +++ b/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/network/impl/MetisModificationServiceImpl.kt @@ -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 @@ -102,7 +101,6 @@ internal class MetisModificationServiceImpl( override suspend fun updatePostDisplayPriority( context: MetisContext, post: StandalonePost, - displayPriority: DisplayPriority, serverUrl: String, authToken: String ): NetworkResponse { @@ -119,7 +117,7 @@ internal class MetisModificationServiceImpl( } contentType(ContentType.Application.Json) - parameter("displayPriority", displayPriority) + parameter("displayPriority", post.displayPriority) cookieAuth(authToken) }.body() } diff --git a/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/ConversationViewModel.kt b/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/ConversationViewModel.kt index 238be4c44..d33a6934f 100644 --- a/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/ConversationViewModel.kt +++ b/feature/metis/conversation/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/ConversationViewModel.kt @@ -390,7 +390,6 @@ internal open class ConversationViewModel( metisModificationService.updatePostDisplayPriority( context = metisContext, post = newPost, - displayPriority = newDisplayPriority, serverUrl = serverConfigurationService.serverUrl.first(), authToken = accountService.authToken.first(), ) diff --git a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/BaseThreadUITest.kt b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/BaseThreadUITest.kt index 49db524f3..7c203c6fd 100644 --- a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/BaseThreadUITest.kt +++ b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/BaseThreadUITest.kt @@ -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 @@ -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 ) } @@ -86,6 +88,7 @@ abstract class BaseThreadUITest : BaseComposeTest() { onCreatePost = { CompletableDeferred() }, onEditPost = { _, _ -> CompletableDeferred() }, onResolvePost = onResolvePost, + onPinPost = { CompletableDeferred() }, onDeletePost = { CompletableDeferred() }, onRequestReactWithEmoji = { _, _, _ -> CompletableDeferred() }, onRequestReload = {}, diff --git a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ConversationMessagesE2eTest.kt b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ConversationMessagesE2eTest.kt index 8de66cd36..ce7780fcf 100644 --- a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ConversationMessagesE2eTest.kt +++ b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ConversationMessagesE2eTest.kt @@ -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 @@ -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") + } + } } \ No newline at end of file diff --git a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/storage/impl/MetisStorageServiceImplTestUpgradeLocalAnswerPost.kt b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/storage/impl/MetisStorageServiceImplTestUpgradeLocalAnswerPost.kt index cbe8a8b9a..102e2f691 100644 --- a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/storage/impl/MetisStorageServiceImplTestUpgradeLocalAnswerPost.kt +++ b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/service/storage/impl/MetisStorageServiceImplTestUpgradeLocalAnswerPost.kt @@ -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 @@ -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) diff --git a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/reply/ReplyTextFieldVisibilityUITest.kt b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/reply/ReplyTextFieldVisibilityUITest.kt index 0ad718440..bc1869bc2 100644 --- a/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/reply/ReplyTextFieldVisibilityUITest.kt +++ b/feature/metis/conversation/src/test/kotlin/de/tum/informatics/www1/artemis/native_app/feature/metis/conversation/ui/reply/ReplyTextFieldVisibilityUITest.kt @@ -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 @@ -74,6 +73,7 @@ class ReplyTextFieldVisibilityUITest : BaseThreadUITest() { isReplyEnabled = true, onCreatePost = { CompletableDeferred() }, onEditPost = { _, _ -> CompletableDeferred() }, + onPinPost = { CompletableDeferred() }, onDeletePost = { CompletableDeferred() }, onRequestReactWithEmoji = { _, _, _ -> CompletableDeferred() }, onClickViewPost = {},