Adding unit test

This commit is contained in:
Maxime NATUREL 2023-02-13 18:07:23 +01:00
parent 454ce1c095
commit 6034085244
1 changed files with 16 additions and 2 deletions

View File

@ -147,6 +147,19 @@ class DefaultPollAggregationProcessorTest {
pollAggregationProcessor.handlePollResponseEvent(session, realm.instance, AN_INVALID_POLL_RESPONSE_EVENT).shouldBeFalse()
}
@Test
fun `given a poll response event and no existing poll start event, when processing, then is processed and returns true`() {
// Given
mockRoom(roomId = A_ROOM_ID, eventId = AN_EVENT_ID, hasExistingTimelineEvent = false)
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity()
// When
val result = pollAggregationProcessor.handlePollResponseEvent(session, realm.instance, A_POLL_RESPONSE_EVENT)
// Then
result.shouldBeTrue()
}
@Test
fun `given a poll end event, when processing, then is processed and return true`() = runTest {
// Given
@ -234,11 +247,12 @@ class DefaultPollAggregationProcessorTest {
private fun mockRoom(
roomId: String,
eventId: String
eventId: String,
hasExistingTimelineEvent: Boolean = true,
) {
val room = mockk<Room>()
every { session.getRoom(roomId) } returns room
every { room.getTimelineEvent(eventId) } returns A_TIMELINE_EVENT
every { room.getTimelineEvent(eventId) } returns if (hasExistingTimelineEvent) A_TIMELINE_EVENT else null
}
private fun mockRedactionPowerLevels(userId: String, isAbleToRedact: Boolean): PowerLevelsHelper {