diff --git a/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt b/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt index 8028923..bf5ff6f 100644 --- a/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt +++ b/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt @@ -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() + } \ No newline at end of file diff --git a/chat-engine/src/testFixtures/kotlin/fixture/Fixtures.kt b/chat-engine/src/testFixtures/kotlin/fixture/Fixtures.kt index 707e318..68f252b 100644 --- a/chat-engine/src/testFixtures/kotlin/fixture/Fixtures.kt +++ b/chat-engine/src/testFixtures/kotlin/fixture/Fixtures.kt @@ -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 = listOf(aRoomMessageEvent()), +) = RoomState(roomOverview, events) \ No newline at end of file diff --git a/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationFactoryTest.kt b/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationFactoryTest.kt index 69bc836..5c26faa 100644 --- a/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationFactoryTest.kt +++ b/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationFactoryTest.kt @@ -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 diff --git a/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationRendererTest.kt b/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationRendererTest.kt index 0be9e2f..724aa50 100644 --- a/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationRendererTest.kt +++ b/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationRendererTest.kt @@ -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 diff --git a/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationStateMapperTest.kt b/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationStateMapperTest.kt index 045ed36..2711f43 100644 --- a/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationStateMapperTest.kt +++ b/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationStateMapperTest.kt @@ -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 diff --git a/features/notifications/src/test/kotlin/app/dapk/st/notifications/RenderNotificationsUseCaseTest.kt b/features/notifications/src/test/kotlin/app/dapk/st/notifications/RenderNotificationsUseCaseTest.kt index c4a30ba..e99921a 100644 --- a/features/notifications/src/test/kotlin/app/dapk/st/notifications/RenderNotificationsUseCaseTest.kt +++ b/features/notifications/src/test/kotlin/app/dapk/st/notifications/RenderNotificationsUseCaseTest.kt @@ -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())) diff --git a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/LocalEchoMapperTest.kt b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/LocalEchoMapperTest.kt index a58e61b..a2f794d 100644 --- a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/LocalEchoMapperTest.kt +++ b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/LocalEchoMapperTest.kt @@ -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 { diff --git a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt index b5edabd..5603193 100644 --- a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt +++ b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt @@ -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, ) ) } diff --git a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/ObserveUnreadRenderNotificationsUseCaseTest.kt b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/ObserveUnreadRenderNotificationsUseCaseTest.kt index bc77daa..50bd2b9 100644 --- a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/ObserveUnreadRenderNotificationsUseCaseTest.kt +++ b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/ObserveUnreadRenderNotificationsUseCaseTest.kt @@ -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>() -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")) diff --git a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt index 4acd7bf..c2edd7d 100644 --- a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt +++ b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt @@ -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() diff --git a/features/notifications/src/test/kotlin/fake/FakeObserveInviteNotificationsUseCase.kt b/matrix-chat-engine/src/test/kotlin/fake/FakeObserveInviteNotificationsUseCase.kt similarity index 68% rename from features/notifications/src/test/kotlin/fake/FakeObserveInviteNotificationsUseCase.kt rename to matrix-chat-engine/src/test/kotlin/fake/FakeObserveInviteNotificationsUseCase.kt index 5e1b7eb..886fe27 100644 --- a/features/notifications/src/test/kotlin/fake/FakeObserveInviteNotificationsUseCase.kt +++ b/matrix-chat-engine/src/test/kotlin/fake/FakeObserveInviteNotificationsUseCase.kt @@ -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() } \ No newline at end of file diff --git a/features/notifications/src/test/kotlin/fake/FakeObserveUnreadNotificationsUseCase.kt b/matrix-chat-engine/src/test/kotlin/fake/FakeObserveUnreadNotificationsUseCase.kt similarity index 68% rename from features/notifications/src/test/kotlin/fake/FakeObserveUnreadNotificationsUseCase.kt rename to matrix-chat-engine/src/test/kotlin/fake/FakeObserveUnreadNotificationsUseCase.kt index b90b035..d04b782 100644 --- a/features/notifications/src/test/kotlin/fake/FakeObserveUnreadNotificationsUseCase.kt +++ b/matrix-chat-engine/src/test/kotlin/fake/FakeObserveUnreadNotificationsUseCase.kt @@ -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() } \ No newline at end of file diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/room/RoomEventsDecrypterTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/room/RoomEventsDecrypterTest.kt index 3178ae9..23a5623 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/room/RoomEventsDecrypterTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/room/RoomEventsDecrypterTest.kt @@ -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) diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/EventLookupUseCaseTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/EventLookupUseCaseTest.kt index b837fb6..5bc47b6 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/EventLookupUseCaseTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/EventLookupUseCaseTest.kt @@ -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 { diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreatorTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreatorTest.kt index f0b9a94..b265549 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreatorTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreatorTest.kt @@ -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, diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomRefresherTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomRefresherTest.kt index 60a76fb..b0b1ef3 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomRefresherTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomRefresherTest.kt @@ -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 { diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/TimelineEventsProcessorTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/TimelineEventsProcessorTest.kt index 31ecef5..d8a1d4a 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/TimelineEventsProcessorTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/TimelineEventsProcessorTest.kt @@ -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) diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/UnreadEventsProcessorTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/UnreadEventsProcessorTest.kt index 9fd79c2..28d2be1 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/UnreadEventsProcessorTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/UnreadEventsProcessorTest.kt @@ -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() diff --git a/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomEventFixture.kt b/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomEventFixture.kt index 65b1c09..9b4d641 100644 --- a/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomEventFixture.kt +++ b/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomEventFixture.kt @@ -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( diff --git a/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomStateFixture.kt b/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomStateFixture.kt index dbb646d..511bcf4 100644 --- a/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomStateFixture.kt +++ b/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomStateFixture.kt @@ -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 = listOf(aRoomMessageEvent()), + events: List = listOf(aMatrixRoomMessageEvent()), ) = RoomState(roomOverview, events) \ No newline at end of file