-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e53fa9d
commit cb4a308
Showing
3 changed files
with
130 additions
and
62 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...rtemis/native_app/feature/metis/conversation/service/storage/impl/MetisStorageBaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.storage.impl | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
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.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 | ||
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.db.pojo.AnswerPostPojo | ||
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.db.pojo.PostPojo | ||
import de.tum.informatics.www1.artemis.native_app.feature.metistest.MetisDatabaseProviderMock | ||
import kotlinx.datetime.Clock | ||
|
||
abstract class MetisStorageBaseTest { | ||
|
||
private val databaseProviderMock = MetisDatabaseProviderMock(InstrumentationRegistry.getInstrumentation().context) | ||
internal val sut = MetisStorageServiceImpl(databaseProviderMock) | ||
|
||
internal val host = "host" | ||
|
||
private val author = User(id = 20, name = "AuthorName") | ||
private val parentClientPostId = "parent-client-id-0" | ||
internal val answerClientPostId = "answer-client-id-0" | ||
|
||
private val course: MetisContext.Course = MetisContext.Course(courseId = 1) | ||
internal val conversation = OneToOneChat(id = 2) | ||
internal val metisContext = MetisContext.Conversation(course.courseId, conversation.id) | ||
|
||
internal val localAnswerPojo = AnswerPostPojo( | ||
parentPostId = parentClientPostId, | ||
postId = answerClientPostId, | ||
resolvesPost = false, | ||
basePostingCache = AnswerPostPojo.BasePostingCache( | ||
serverPostId = 0, | ||
authorId = author.id, | ||
creationDate = Clock.System.now(), | ||
updatedDate = null, | ||
content = "Answer post content 0", | ||
authorRole = UserRole.USER, | ||
authorName = author.name!! | ||
), | ||
reactions = emptyList(), | ||
serverPostIdCache = AnswerPostPojo.ServerPostIdCache( | ||
serverPostId = null // Only local answer post, no server id | ||
) | ||
) | ||
|
||
internal val basePostPojo = PostPojo( | ||
clientPostId = parentClientPostId, | ||
serverPostId = 0, | ||
content = "Base post content", | ||
resolved = false, | ||
updatedDate = null, | ||
creationDate = Clock.System.now(), | ||
authorId = author.id, | ||
title = null, | ||
authorName = author.name!!, | ||
authorRole = UserRole.USER, | ||
courseWideContext = null, | ||
tags = emptyList(), | ||
answers = emptyList(), | ||
reactions = emptyList() | ||
) | ||
|
||
internal val basePost = StandalonePost(basePostPojo, conversation) | ||
internal val localAnswer = AnswerPost(localAnswerPojo, basePost) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...pp/feature/metis/conversation/service/storage/impl/MetisStorageServiceTestLiveCreation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.storage.impl | ||
|
||
import de.tum.informatics.www1.artemis.native_app.core.common.test.UnitTest | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Test | ||
import org.junit.experimental.categories.Category | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@Category(UnitTest::class) | ||
@RunWith(RobolectricTestRunner::class) | ||
class MetisStorageServiceTestLiveCreation : MetisStorageBaseTest() { | ||
|
||
@Test | ||
fun testInsertLiveCreatedPostWithExistingPost() = runTest { | ||
// GIVEN: A base post already exists | ||
sut.insertOrUpdatePosts( | ||
host = host, | ||
metisContext = metisContext, | ||
posts = listOf(basePost), | ||
) | ||
|
||
// WHEN: Inserting a live-created post | ||
sut.insertLiveCreatedPost( | ||
host = host, | ||
metisContext = metisContext, | ||
post = basePost | ||
) | ||
|
||
// THEN: No post should be inserted and the existing posts should not be modified | ||
assertStoredContentIsNotModified() | ||
} | ||
|
||
@Test | ||
fun testInsertLiveCreatedPost() = runTest { | ||
// GIVEN: An empty chat | ||
|
||
// WHEN: Inserting a live-created post | ||
sut.insertLiveCreatedPost( | ||
host = host, | ||
metisContext = metisContext, | ||
post = basePost | ||
) | ||
|
||
// THEN: The post should be inserted and matched to the correct conversation | ||
assertPostIsCreated() | ||
assertPostIsMatchedToConversation() | ||
} | ||
|
||
private fun assertPostIsCreated() { | ||
//TODO | ||
} | ||
|
||
private fun assertStoredContentIsNotModified() { | ||
//TODO | ||
} | ||
|
||
private fun assertPostIsMatchedToConversation() { | ||
//TODO | ||
} | ||
} |