Updating unit tests for poll aggregation processor
This commit is contained in:
parent
35d5c96c34
commit
610c4e3339
@ -45,7 +45,6 @@ import org.matrix.android.sdk.internal.session.room.relation.poll.FetchPollRespo
|
|||||||
import org.matrix.android.sdk.internal.task.TaskExecutor
|
import org.matrix.android.sdk.internal.task.TaskExecutor
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
// TODO update unit tests
|
|
||||||
internal class DefaultPollAggregationProcessor @Inject constructor(
|
internal class DefaultPollAggregationProcessor @Inject constructor(
|
||||||
private val taskExecutor: TaskExecutor,
|
private val taskExecutor: TaskExecutor,
|
||||||
private val fetchPollResponseEventsTask: FetchPollResponseEventsTask,
|
private val fetchPollResponseEventsTask: FetchPollResponseEventsTask,
|
||||||
|
@ -25,6 +25,8 @@ import kotlinx.coroutines.test.advanceUntilIdle
|
|||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.amshove.kluent.shouldBeFalse
|
import org.amshove.kluent.shouldBeFalse
|
||||||
import org.amshove.kluent.shouldBeTrue
|
import org.amshove.kluent.shouldBeTrue
|
||||||
|
import org.amshove.kluent.shouldContain
|
||||||
|
import org.amshove.kluent.shouldNotContain
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
@ -105,6 +107,24 @@ class DefaultPollAggregationProcessorTest {
|
|||||||
pollAggregationProcessor.handlePollResponseEvent(session, realm.instance, A_POLL_RESPONSE_EVENT).shouldBeTrue()
|
pollAggregationProcessor.handlePollResponseEvent(session, realm.instance, A_POLL_RESPONSE_EVENT).shouldBeTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given a poll response event with a reference, when processing, then event id is removed from encrypted events list`() {
|
||||||
|
// Given
|
||||||
|
val anotherEventId = "other-event-id"
|
||||||
|
val pollResponseAggregatedSummaryEntity = PollResponseAggregatedSummaryEntity(
|
||||||
|
encryptedRelatedEventIds = RealmList(AN_EVENT_ID, anotherEventId)
|
||||||
|
)
|
||||||
|
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns pollResponseAggregatedSummaryEntity
|
||||||
|
|
||||||
|
// When
|
||||||
|
val result = pollAggregationProcessor.handlePollResponseEvent(session, realm.instance, A_POLL_RESPONSE_EVENT)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.shouldBeTrue()
|
||||||
|
pollResponseAggregatedSummaryEntity.encryptedRelatedEventIds.shouldNotContain(AN_EVENT_ID)
|
||||||
|
pollResponseAggregatedSummaryEntity.encryptedRelatedEventIds.shouldContain(anotherEventId)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given a poll response event after poll is closed, when processing, then is ignored and returns false`() {
|
fun `given a poll response event after poll is closed, when processing, then is ignored and returns false`() {
|
||||||
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity().apply {
|
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity().apply {
|
||||||
@ -132,12 +152,33 @@ class DefaultPollAggregationProcessorTest {
|
|||||||
// Given
|
// Given
|
||||||
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity()
|
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity()
|
||||||
every { fakeTaskExecutor.instance.executorScope } returns this
|
every { fakeTaskExecutor.instance.executorScope } returns this
|
||||||
|
|
||||||
// When
|
|
||||||
val powerLevelsHelper = mockRedactionPowerLevels(A_USER_ID_1, true)
|
val powerLevelsHelper = mockRedactionPowerLevels(A_USER_ID_1, true)
|
||||||
|
|
||||||
|
// When
|
||||||
|
val result = pollAggregationProcessor.handlePollEndEvent(session, powerLevelsHelper, realm.instance, A_POLL_END_EVENT)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
pollAggregationProcessor.handlePollEndEvent(session, powerLevelsHelper, realm.instance, A_POLL_END_EVENT).shouldBeTrue()
|
result.shouldBeTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given a poll end event, when processing, then event id is removed from encrypted events list`() = runTest {
|
||||||
|
// Given
|
||||||
|
val anotherEventId = "other-event-id"
|
||||||
|
val pollResponseAggregatedSummaryEntity = PollResponseAggregatedSummaryEntity(
|
||||||
|
encryptedRelatedEventIds = RealmList(AN_EVENT_ID, anotherEventId)
|
||||||
|
)
|
||||||
|
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns pollResponseAggregatedSummaryEntity
|
||||||
|
every { fakeTaskExecutor.instance.executorScope } returns this
|
||||||
|
val powerLevelsHelper = mockRedactionPowerLevels(A_USER_ID_1, true)
|
||||||
|
|
||||||
|
// When
|
||||||
|
val result = pollAggregationProcessor.handlePollEndEvent(session, powerLevelsHelper, realm.instance, A_POLL_END_EVENT)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.shouldBeTrue()
|
||||||
|
pollResponseAggregatedSummaryEntity.encryptedRelatedEventIds.shouldNotContain(AN_EVENT_ID)
|
||||||
|
pollResponseAggregatedSummaryEntity.encryptedRelatedEventIds.shouldContain(anotherEventId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -145,12 +186,13 @@ class DefaultPollAggregationProcessorTest {
|
|||||||
// Given
|
// Given
|
||||||
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity()
|
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity()
|
||||||
every { fakeTaskExecutor.instance.executorScope } returns this
|
every { fakeTaskExecutor.instance.executorScope } returns this
|
||||||
|
|
||||||
// When
|
|
||||||
val powerLevelsHelper = mockRedactionPowerLevels(A_USER_ID_1, false)
|
val powerLevelsHelper = mockRedactionPowerLevels(A_USER_ID_1, false)
|
||||||
|
|
||||||
|
// When
|
||||||
|
val result = pollAggregationProcessor.handlePollEndEvent(session, powerLevelsHelper, realm.instance, A_POLL_END_EVENT)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
pollAggregationProcessor.handlePollEndEvent(session, powerLevelsHelper, realm.instance, A_POLL_END_EVENT).shouldBeTrue()
|
result.shouldBeTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user