From 60340852449ccecc820188e0ba64004ec254468d Mon Sep 17 00:00:00 2001 From: Maxime NATUREL <46314705+mnaturel@users.noreply.github.com> Date: Mon, 13 Feb 2023 18:07:23 +0100 Subject: [PATCH] Adding unit test --- .../DefaultPollAggregationProcessorTest.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessorTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessorTest.kt index 766e51a8e5..248c4b322d 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessorTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessorTest.kt @@ -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() 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 {