Verify tombstone event

This commit is contained in:
Florian Renaud 2022-08-17 16:20:06 +02:00
parent 725537d8fe
commit cbf9dbf290
3 changed files with 16 additions and 4 deletions

View File

@ -30,9 +30,11 @@ import org.amshove.kluent.shouldBeEqualTo
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
import org.matrix.android.sdk.api.session.room.model.tombstone.RoomTombstoneContent
import org.matrix.android.sdk.internal.database.awaitNotEmptyResult
@ -103,6 +105,7 @@ internal class DefaultCreateRoomFromLocalRoomTaskTest {
val result = defaultCreateRoomFromLocalRoomTask.execute(params)
// Then
verifyTombstoneEvent(AN_EXISTING_ROOM_ID)
result shouldBeEqualTo AN_EXISTING_ROOM_ID
}
@ -124,6 +127,7 @@ internal class DefaultCreateRoomFromLocalRoomTaskTest {
val result = defaultCreateRoomFromLocalRoomTask.execute(params)
// Then
verifyTombstoneEvent(null)
// CreateRoomTask has been called with the initial CreateRoomParams
coVerify { createRoomTask.execute(aCreateRoomParams) }
// The resulting roomId matches the roomId returned by the createRoomTask
@ -144,4 +148,11 @@ internal class DefaultCreateRoomFromLocalRoomTaskTest {
.findFirst()
} returns localRoomSummaryEntity
}
private fun verifyTombstoneEvent(expectedRoomId: String?) {
fakeStateEventDataSource.verifyGetStateEvent(A_LOCAL_ROOM_ID, EventType.STATE_ROOM_TOMBSTONE, QueryStringValue.IsEmpty)
fakeStateEventDataSource.instance.getStateEvent(A_LOCAL_ROOM_ID, EventType.STATE_ROOM_TOMBSTONE, QueryStringValue.IsEmpty)
?.content.toModel<RoomTombstoneContent>()
?.replacementRoomId shouldBeEqualTo expectedRoomId
}
}

View File

@ -22,6 +22,7 @@ import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.junit.After
import org.junit.Test
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toContent
@ -69,7 +70,7 @@ class DefaultGetActiveBeaconInfoForUserTaskTest {
fakeStateEventDataSource.verifyGetStateEvent(
roomId = params.roomId,
eventType = EventType.STATE_ROOM_BEACON_INFO.first(),
stateKey = A_USER_ID
stateKey = QueryStringValue.Equals(A_USER_ID)
)
}
}

View File

@ -19,7 +19,7 @@ package org.matrix.android.sdk.test.fakes
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.QueryStateEventValue
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
@ -37,12 +37,12 @@ internal class FakeStateEventDataSource {
} returns event
}
fun verifyGetStateEvent(roomId: String, eventType: String, stateKey: String) {
fun verifyGetStateEvent(roomId: String, eventType: String, stateKey: QueryStateEventValue) {
verify {
instance.getStateEvent(
roomId = roomId,
eventType = eventType,
stateKey = QueryStringValue.Equals(stateKey)
stateKey = stateKey
)
}
}