Adding more tests on ignored cases

This commit is contained in:
Maxime NATUREL 2022-06-08 11:45:35 +02:00
parent 51b930147a
commit dccc3b457d
1 changed files with 84 additions and 7 deletions

View File

@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test import org.junit.Test
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.UnsignedData
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconInfoContent import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconInfoContent
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent
import org.matrix.android.sdk.test.fakes.FakeClock import org.matrix.android.sdk.test.fakes.FakeClock
@ -28,6 +29,7 @@ import org.matrix.android.sdk.test.fakes.FakeWorkManagerProvider
private const val A_SESSION_ID = "session_id" private const val A_SESSION_ID = "session_id"
private const val A_SENDER_ID = "sender_id" private const val A_SENDER_ID = "sender_id"
private const val AN_EVENT_ID = "event_id" private const val AN_EVENT_ID = "event_id"
private const val A_ROOM_ID = "room_id"
internal class LiveLocationAggregationProcessorTest { internal class LiveLocationAggregationProcessorTest {
@ -50,7 +52,7 @@ internal class LiveLocationAggregationProcessorTest {
realm = fakeRealm.instance, realm = fakeRealm.instance,
event = event, event = event,
content = beaconInfo, content = beaconInfo,
roomId = "", roomId = A_ROOM_ID,
isLocalEcho = true isLocalEcho = true
) )
@ -67,14 +69,14 @@ internal class LiveLocationAggregationProcessorTest {
realm = fakeRealm.instance, realm = fakeRealm.instance,
event = eventNoSenderId, event = eventNoSenderId,
content = beaconInfo, content = beaconInfo,
roomId = "", roomId = A_ROOM_ID,
isLocalEcho = false isLocalEcho = false
) )
val resultEmptySenderId = liveLocationAggregationProcessor.handleBeaconInfo( val resultEmptySenderId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance, realm = fakeRealm.instance,
event = eventEmptySenderId, event = eventEmptySenderId,
content = beaconInfo, content = beaconInfo,
roomId = "", roomId = A_ROOM_ID,
isLocalEcho = false isLocalEcho = false
) )
@ -82,6 +84,55 @@ internal class LiveLocationAggregationProcessorTest {
resultEmptySenderId shouldBeEqualTo false resultEmptySenderId shouldBeEqualTo false
} }
@Test
fun `given beacon info when no target eventId is found then it is ignored`() {
val unsignedDataWithNoEventId = UnsignedData(
age = 123
)
val unsignedDataWithEmptyEventId = UnsignedData(
age = 123,
replacesState = ""
)
val eventWithNoEventId = Event(senderId = A_SENDER_ID, unsignedData = unsignedDataWithNoEventId)
val eventWithEmptyEventId = Event(senderId = A_SENDER_ID, eventId = "", unsignedData = unsignedDataWithEmptyEventId)
val beaconInfoLive = MessageBeaconInfoContent(isLive = true)
val beaconInfoNotLive = MessageBeaconInfoContent(isLive = false)
val resultLiveNoEventId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventWithNoEventId,
content = beaconInfoLive,
roomId = A_ROOM_ID,
isLocalEcho = false
)
val resultLiveEmptyEventId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventWithEmptyEventId,
content = beaconInfoLive,
roomId = A_ROOM_ID,
isLocalEcho = false
)
val resultNotLiveNoEventId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventWithNoEventId,
content = beaconInfoNotLive,
roomId = A_ROOM_ID,
isLocalEcho = false
)
val resultNotLiveEmptyEventId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventWithEmptyEventId,
content = beaconInfoNotLive,
roomId = A_ROOM_ID,
isLocalEcho = false
)
resultLiveNoEventId shouldBeEqualTo false
resultLiveEmptyEventId shouldBeEqualTo false
resultNotLiveNoEventId shouldBeEqualTo false
resultNotLiveEmptyEventId shouldBeEqualTo false
}
@Test @Test
fun `given beacon location data when it is local echo then it is ignored`() { fun `given beacon location data when it is local echo then it is ignored`() {
val event = Event(senderId = A_SENDER_ID) val event = Event(senderId = A_SENDER_ID)
@ -91,14 +142,40 @@ internal class LiveLocationAggregationProcessorTest {
realm = fakeRealm.instance, realm = fakeRealm.instance,
event = event, event = event,
content = beaconLocationData, content = beaconLocationData,
roomId = "", roomId = A_ROOM_ID,
relatedEventId = "", relatedEventId = AN_EVENT_ID,
isLocalEcho = true isLocalEcho = true
) )
result shouldBeEqualTo false result shouldBeEqualTo false
} }
@Test
fun `given beacon location data when relatedEventId is null or empty then it is ignored`() {
val event = Event(senderId = A_SENDER_ID)
val beaconLocationData = MessageBeaconLocationDataContent()
val resultNoRelatedEventId = liveLocationAggregationProcessor.handleBeaconLocationData(
realm = fakeRealm.instance,
event = event,
content = beaconLocationData,
roomId = A_ROOM_ID,
relatedEventId = null,
isLocalEcho = false
)
val resultEmptyRelatedEventId = liveLocationAggregationProcessor.handleBeaconLocationData(
realm = fakeRealm.instance,
event = event,
content = beaconLocationData,
roomId = A_ROOM_ID,
relatedEventId = "",
isLocalEcho = false
)
resultNoRelatedEventId shouldBeEqualTo false
resultEmptyRelatedEventId shouldBeEqualTo false
}
@Test @Test
fun `given beacon location data and event when senderId is null or empty then it is ignored`() { fun `given beacon location data and event when senderId is null or empty then it is ignored`() {
val eventNoSenderId = Event(eventId = AN_EVENT_ID) val eventNoSenderId = Event(eventId = AN_EVENT_ID)
@ -110,7 +187,7 @@ internal class LiveLocationAggregationProcessorTest {
event = eventNoSenderId, event = eventNoSenderId,
content = beaconLocationData, content = beaconLocationData,
roomId = "", roomId = "",
relatedEventId = "", relatedEventId = AN_EVENT_ID,
isLocalEcho = false isLocalEcho = false
) )
val resultEmptySenderId = liveLocationAggregationProcessor.handleBeaconLocationData( val resultEmptySenderId = liveLocationAggregationProcessor.handleBeaconLocationData(
@ -118,7 +195,7 @@ internal class LiveLocationAggregationProcessorTest {
event = eventEmptySenderId, event = eventEmptySenderId,
content = beaconLocationData, content = beaconLocationData,
roomId = "", roomId = "",
relatedEventId = "", relatedEventId = AN_EVENT_ID,
isLocalEcho = false isLocalEcho = false
) )