code review
This commit is contained in:
		
							parent
							
								
									c06eca6936
								
							
						
					
					
						commit
						bec8b5f71e
					
				@ -19,17 +19,17 @@ package org.matrix.android.sdk.internal.database.mapper
 | 
			
		||||
import io.mockk.every
 | 
			
		||||
import io.mockk.mockk
 | 
			
		||||
import io.realm.RealmList
 | 
			
		||||
import org.amshove.kluent.shouldBe
 | 
			
		||||
import org.amshove.kluent.shouldBeEqualTo
 | 
			
		||||
import org.amshove.kluent.shouldNotBe
 | 
			
		||||
import org.junit.Test
 | 
			
		||||
import org.matrix.android.sdk.internal.database.model.EditAggregatedSummaryEntity
 | 
			
		||||
import org.matrix.android.sdk.internal.database.model.EditionOfEvent
 | 
			
		||||
import org.matrix.android.sdk.internal.database.model.EventEntity
 | 
			
		||||
 | 
			
		||||
class EditAggregationSummaryMapperTest {
 | 
			
		||||
class EditAggregatedSummaryEntityMapperTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    fun test() {
 | 
			
		||||
    fun `test mapping summary entity to model`() {
 | 
			
		||||
        val edits = RealmList<EditionOfEvent>(
 | 
			
		||||
                EditionOfEvent(
 | 
			
		||||
                        timestamp = 0L,
 | 
			
		||||
@ -56,12 +56,48 @@ class EditAggregationSummaryMapperTest {
 | 
			
		||||
 | 
			
		||||
        val mapped = EditAggregatedSummaryEntityMapper.map(fakeSummaryEntity)
 | 
			
		||||
        mapped shouldNotBe null
 | 
			
		||||
        mapped!!.sourceEvents.size shouldBe 2
 | 
			
		||||
        mapped.localEchos.size shouldBe 1
 | 
			
		||||
        mapped.localEchos.first() shouldBe "e2"
 | 
			
		||||
        mapped!!.sourceEvents.size shouldBeEqualTo 2
 | 
			
		||||
        mapped.localEchos.size shouldBeEqualTo 1
 | 
			
		||||
        mapped.localEchos.first() shouldBeEqualTo "e2"
 | 
			
		||||
 | 
			
		||||
        mapped.lastEditTs shouldBe 30L
 | 
			
		||||
        mapped.latestEdit?.eventId shouldBe "e2"
 | 
			
		||||
        mapped.lastEditTs shouldBeEqualTo 30L
 | 
			
		||||
        mapped.latestEdit?.eventId shouldBeEqualTo "e2"
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    fun `event with lexicographically largest event_id is treated as more recent`() {
 | 
			
		||||
        val lowerId = "\$Albatross"
 | 
			
		||||
        val higherId = "\$Zebra"
 | 
			
		||||
 | 
			
		||||
        (higherId > lowerId) shouldBeEqualTo true
 | 
			
		||||
        val timestamp = 1669288766745L
 | 
			
		||||
        val edits = RealmList<EditionOfEvent>(
 | 
			
		||||
                EditionOfEvent(
 | 
			
		||||
                        timestamp = timestamp,
 | 
			
		||||
                        eventId = lowerId,
 | 
			
		||||
                        isLocalEcho = false,
 | 
			
		||||
                        event = mockEvent(lowerId)
 | 
			
		||||
                ),
 | 
			
		||||
                EditionOfEvent(
 | 
			
		||||
                        timestamp = timestamp,
 | 
			
		||||
                        eventId = higherId,
 | 
			
		||||
                        isLocalEcho = false,
 | 
			
		||||
                        event = mockEvent(higherId)
 | 
			
		||||
                ),
 | 
			
		||||
                EditionOfEvent(
 | 
			
		||||
                        timestamp = 1L,
 | 
			
		||||
                        eventId = "e2",
 | 
			
		||||
                        isLocalEcho = true,
 | 
			
		||||
                        event = mockEvent("e2")
 | 
			
		||||
                )
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        val fakeSummaryEntity = mockk<EditAggregatedSummaryEntity> {
 | 
			
		||||
            every { editions } returns edits
 | 
			
		||||
        }
 | 
			
		||||
        val mapped = EditAggregatedSummaryEntityMapper.map(fakeSummaryEntity)
 | 
			
		||||
        mapped!!.lastEditTs shouldBeEqualTo timestamp
 | 
			
		||||
        mapped.latestEdit?.eventId shouldBeEqualTo higherId
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun mockEvent(eventId: String): EventEntity {
 | 
			
		||||
@ -31,7 +31,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageTextContent
 | 
			
		||||
 | 
			
		||||
class ValidDecryptedEventTest {
 | 
			
		||||
 | 
			
		||||
    val fakeEvent = Event(
 | 
			
		||||
    private val fakeEvent = Event(
 | 
			
		||||
            type = EventType.ENCRYPTED,
 | 
			
		||||
            eventId = "\$eventId",
 | 
			
		||||
            roomId = "!fakeRoom",
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user