porting notification tests to the engine

This commit is contained in:
Adam Brown 2022-10-12 21:05:56 +01:00
parent 4d033230e4
commit 709d6c0e1f
20 changed files with 106 additions and 68 deletions

View File

@ -5,6 +5,7 @@ import app.dapk.st.matrix.common.RoomId
import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
import test.delegateEmit
import test.delegateReturn
import java.io.InputStream
@ -16,4 +17,8 @@ class FakeChatEngine : ChatEngine by mockk() {
fun givenImportKeys(inputStream: InputStream, passphrase: String) = coEvery { inputStream.importRoomKeys(passphrase) }.delegateReturn()
fun givenNotificationsInvites() = every { notificationsInvites() }.delegateEmit()
fun givenNotificationsMessages() = every { notificationsMessages() }.delegateEmit()
}

View File

@ -29,3 +29,38 @@ fun anEncryptedRoomMessageEvent(
edited: Boolean = false,
redacted: Boolean = false,
) = RoomEvent.Message(eventId, utcTimestamp, content, author, meta, edited, redacted)
fun aRoomImageMessageEvent(
eventId: EventId = anEventId(),
utcTimestamp: Long = 0L,
content: RoomEvent.Image.ImageMeta = anImageMeta(),
author: RoomMember = aRoomMember(),
meta: MessageMeta = MessageMeta.FromServer,
edited: Boolean = false,
) = RoomEvent.Image(eventId, utcTimestamp, content, author, meta, edited)
fun aRoomReplyMessageEvent(
message: RoomEvent = aRoomMessageEvent(),
replyingTo: RoomEvent = aRoomMessageEvent(eventId = anEventId("in-reply-to-id")),
) = RoomEvent.Reply(message, replyingTo)
fun aRoomMessageEvent(
eventId: EventId = anEventId(),
utcTimestamp: Long = 0L,
content: String = "message-content",
author: RoomMember = aRoomMember(),
meta: MessageMeta = MessageMeta.FromServer,
edited: Boolean = false,
) = RoomEvent.Message(eventId, utcTimestamp, content, author, meta, edited)
fun anImageMeta(
width: Int? = 100,
height: Int? = 100,
url: String = "https://a-url.com",
keys: RoomEvent.Image.ImageMeta.Keys? = null
) = RoomEvent.Image.ImageMeta(width, height, url, keys)
fun aRoomState(
roomOverview: RoomOverview = aRoomOverview(),
events: List<RoomEvent> = listOf(aRoomMessageEvent()),
) = RoomState(roomOverview, events)

View File

@ -4,8 +4,8 @@ import android.app.Notification
import android.app.PendingIntent
import android.os.Build
import app.dapk.st.core.DeviceMeta
import app.dapk.st.engine.RoomOverview
import app.dapk.st.matrix.common.AvatarUrl
import app.dapk.st.matrix.sync.RoomOverview
import fake.FakeContext
import fixture.NotificationDelegateFixtures.anAndroidNotification
import fixture.NotificationDelegateFixtures.anInboxStyle

View File

@ -1,8 +1,8 @@
package app.dapk.st.notifications
import app.dapk.st.engine.RoomEvent
import app.dapk.st.engine.RoomOverview
import app.dapk.st.matrix.common.RoomId
import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomOverview
import fake.FakeNotificationFactory
import fake.FakeNotificationManager
import fake.aFakeNotification

View File

@ -1,9 +1,9 @@
package app.dapk.st.notifications
import android.content.Context
import app.dapk.st.engine.RoomEvent
import app.dapk.st.engine.RoomOverview
import app.dapk.st.matrix.common.RoomId
import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomOverview
import app.dapk.st.navigator.IntentFactory
import fixture.NotificationDelegateFixtures.anAndroidNotification
import fixture.NotificationFixtures.aDismissRoomNotification

View File

