mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 03:48:12 +03:00
Mockk GetOngoingVoiceBroadcastsUseCase and adapt tests
This commit is contained in:
parent
23b4f6d42f
commit
0cc2a477b4
2 changed files with 16 additions and 8 deletions
|
@ -31,8 +31,12 @@ class GetOngoingVoiceBroadcastsUseCase @Inject constructor(
|
|||
) {
|
||||
|
||||
fun execute(roomId: String): List<VoiceBroadcastEvent> {
|
||||
val session = activeSessionHolder.getSafeActiveSession() ?: return emptyList()
|
||||
val room = session.getRoom(roomId) ?: error("Unknown roomId: $roomId")
|
||||
println("## GetOngoingVoiceBroadcastsUseCase")
|
||||
println("## GetOngoingVoiceBroadcastsUseCase activeSessionHolder $activeSessionHolder")
|
||||
val session = activeSessionHolder.getSafeActiveSession()
|
||||
println("## GetOngoingVoiceBroadcastsUseCase session $session")
|
||||
val room = session?.getRoom(roomId) ?: error("Unknown roomId: $roomId")
|
||||
println("## GetOngoingVoiceBroadcastsUseCase room $room")
|
||||
|
||||
Timber.d("## GetLastVoiceBroadcastUseCase: get last voice broadcast in $roomId")
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import im.vector.app.features.voicebroadcast.VoiceBroadcastConstants
|
|||
import im.vector.app.features.voicebroadcast.VoiceBroadcastRecorder
|
||||
import im.vector.app.features.voicebroadcast.model.MessageVoiceBroadcastInfoContent
|
||||
import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState
|
||||
import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent
|
||||
import im.vector.app.test.fakes.FakeContext
|
||||
import im.vector.app.test.fakes.FakeRoom
|
||||
import im.vector.app.test.fakes.FakeRoomService
|
||||
|
@ -27,13 +28,13 @@ import im.vector.app.test.fakes.FakeSession
|
|||
import io.mockk.clearAllMocks
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.slot
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.amshove.kluent.shouldBe
|
||||
import org.amshove.kluent.shouldBeNull
|
||||
import org.junit.Test
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.events.model.Content
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
|
@ -48,12 +49,13 @@ class StartVoiceBroadcastUseCaseTest {
|
|||
private val fakeRoom = FakeRoom()
|
||||
private val fakeSession = FakeSession(fakeRoomService = FakeRoomService(fakeRoom))
|
||||
private val fakeVoiceBroadcastRecorder = mockk<VoiceBroadcastRecorder>(relaxed = true)
|
||||
private val fakeGetOngoingVoiceBroadcastsUseCase = mockk<GetOngoingVoiceBroadcastsUseCase>()
|
||||
private val startVoiceBroadcastUseCase = StartVoiceBroadcastUseCase(
|
||||
session = fakeSession,
|
||||
voiceBroadcastRecorder = fakeVoiceBroadcastRecorder,
|
||||
context = FakeContext().instance,
|
||||
buildMeta = mockk(),
|
||||
getOngoingVoiceBroadcastsUseCase = GetOngoingVoiceBroadcastsUseCase(fakeSession),
|
||||
getOngoingVoiceBroadcastsUseCase = fakeGetOngoingVoiceBroadcastsUseCase,
|
||||
)
|
||||
|
||||
@Test
|
||||
|
@ -81,7 +83,7 @@ class StartVoiceBroadcastUseCaseTest {
|
|||
private suspend fun testVoiceBroadcastStarted(voiceBroadcasts: List<VoiceBroadcast>) {
|
||||
// Given
|
||||
clearAllMocks()
|
||||
givenAVoiceBroadcasts(voiceBroadcasts)
|
||||
givenVoiceBroadcasts(voiceBroadcasts)
|
||||
val voiceBroadcastInfoContentInterceptor = slot<Content>()
|
||||
coEvery { fakeRoom.stateService().sendStateEvent(any(), any(), capture(voiceBroadcastInfoContentInterceptor)) } coAnswers { AN_EVENT_ID }
|
||||
|
||||
|
@ -104,7 +106,7 @@ class StartVoiceBroadcastUseCaseTest {
|
|||
private suspend fun testVoiceBroadcastNotStarted(voiceBroadcasts: List<VoiceBroadcast>) {
|
||||
// Given
|
||||
clearAllMocks()
|
||||
givenAVoiceBroadcasts(voiceBroadcasts)
|
||||
givenVoiceBroadcasts(voiceBroadcasts)
|
||||
|
||||
// When
|
||||
startVoiceBroadcastUseCase.execute(A_ROOM_ID)
|
||||
|
@ -113,7 +115,7 @@ class StartVoiceBroadcastUseCaseTest {
|
|||
coVerify(exactly = 0) { fakeRoom.stateService().sendStateEvent(any(), any(), any()) }
|
||||
}
|
||||
|
||||
private fun givenAVoiceBroadcasts(voiceBroadcasts: List<VoiceBroadcast>) {
|
||||
private fun givenVoiceBroadcasts(voiceBroadcasts: List<VoiceBroadcast>) {
|
||||
val events = voiceBroadcasts.map {
|
||||
Event(
|
||||
type = VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO,
|
||||
|
@ -123,7 +125,9 @@ class StartVoiceBroadcastUseCaseTest {
|
|||
).toContent()
|
||||
)
|
||||
}
|
||||
fakeRoom.stateService().givenGetStateEvents(QueryStringValue.IsNotEmpty, events)
|
||||
.mapNotNull { it.asVoiceBroadcastEvent() }
|
||||
.filter { it.content?.voiceBroadcastState != VoiceBroadcastState.STOPPED }
|
||||
every { fakeGetOngoingVoiceBroadcastsUseCase.execute(any()) } returns events
|
||||
}
|
||||
|
||||
private data class VoiceBroadcast(val userId: String, val state: VoiceBroadcastState)
|
||||
|
|
Loading…
Reference in a new issue