Fix test
This commit is contained in:
parent
44c0466b09
commit
8b190d776a
4 changed files with 31 additions and 25 deletions
|
|
@ -18,6 +18,7 @@ package io.element.android.libraries.push.impl.notifications
|
||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.libraries.matrix.api.core.EventId
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
|
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||||
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
||||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||||
|
|
@ -124,11 +125,13 @@ class NotificationFactoryTest {
|
||||||
fun `given room with message when mapping to notification then delegates to room group message creator`() = testWith(notificationFactory) {
|
fun `given room with message when mapping to notification then delegates to room group message creator`() = testWith(notificationFactory) {
|
||||||
val events = listOf(A_MESSAGE_EVENT)
|
val events = listOf(A_MESSAGE_EVENT)
|
||||||
val expectedNotification = roomGroupMessageCreator.givenCreatesRoomMessageFor(
|
val expectedNotification = roomGroupMessageCreator.givenCreatesRoomMessageFor(
|
||||||
A_SESSION_ID, events, A_ROOM_ID, A_SESSION_ID.value, MY_AVATAR_URL
|
MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL), events, A_ROOM_ID
|
||||||
)
|
)
|
||||||
val roomWithMessage = mapOf(A_ROOM_ID to listOf(ProcessedEvent(ProcessedEvent.Type.KEEP, A_MESSAGE_EVENT)))
|
val roomWithMessage = mapOf(A_ROOM_ID to listOf(ProcessedEvent(ProcessedEvent.Type.KEEP, A_MESSAGE_EVENT)))
|
||||||
|
|
||||||
val result = roomWithMessage.toNotifications(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL)
|
val result = roomWithMessage.toNotifications(
|
||||||
|
MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL)
|
||||||
|
)
|
||||||
|
|
||||||
assertThat(result).isEqualTo(listOf(expectedNotification))
|
assertThat(result).isEqualTo(listOf(expectedNotification))
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +141,9 @@ class NotificationFactoryTest {
|
||||||
val events = listOf(ProcessedEvent(ProcessedEvent.Type.REMOVE, A_MESSAGE_EVENT))
|
val events = listOf(ProcessedEvent(ProcessedEvent.Type.REMOVE, A_MESSAGE_EVENT))
|
||||||
val emptyRoom = mapOf(A_ROOM_ID to events)
|
val emptyRoom = mapOf(A_ROOM_ID to events)
|
||||||
|
|
||||||
val result = emptyRoom.toNotifications(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL)
|
val result = emptyRoom.toNotifications(
|
||||||
|
MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL)
|
||||||
|
)
|
||||||
|
|
||||||
assertThat(result).isEqualTo(
|
assertThat(result).isEqualTo(
|
||||||
listOf(
|
listOf(
|
||||||
|
|
@ -153,7 +158,9 @@ class NotificationFactoryTest {
|
||||||
fun `given a room with only redacted events when mapping to notification then is Empty`() = testWith(notificationFactory) {
|
fun `given a room with only redacted events when mapping to notification then is Empty`() = testWith(notificationFactory) {
|
||||||
val redactedRoom = mapOf(A_ROOM_ID to listOf(ProcessedEvent(ProcessedEvent.Type.KEEP, A_MESSAGE_EVENT.copy(isRedacted = true))))
|
val redactedRoom = mapOf(A_ROOM_ID to listOf(ProcessedEvent(ProcessedEvent.Type.KEEP, A_MESSAGE_EVENT.copy(isRedacted = true))))
|
||||||
|
|
||||||
val result = redactedRoom.toNotifications(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL)
|
val result = redactedRoom.toNotifications(
|
||||||
|
MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL)
|
||||||
|
)
|
||||||
|
|
||||||
assertThat(result).isEqualTo(
|
assertThat(result).isEqualTo(
|
||||||
listOf(
|
listOf(
|
||||||
|
|
@ -176,14 +183,14 @@ class NotificationFactoryTest {
|
||||||
)
|
)
|
||||||
val withRedactedRemoved = listOf(A_MESSAGE_EVENT.copy(eventId = EventId("\$not-redacted")))
|
val withRedactedRemoved = listOf(A_MESSAGE_EVENT.copy(eventId = EventId("\$not-redacted")))
|
||||||
val expectedNotification = roomGroupMessageCreator.givenCreatesRoomMessageFor(
|
val expectedNotification = roomGroupMessageCreator.givenCreatesRoomMessageFor(
|
||||||
A_SESSION_ID,
|
MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
|
||||||
withRedactedRemoved,
|
withRedactedRemoved,
|
||||||
A_ROOM_ID,
|
A_ROOM_ID,
|
||||||
A_SESSION_ID.value,
|
|
||||||
MY_AVATAR_URL
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val result = roomWithRedactedMessage.toNotifications(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL)
|
val result = roomWithRedactedMessage.toNotifications(
|
||||||
|
MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL)
|
||||||
|
)
|
||||||
|
|
||||||
assertThat(result).isEqualTo(listOf(expectedNotification))
|
assertThat(result).isEqualTo(listOf(expectedNotification))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package io.element.android.libraries.push.impl.notifications
|
package io.element.android.libraries.push.impl.notifications
|
||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
|
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||||
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
||||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||||
|
|
@ -193,9 +194,7 @@ class NotificationRendererTest {
|
||||||
|
|
||||||
private fun renderEventsAsNotifications() {
|
private fun renderEventsAsNotifications() {
|
||||||
notificationRenderer.render(
|
notificationRenderer.render(
|
||||||
sessionId = A_SESSION_ID,
|
MatrixUser(A_SESSION_ID, MY_USER_DISPLAY_NAME, MY_USER_AVATAR_URL),
|
||||||
myUserDisplayName = MY_USER_DISPLAY_NAME,
|
|
||||||
myUserAvatarUrl = MY_USER_AVATAR_URL,
|
|
||||||
useCompleteNotificationFormat = USE_COMPLETE_NOTIFICATION_FORMAT,
|
useCompleteNotificationFormat = USE_COMPLETE_NOTIFICATION_FORMAT,
|
||||||
eventsToProcess = AN_EVENT_LIST
|
eventsToProcess = AN_EVENT_LIST
|
||||||
)
|
)
|
||||||
|
|
@ -214,9 +213,7 @@ class NotificationRendererTest {
|
||||||
) {
|
) {
|
||||||
notificationFactory.givenNotificationsFor(
|
notificationFactory.givenNotificationsFor(
|
||||||
groupedEvents = A_PROCESSED_EVENTS,
|
groupedEvents = A_PROCESSED_EVENTS,
|
||||||
sessionId = A_SESSION_ID,
|
matrixUser = MatrixUser(A_SESSION_ID, MY_USER_DISPLAY_NAME, MY_USER_AVATAR_URL),
|
||||||
myUserDisplayName = MY_USER_DISPLAY_NAME,
|
|
||||||
myUserAvatarUrl = MY_USER_AVATAR_URL,
|
|
||||||
useCompleteNotificationFormat = useCompleteNotificationFormat,
|
useCompleteNotificationFormat = useCompleteNotificationFormat,
|
||||||
roomNotifications = roomNotifications,
|
roomNotifications = roomNotifications,
|
||||||
invitationNotifications = invitationNotifications,
|
invitationNotifications = invitationNotifications,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package io.element.android.libraries.push.impl.notifications.fake
|
package io.element.android.libraries.push.impl.notifications.fake
|
||||||
|
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||||
import io.element.android.libraries.push.impl.notifications.GroupedNotificationEvents
|
import io.element.android.libraries.push.impl.notifications.GroupedNotificationEvents
|
||||||
import io.element.android.libraries.push.impl.notifications.NotificationFactory
|
import io.element.android.libraries.push.impl.notifications.NotificationFactory
|
||||||
import io.element.android.libraries.push.impl.notifications.OneShotNotification
|
import io.element.android.libraries.push.impl.notifications.OneShotNotification
|
||||||
|
|
@ -30,9 +30,7 @@ class FakeNotificationFactory {
|
||||||
|
|
||||||
fun givenNotificationsFor(
|
fun givenNotificationsFor(
|
||||||
groupedEvents: GroupedNotificationEvents,
|
groupedEvents: GroupedNotificationEvents,
|
||||||
sessionId: SessionId,
|
matrixUser: MatrixUser,
|
||||||
myUserDisplayName: String,
|
|
||||||
myUserAvatarUrl: String?,
|
|
||||||
useCompleteNotificationFormat: Boolean,
|
useCompleteNotificationFormat: Boolean,
|
||||||
roomNotifications: List<RoomNotification>,
|
roomNotifications: List<RoomNotification>,
|
||||||
invitationNotifications: List<OneShotNotification>,
|
invitationNotifications: List<OneShotNotification>,
|
||||||
|
|
@ -40,13 +38,13 @@ class FakeNotificationFactory {
|
||||||
summaryNotification: SummaryNotification
|
summaryNotification: SummaryNotification
|
||||||
) {
|
) {
|
||||||
with(instance) {
|
with(instance) {
|
||||||
every { groupedEvents.roomEvents.toNotifications(sessionId, myUserDisplayName, myUserAvatarUrl) } returns roomNotifications
|
every { groupedEvents.roomEvents.toNotifications(matrixUser) } returns roomNotifications
|
||||||
every { groupedEvents.invitationEvents.toNotifications() } returns invitationNotifications
|
every { groupedEvents.invitationEvents.toNotifications() } returns invitationNotifications
|
||||||
every { groupedEvents.simpleEvents.toNotifications() } returns simpleNotifications
|
every { groupedEvents.simpleEvents.toNotifications() } returns simpleNotifications
|
||||||
|
|
||||||
every {
|
every {
|
||||||
createSummaryNotification(
|
createSummaryNotification(
|
||||||
sessionId,
|
matrixUser,
|
||||||
roomNotifications,
|
roomNotifications,
|
||||||
invitationNotifications,
|
invitationNotifications,
|
||||||
simpleNotifications,
|
simpleNotifications,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
package io.element.android.libraries.push.impl.notifications.fake
|
package io.element.android.libraries.push.impl.notifications.fake
|
||||||
|
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||||
import io.element.android.libraries.push.impl.notifications.RoomGroupMessageCreator
|
import io.element.android.libraries.push.impl.notifications.RoomGroupMessageCreator
|
||||||
import io.element.android.libraries.push.impl.notifications.RoomNotification
|
import io.element.android.libraries.push.impl.notifications.RoomNotification
|
||||||
import io.element.android.libraries.push.impl.notifications.model.NotifiableMessageEvent
|
import io.element.android.libraries.push.impl.notifications.model.NotifiableMessageEvent
|
||||||
|
|
@ -29,14 +29,18 @@ class FakeRoomGroupMessageCreator {
|
||||||
val instance = mockk<RoomGroupMessageCreator>()
|
val instance = mockk<RoomGroupMessageCreator>()
|
||||||
|
|
||||||
fun givenCreatesRoomMessageFor(
|
fun givenCreatesRoomMessageFor(
|
||||||
sessionId: SessionId,
|
matrixUser: MatrixUser,
|
||||||
events: List<NotifiableMessageEvent>,
|
events: List<NotifiableMessageEvent>,
|
||||||
roomId: RoomId,
|
roomId: RoomId,
|
||||||
userDisplayName: String,
|
|
||||||
userAvatarUrl: String?
|
|
||||||
): RoomNotification.Message {
|
): RoomNotification.Message {
|
||||||
val mockMessage = mockk<RoomNotification.Message>()
|
val mockMessage = mockk<RoomNotification.Message>()
|
||||||
every { instance.createRoomMessage(sessionId, events, roomId, userDisplayName, userAvatarUrl) } returns mockMessage
|
every {
|
||||||
|
instance.createRoomMessage(
|
||||||
|
currentUser = matrixUser,
|
||||||
|
events = events,
|
||||||
|
roomId = roomId,
|
||||||
|
)
|
||||||
|
} returns mockMessage
|
||||||
return mockMessage
|
return mockMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue