Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Nov 24, 2022
1 parent c06eca6 commit bec8b5f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit bec8b5f

Please sign in to comment.