@ -15,8 +15,6 @@ class RenderNotificationsUseCaseTest {
private val fakeNotificationMessageRenderer = FakeNotificationMessageRenderer()
private val fakeNotificationInviteRenderer = FakeNotificationInviteRenderer()
private val fakeObserveUnreadNotificationsUseCase = FakeObserveUnreadNotificationsUseCase()
private val fakeObserveInviteNotificationsUseCase = FakeObserveInviteNotificationsUseCase()
private val fakeNotificationChannels = FakeNotificationChannels().also {
it.instance.expect { it.initChannels() }
}
@ -32,8 +30,8 @@ class RenderNotificationsUseCaseTest {
@Test
fun `given events, when listening for changes then initiates channels once`() = runTest {
fakeNotificationMessageRenderer.instance.expect { it.render(any()) }
fakeObserveUnreadNotificationsUseCase.given().emits(AN_UNREAD_NOTIFICATIONS)
fakeObserveInviteNotificationsUseCase.given().emits()
fakeChatEngine.givenNotificationsMessages().emits(AN_UNREAD_NOTIFICATIONS)
fakeChatEngine.givenNotificationsInvites().emits()
renderNotificationsUseCase.listenForNotificationChanges(TestScope(UnconfinedTestDispatcher()))
@ -43,8 +41,8 @@ class RenderNotificationsUseCaseTest {
@Test
fun `given renderable unread events, when listening for changes, then renders change`() = runTest {
fakeNotificationMessageRenderer.instance.expect { it.render(any()) }
fakeObserveUnreadNotificationsUseCase.given().emits(AN_UNREAD_NOTIFICATIONS)
fakeObserveInviteNotificationsUseCase.given().emits()
fakeChatEngine.givenNotificationsMessages().emits(AN_UNREAD_NOTIFICATIONS)
fakeChatEngine.givenNotificationsInvites().emits()
renderNotificationsUseCase.listenForNotificationChanges(TestScope(UnconfinedTestDispatcher()))

View File

@ -27,8 +27,8 @@ class LocalEchoMapperTest {
result shouldBeEqualTo aRoomMessageEvent(
eventId = echo.eventId!!,
content = AN_ECHO_CONTENT.content.body,
meta = A_META
).engine()
meta = A_META.engine()
)
}
@Test
@ -40,20 +40,20 @@ class LocalEchoMapperTest {
result shouldBeEqualTo aRoomMessageEvent(
eventId = anEventId(echo.localId),
content = AN_ECHO_CONTENT.content.body,
meta = A_META
).engine()
meta = A_META.engine()
)
}
@Test
fun `when merging with echo then updates meta with the echos meta`() = runWith(localEchoMapper) {
val previousMeta = MessageMeta.LocalEcho("previous", MessageMeta.LocalEcho.State.Sending)
val event = aRoomMessageEvent(meta = previousMeta).engine()
val previousMeta = MessageMeta.LocalEcho("previous", MessageMeta.LocalEcho.State.Sending).engine()
val event = aRoomMessageEvent(meta = previousMeta)
val echo = aLocalEcho()
fakeMetaMapper.given(echo).returns(A_META.engine() as app.dapk.st.engine.MessageMeta.LocalEcho)
val result = event.mergeWith(echo)
result shouldBeEqualTo aRoomMessageEvent(meta = A_META).engine()
result shouldBeEqualTo aRoomMessageEvent(meta = A_META.engine())
}
private fun givenEcho(eventId: EventId? = null, localId: String = "", meta: MessageMeta.LocalEcho = A_META): MessageService.LocalEcho {

View File

@ -20,7 +20,7 @@ class MergeWithLocalEchosUseCaseTest {
@Test
fun `given no local echos, when merging text message, then returns original state`() {
val roomState = aRoomState(events = listOf(A_ROOM_MESSAGE_EVENT)).engine()
val roomState = aRoomState(events = listOf(A_ROOM_MESSAGE_EVENT))
val result = mergeWithLocalEchosUseCase.invoke(roomState, A_ROOM_MEMBER, emptyList())
@ -29,7 +29,7 @@ class MergeWithLocalEchosUseCaseTest {
@Test
fun `given no local echos, when merging events, then returns original ordered by timestamp descending`() {
val roomState = aRoomState(events = listOf(A_ROOM_IMAGE_MESSAGE_EVENT.copy(utcTimestamp = 1500), A_ROOM_MESSAGE_EVENT.copy(utcTimestamp = 1000))).engine()
val roomState = aRoomState(events = listOf(A_ROOM_IMAGE_MESSAGE_EVENT.copy(utcTimestamp = 1500), A_ROOM_MESSAGE_EVENT.copy(utcTimestamp = 1000)))
val result = mergeWithLocalEchosUseCase.invoke(roomState, A_ROOM_MEMBER, emptyList())
@ -39,15 +39,15 @@ class MergeWithLocalEchosUseCaseTest {
@Test
fun `given local echo with sending state, when merging then maps to room event with local echo state`() {
val second = createLocalEcho(A_LOCAL_ECHO_EVENT_ID, A_LOCAL_ECHO_BODY, state = MessageService.LocalEcho.State.Sending)
fakeLocalEchoMapper.givenMapping(second, A_ROOM_MEMBER).returns(ANOTHER_ROOM_MESSAGE_EVENT.engine())
val roomState = aRoomState(events = listOf(A_ROOM_MESSAGE_EVENT)).engine()
fakeLocalEchoMapper.givenMapping(second, A_ROOM_MEMBER).returns(ANOTHER_ROOM_MESSAGE_EVENT)
val roomState = aRoomState(events = listOf(A_ROOM_MESSAGE_EVENT))
val result = mergeWithLocalEchosUseCase.invoke(roomState, A_ROOM_MEMBER, listOf(second))
result shouldBeEqualTo roomState.copy(
events = listOf(
A_ROOM_MESSAGE_EVENT.engine(),
ANOTHER_ROOM_MESSAGE_EVENT.engine(),
A_ROOM_MESSAGE_EVENT,
ANOTHER_ROOM_MESSAGE_EVENT,
)
)
}

View File

@ -2,9 +2,9 @@ package app.dapk.st.engine
import fake.FakeRoomStore
import fixture.NotificationDiffFixtures.aNotificationDiff
import fixture.aMatrixRoomMessageEvent
import fixture.aMatrixRoomOverview
import fixture.aRoomId
import fixture.aRoomMessageEvent
import fixture.anEventId
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.toList
@ -15,8 +15,8 @@ import app.dapk.st.matrix.sync.RoomEvent as MatrixRoomEvent
import app.dapk.st.matrix.sync.RoomOverview as MatrixRoomOverview
private val NO_UNREADS = emptyMap<MatrixRoomOverview, List<MatrixRoomEvent>>()
private val A_MESSAGE = aRoomMessageEvent(eventId = anEventId("1"), content = "hello", utcTimestamp = 1000)
private val A_MESSAGE_2 = aRoomMessageEvent(eventId = anEventId("2"), content = "world", utcTimestamp = 2000)
private val A_MESSAGE = aMatrixRoomMessageEvent(eventId = anEventId("1"), content = "hello", utcTimestamp = 1000)
private val A_MESSAGE_2 = aMatrixRoomMessageEvent(eventId = anEventId("2"), content = "world", utcTimestamp = 2000)
private val A_ROOM_OVERVIEW = aMatrixRoomOverview(roomId = aRoomId("1"))
private val A_ROOM_OVERVIEW_2 = aMatrixRoomOverview(roomId = aRoomId("2"))

View File

@ -23,8 +23,8 @@ import test.delegateReturn
private val A_ROOM_ID = aRoomId()
private val AN_USER_ID = aUserId()
private val A_ROOM_STATE = aRoomState()
private val A_MERGED_ROOM_STATE = A_ROOM_STATE.copy(events = listOf(aRoomMessageEvent(content = "a merged event")))
private val A_ROOM_STATE = aMatrixRoomState()
private val A_MERGED_ROOM_STATE = A_ROOM_STATE.copy(events = listOf(aMatrixRoomMessageEvent(content = "a merged event")))
private val A_LOCAL_ECHOS_LIST = listOf(aLocalEcho())
private val A_ROOM_MEMBER = aRoomMember()

View File

@ -5,6 +5,6 @@ import io.mockk.coEvery
import io.mockk.mockk
import test.delegateEmit
class FakeObserveInviteNotificationsUseCase : app.dapk.st.engine.ObserveInviteNotificationsUseCase by mockk() {
class FakeObserveInviteNotificationsUseCase : ObserveInviteNotificationsUseCase by mockk() {
fun given() = coEvery { this@FakeObserveInviteNotificationsUseCase.invoke() }.delegateEmit()
}

View File

@ -5,6 +5,6 @@ import io.mockk.coEvery
import io.mockk.mockk
import test.delegateEmit
class FakeObserveUnreadNotificationsUseCase : app.dapk.st.engine.ObserveUnreadNotificationsUseCase by mockk() {
class FakeObserveUnreadNotificationsUseCase : ObserveUnreadNotificationsUseCase by mockk() {
fun given() = coEvery { this@FakeObserveUnreadNotificationsUseCase.invoke() }.delegateEmit()
}

View File

@ -15,7 +15,7 @@ import org.junit.Test
private const val A_DECRYPTED_MESSAGE_CONTENT = "decrypted - content"
private val AN_ENCRYPTED_ROOM_CONTENT = aMegolmV1()
private val AN_ENCRYPTED_ROOM_MESSAGE = aRoomMessageEvent(encryptedContent = AN_ENCRYPTED_ROOM_CONTENT)
private val AN_ENCRYPTED_ROOM_MESSAGE = aMatrixRoomMessageEvent(encryptedContent = AN_ENCRYPTED_ROOM_CONTENT)
private val AN_ENCRYPTED_ROOM_REPLY = aRoomReplyMessageEvent(
message = AN_ENCRYPTED_ROOM_MESSAGE,
replyingTo = AN_ENCRYPTED_ROOM_MESSAGE.copy(eventId = anEventId("other-event"))
@ -37,7 +37,7 @@ class RoomEventsDecrypterTest {
@Test
fun `given clear message event, when decrypting, then does nothing`() = runTest {
val aClearMessageEvent = aRoomMessageEvent(encryptedContent = null)
val aClearMessageEvent = aMatrixRoomMessageEvent(encryptedContent = null)
val result = roomEventsDecrypter.decryptRoomEvents(A_USER_CREDENTIALS, listOf(aClearMessageEvent))
result shouldBeEqualTo listOf(aClearMessageEvent)

View File

@ -1,7 +1,7 @@
package app.dapk.st.matrix.sync.internal.sync
import fake.FakeRoomStore
import fixture.aRoomMessageEvent
import fixture.aMatrixRoomMessageEvent
import fixture.anEventId
import internalfixture.aTimelineTextEventContent
import internalfixture.anApiTimelineTextEvent
@ -11,8 +11,8 @@ import org.junit.Test
private val AN_EVENT_ID = anEventId()
private val A_TIMELINE_EVENT = anApiTimelineTextEvent(AN_EVENT_ID, content = aTimelineTextEventContent(body = "timeline event"))
private val A_ROOM_EVENT = aRoomMessageEvent(AN_EVENT_ID, content = "previous room event")
private val A_PERSISTED_EVENT = aRoomMessageEvent(AN_EVENT_ID, content = "persisted event")
private val A_ROOM_EVENT = aMatrixRoomMessageEvent(AN_EVENT_ID, content = "previous room event")
private val A_PERSISTED_EVENT = aMatrixRoomMessageEvent(AN_EVENT_ID, content = "persisted event")
class EventLookupUseCaseTest {

View File

@ -5,7 +5,6 @@ import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.internal.request.ApiEncryptedContent
import app.dapk.st.matrix.sync.internal.request.ApiTimelineEvent
import fake.FakeErrorTracker
import fake.FakeMatrixLogger
import fake.FakeRoomMembersService
import fixture.*
import internalfixture.*
@ -41,7 +40,7 @@ internal class RoomEventCreatorTest {
val result = with(roomEventCreator) { megolmEvent.toRoomEvent(A_ROOM_ID) }
result shouldBeEqualTo aRoomMessageEvent(
result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = megolmEvent.eventId,
utcTimestamp = megolmEvent.utcTimestamp,
content = "Encrypted message",
@ -74,7 +73,7 @@ internal class RoomEventCreatorTest {
val result = with(roomEventCreator) { A_TEXT_EVENT.toRoomEvent(A_USER_CREDENTIALS, A_ROOM_ID, EMPTY_LOOKUP) }
result shouldBeEqualTo aRoomMessageEvent(
result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = A_TEXT_EVENT.id,
utcTimestamp = A_TEXT_EVENT.utcTimestamp,
content = A_TEXT_EVENT_MESSAGE,
@ -88,7 +87,7 @@ internal class RoomEventCreatorTest {
val result = with(roomEventCreator) { A_TEXT_EVENT_WITHOUT_CONTENT.toRoomEvent(A_USER_CREDENTIALS, A_ROOM_ID, EMPTY_LOOKUP) }
result shouldBeEqualTo aRoomMessageEvent(
result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = A_TEXT_EVENT_WITHOUT_CONTENT.id,
utcTimestamp = A_TEXT_EVENT_WITHOUT_CONTENT.utcTimestamp,
content = "redacted",
@ -103,7 +102,7 @@ internal class RoomEventCreatorTest {
val result = with(roomEventCreator) { editEvent.toRoomEvent(A_USER_CREDENTIALS, A_ROOM_ID, EMPTY_LOOKUP) }
result shouldBeEqualTo aRoomMessageEvent(
result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = editEvent.id,
utcTimestamp = editEvent.utcTimestamp,
content = editEvent.asTextContent().body!!,
@ -121,7 +120,7 @@ internal class RoomEventCreatorTest {
val result = with(roomEventCreator) { editedMessage.toRoomEvent(A_USER_CREDENTIALS, A_ROOM_ID, lookup) }
result shouldBeEqualTo aRoomMessageEvent(
result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = originalMessage.id,
utcTimestamp = editedMessage.utcTimestamp,
content = A_TEXT_EVENT_MESSAGE,
@ -133,13 +132,13 @@ internal class RoomEventCreatorTest {
@Test
fun `given edited event which relates to a room event then updates existing message`() = runTest {
fakeRoomMembersService.givenMember(A_ROOM_ID, A_SENDER.id, A_SENDER)
val originalMessage = aRoomMessageEvent()
val originalMessage = aMatrixRoomMessageEvent()
val editedMessage = originalMessage.toEditEvent(newTimestamp = 1000, messageContent = A_TEXT_EVENT_MESSAGE)
val lookup = givenLookup(originalMessage)
val result = with(roomEventCreator) { editedMessage.toRoomEvent(A_USER_CREDENTIALS, A_ROOM_ID, lookup) }
result shouldBeEqualTo aRoomMessageEvent(
result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = originalMessage.eventId,
utcTimestamp = editedMessage.utcTimestamp,
content = A_TEXT_EVENT_MESSAGE,
@ -151,7 +150,7 @@ internal class RoomEventCreatorTest {
@Test
fun `given edited event which relates to a room reply event then only updates message`() = runTest {
fakeRoomMembersService.givenMember(A_ROOM_ID, A_SENDER.id, A_SENDER)
val originalMessage = aRoomReplyMessageEvent(message = aRoomMessageEvent())
val originalMessage = aRoomReplyMessageEvent(message = aMatrixRoomMessageEvent())
val editedMessage = (originalMessage.message as RoomEvent.Message).toEditEvent(newTimestamp = 1000, messageContent = A_TEXT_EVENT_MESSAGE)
val lookup = givenLookup(originalMessage)
@ -159,7 +158,7 @@ internal class RoomEventCreatorTest {
result shouldBeEqualTo aRoomReplyMessageEvent(
replyingTo = originalMessage.replyingTo,
message = aRoomMessageEvent(
message = aMatrixRoomMessageEvent(
eventId = originalMessage.eventId,
utcTimestamp = editedMessage.utcTimestamp,
content = A_TEXT_EVENT_MESSAGE,
@ -182,7 +181,7 @@ internal class RoomEventCreatorTest {
@Test
fun `given edited event is older than related room event then ignores edit`() = runTest {
val originalMessage = aRoomMessageEvent(utcTimestamp = 1000)
val originalMessage = aMatrixRoomMessageEvent(utcTimestamp = 1000)
val editedMessage = originalMessage.toEditEvent(newTimestamp = 0, messageContent = A_TEXT_EVENT_MESSAGE)
val lookup = givenLookup(originalMessage)
@ -199,7 +198,7 @@ internal class RoomEventCreatorTest {
println(replyEvent.content)
val result = with(roomEventCreator) { replyEvent.toRoomEvent(A_USER_CREDENTIALS, A_ROOM_ID, EMPTY_LOOKUP) }
result shouldBeEqualTo aRoomMessageEvent(
result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = replyEvent.id,
utcTimestamp = replyEvent.utcTimestamp,
content = replyEvent.asTextContent().body!!,
@ -217,13 +216,13 @@ internal class RoomEventCreatorTest {
val result = with(roomEventCreator) { replyMessage.toRoomEvent(A_USER_CREDENTIALS, A_ROOM_ID, lookup) }
result shouldBeEqualTo aRoomReplyMessageEvent(
replyingTo = aRoomMessageEvent(
replyingTo = aMatrixRoomMessageEvent(
eventId = originalMessage.id,
utcTimestamp = originalMessage.utcTimestamp,
content = originalMessage.asTextContent().body!!,
author = A_SENDER,
),
message = aRoomMessageEvent(
message = aMatrixRoomMessageEvent(
eventId = replyMessage.id,
utcTimestamp = replyMessage.utcTimestamp,
content = A_REPLY_EVENT_MESSAGE,
@ -235,7 +234,7 @@ internal class RoomEventCreatorTest {
@Test
fun `given reply event which relates to a room event then maps to reply`() = runTest {
fakeRoomMembersService.givenMember(A_ROOM_ID, A_SENDER.id, A_SENDER)
val originalMessage = aRoomMessageEvent()
val originalMessage = aMatrixRoomMessageEvent()
val replyMessage = originalMessage.toReplyEvent(messageContent = A_REPLY_EVENT_MESSAGE)
val lookup = givenLookup(originalMessage)
@ -243,7 +242,7 @@ internal class RoomEventCreatorTest {
result shouldBeEqualTo aRoomReplyMessageEvent(
replyingTo = originalMessage,
message = aRoomMessageEvent(
message = aMatrixRoomMessageEvent(
eventId = replyMessage.id,
utcTimestamp = replyMessage.utcTimestamp,
content = A_REPLY_EVENT_MESSAGE,
@ -263,7 +262,7 @@ internal class RoomEventCreatorTest {
result shouldBeEqualTo aRoomReplyMessageEvent(
replyingTo = originalMessage.message,
message = aRoomMessageEvent(
message = aMatrixRoomMessageEvent(
eventId = replyMessage.id,
utcTimestamp = replyMessage.utcTimestamp,
content = A_REPLY_EVENT_MESSAGE,

View File

@ -5,8 +5,8 @@ import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomState
import fake.FakeMatrixLogger
import fake.FakeRoomDataSource
import internalfake.FakeRoomEventsDecrypter
import fixture.*
import internalfake.FakeRoomEventsDecrypter
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
@ -15,13 +15,14 @@ import test.expect
private val A_ROOM_ID = aRoomId()
private object ARoom {
val MESSAGE_EVENT = aRoomMessageEvent(utcTimestamp = 0)
val MESSAGE_EVENT = aMatrixRoomMessageEvent(utcTimestamp = 0)
val ENCRYPTED_EVENT = anEncryptedRoomMessageEvent(utcTimestamp = 1)
val DECRYPTED_EVENT = aRoomMessageEvent(utcTimestamp = 2)
val PREVIOUS_STATE = RoomState(aRoomOverview(), listOf(MESSAGE_EVENT, ENCRYPTED_EVENT))
val DECRYPTED_EVENT = aMatrixRoomMessageEvent(utcTimestamp = 2)
val PREVIOUS_STATE = RoomState(aMatrixRoomOverview(), listOf(MESSAGE_EVENT, ENCRYPTED_EVENT))
val DECRYPTED_EVENTS = listOf(MESSAGE_EVENT, DECRYPTED_EVENT)
val NEW_STATE = RoomState(aRoomOverview(lastMessage = DECRYPTED_EVENT.asLastMessage()), DECRYPTED_EVENTS)
val NEW_STATE = RoomState(aMatrixRoomOverview(lastMessage = DECRYPTED_EVENT.asLastMessage()), DECRYPTED_EVENTS)
}
private val A_USER_CREDENTIALS = aUserCredentials()
internal class RoomRefresherTest {

View File

@ -19,7 +19,7 @@ private val A_ROOM_ID = aRoomId()
private val ANY_LOOKUP_RESULT = LookupResult(anApiTimelineTextEvent(), roomEvent = null)
private val AN_ENCRYPTED_TIMELINE_EVENT = anEncryptedApiTimelineEvent()
private val A_TEXT_TIMELINE_EVENT = anApiTimelineTextEvent()
private val A_MESSAGE_ROOM_EVENT = aRoomMessageEvent(anEventId("a-message"))
private val A_MESSAGE_ROOM_EVENT = aMatrixRoomMessageEvent(anEventId("a-message"))
private val AN_ENCRYPTED_ROOM_EVENT = anEncryptedRoomMessageEvent(anEventId("encrypted-message"))
private val A_LOOKUP_EVENT_ID = anEventId("lookup-id")
private val A_USER_CREDENTIALS = aUserCredentials()
@ -52,7 +52,7 @@ class TimelineEventsProcessorTest {
@Test
fun `given encrypted and text timeline events when processing then maps to room events`() = runTest {
val previousEvents = listOf(aRoomMessageEvent(eventId = anEventId("previous-event")))
val previousEvents = listOf(aMatrixRoomMessageEvent(eventId = anEventId("previous-event")))
val newTimelineEvents = listOf(AN_ENCRYPTED_TIMELINE_EVENT, A_TEXT_TIMELINE_EVENT)
val roomToProcess = aRoomToProcess(apiSyncRoom = anApiSyncRoom(anApiSyncRoomTimeline(newTimelineEvents)))
fakeRoomEventsDecrypter.givenDecrypts(A_USER_CREDENTIALS, previousEvents)

View File

@ -8,8 +8,8 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
import test.expect
private val A_ROOM_OVERVIEW = aRoomOverview()
private val A_ROOM_MESSAGE_FROM_OTHER = aRoomMessageEvent(
private val A_ROOM_OVERVIEW = aMatrixRoomOverview()
private val A_ROOM_MESSAGE_FROM_OTHER = aMatrixRoomMessageEvent(
eventId = anEventId("a-new-message-event"),
author = aRoomMember(id = aUserId("a-different-user"))
)
@ -27,7 +27,7 @@ internal class UnreadEventsProcessorTest {
fun `given initial sync when processing unread then does mark any events as unread`() = runTest {
unreadEventsProcessor.processUnreadState(
isInitialSync = true,
overview = aRoomOverview(),
overview = aMatrixRoomOverview(),
previousState = null,
newEvents = emptyList(),
selfId = aUserId()

View File

@ -4,7 +4,7 @@ import app.dapk.st.matrix.common.*
import app.dapk.st.matrix.sync.MessageMeta
import app.dapk.st.matrix.sync.RoomEvent
fun aRoomMessageEvent(
fun aMatrixRoomMessageEvent(
eventId: EventId = anEventId(),
utcTimestamp: Long = 0L,
content: String = "message-content",
@ -25,8 +25,8 @@ fun aRoomImageMessageEvent(
) = RoomEvent.Image(eventId, utcTimestamp, content, author, meta, encryptedContent, edited)
fun aRoomReplyMessageEvent(
message: RoomEvent = aRoomMessageEvent(),
replyingTo: RoomEvent = aRoomMessageEvent(eventId = anEventId("in-reply-to-id")),
message: RoomEvent = aMatrixRoomMessageEvent(),
replyingTo: RoomEvent = aMatrixRoomMessageEvent(eventId = anEventId("in-reply-to-id")),
) = RoomEvent.Reply(message, replyingTo)
fun anEncryptedRoomMessageEvent(

View File

@ -4,7 +4,7 @@ import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomOverview
import app.dapk.st.matrix.sync.RoomState
fun aRoomState(
fun aMatrixRoomState(
roomOverview: RoomOverview = aMatrixRoomOverview(),
events: List<RoomEvent> = listOf(aRoomMessageEvent()),
events: List<RoomEvent> = listOf(aMatrixRoomMessageEvent()),
) = RoomState(roomOverview, events)