mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 03:49:04 +03:00
Adding use case to retrieve flow on live summaries given a list of event ids
This commit is contained in:
parent
96da695473
commit
9a39354332
4 changed files with 146 additions and 12 deletions
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.app.features.location.live
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.emptyFlow
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
import org.matrix.android.sdk.api.session.getRoom
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationShareAggregatedSummary
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetLiveLocationShareSummariesUseCase @Inject constructor(
|
||||||
|
private val session: Session,
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun execute(roomId: String, eventIds: List<String>): Flow<List<LiveLocationShareAggregatedSummary>> {
|
||||||
|
return session.getRoom(roomId)
|
||||||
|
?.locationSharingService()
|
||||||
|
?.getLiveLocationShareSummaries(eventIds)
|
||||||
|
?.asFlow()
|
||||||
|
?: emptyFlow()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.app.features.location.live
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
|
import im.vector.app.test.fakes.FakeSession
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockkStatic
|
||||||
|
import io.mockk.unmockkAll
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationShareAggregatedSummary
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent
|
||||||
|
|
||||||
|
private const val A_ROOM_ID = "room_id"
|
||||||
|
|
||||||
|
class GetLiveLocationShareSummariesUseCaseTest {
|
||||||
|
|
||||||
|
private val fakeSession = FakeSession()
|
||||||
|
|
||||||
|
private val getLiveLocationShareSummariesUseCase = GetLiveLocationShareSummariesUseCase(
|
||||||
|
session = fakeSession
|
||||||
|
)
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
mockkStatic("androidx.lifecycle.FlowLiveDataConversions")
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun tearDown() {
|
||||||
|
unmockkAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given a room id when calling use case then the current live is stopped with success`() = runTest {
|
||||||
|
val eventIds = listOf("event_id_1", "event_id_2", "event_id_3")
|
||||||
|
val summary1 = LiveLocationShareAggregatedSummary(
|
||||||
|
userId = "userId1",
|
||||||
|
isActive = true,
|
||||||
|
endOfLiveTimestampMillis = 123,
|
||||||
|
lastLocationDataContent = MessageBeaconLocationDataContent()
|
||||||
|
)
|
||||||
|
val summary2 = LiveLocationShareAggregatedSummary(
|
||||||
|
userId = "userId2",
|
||||||
|
isActive = true,
|
||||||
|
endOfLiveTimestampMillis = 1234,
|
||||||
|
lastLocationDataContent = MessageBeaconLocationDataContent()
|
||||||
|
)
|
||||||
|
val summary3 = LiveLocationShareAggregatedSummary(
|
||||||
|
userId = "userId3",
|
||||||
|
isActive = true,
|
||||||
|
endOfLiveTimestampMillis = 1234,
|
||||||
|
lastLocationDataContent = MessageBeaconLocationDataContent()
|
||||||
|
)
|
||||||
|
val summaries = listOf(summary1, summary2, summary3)
|
||||||
|
val liveData = fakeSession.roomService()
|
||||||
|
.getRoom(A_ROOM_ID)
|
||||||
|
.locationSharingService()
|
||||||
|
.givenLiveLocationShareSummaries(eventIds, summaries)
|
||||||
|
every { liveData.asFlow() } returns flowOf(summaries)
|
||||||
|
|
||||||
|
val result = getLiveLocationShareSummariesUseCase.execute(A_ROOM_ID, eventIds).first()
|
||||||
|
|
||||||
|
result shouldBeEqualTo listOf(summary1, summary2, summary3)
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.amshove.kluent.internal.assertEquals
|
import org.amshove.kluent.internal.assertEquals
|
||||||
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
|
@ -38,16 +39,17 @@ import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationSh
|
||||||
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.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
|
|
||||||
|
private const val A_ROOM_ID = "room_id"
|
||||||
|
|
||||||
class GetListOfUserLiveLocationUseCaseTest {
|
class GetListOfUserLiveLocationUseCaseTest {
|
||||||
|
|
||||||
@get:Rule
|
|
||||||
val mvRxTestRule = MvRxTestRule()
|
|
||||||
|
|
||||||
private val fakeSession = FakeSession()
|
private val fakeSession = FakeSession()
|
||||||
|
|
||||||
private val viewStateMapper = mockk<UserLiveLocationViewStateMapper>()
|
private val viewStateMapper = mockk<UserLiveLocationViewStateMapper>()
|
||||||
|
|
||||||
private val getListOfUserLiveLocationUseCase = GetListOfUserLiveLocationUseCase(fakeSession, viewStateMapper)
|
private val getListOfUserLiveLocationUseCase = GetListOfUserLiveLocationUseCase(
|
||||||
|
session = fakeSession,
|
||||||
|
userLiveLocationViewStateMapper = viewStateMapper
|
||||||
|
)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
|
@ -61,8 +63,6 @@ class GetListOfUserLiveLocationUseCaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given a room id then the correct flow of view states list is collected`() = runTest {
|
fun `given a room id then the correct flow of view states list is collected`() = runTest {
|
||||||
val roomId = "roomId"
|
|
||||||
|
|
||||||
val summary1 = LiveLocationShareAggregatedSummary(
|
val summary1 = LiveLocationShareAggregatedSummary(
|
||||||
userId = "userId1",
|
userId = "userId1",
|
||||||
isActive = true,
|
isActive = true,
|
||||||
|
@ -83,7 +83,7 @@ class GetListOfUserLiveLocationUseCaseTest {
|
||||||
)
|
)
|
||||||
val summaries = listOf(summary1, summary2, summary3)
|
val summaries = listOf(summary1, summary2, summary3)
|
||||||
val liveData = fakeSession.roomService()
|
val liveData = fakeSession.roomService()
|
||||||
.getRoom(roomId)
|
.getRoom(A_ROOM_ID)
|
||||||
.locationSharingService()
|
.locationSharingService()
|
||||||
.givenRunningLiveLocationShareSummaries(summaries)
|
.givenRunningLiveLocationShareSummaries(summaries)
|
||||||
|
|
||||||
|
@ -109,8 +109,8 @@ class GetListOfUserLiveLocationUseCaseTest {
|
||||||
coEvery { viewStateMapper.map(summary2) } returns viewState2
|
coEvery { viewStateMapper.map(summary2) } returns viewState2
|
||||||
coEvery { viewStateMapper.map(summary3) } returns null
|
coEvery { viewStateMapper.map(summary3) } returns null
|
||||||
|
|
||||||
val viewStates = getListOfUserLiveLocationUseCase.execute(roomId).first()
|
val viewStates = getListOfUserLiveLocationUseCase.execute(A_ROOM_ID).first()
|
||||||
|
|
||||||
assertEquals(listOf(viewState1, viewState2), viewStates)
|
viewStates shouldBeEqualTo listOf(viewState1, viewState2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,13 +27,23 @@ import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationSh
|
||||||
|
|
||||||
class FakeLocationSharingService : LocationSharingService by mockk() {
|
class FakeLocationSharingService : LocationSharingService by mockk() {
|
||||||
|
|
||||||
fun givenRunningLiveLocationShareSummaries(summaries: List<LiveLocationShareAggregatedSummary>):
|
fun givenRunningLiveLocationShareSummaries(
|
||||||
LiveData<List<LiveLocationShareAggregatedSummary>> {
|
summaries: List<LiveLocationShareAggregatedSummary>
|
||||||
|
): LiveData<List<LiveLocationShareAggregatedSummary>> {
|
||||||
return MutableLiveData(summaries).also {
|
return MutableLiveData(summaries).also {
|
||||||
every { getRunningLiveLocationShareSummaries() } returns it
|
every { getRunningLiveLocationShareSummaries() } returns it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenLiveLocationShareSummaries(
|
||||||
|
eventIds: List<String>,
|
||||||
|
summaries: List<LiveLocationShareAggregatedSummary>
|
||||||
|
): LiveData<List<LiveLocationShareAggregatedSummary>> {
|
||||||
|
return MutableLiveData(summaries).also {
|
||||||
|
every { getLiveLocationShareSummaries(eventIds) } returns it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun givenStopLiveLocationShareReturns(result: UpdateLiveLocationShareResult) {
|
fun givenStopLiveLocationShareReturns(result: UpdateLiveLocationShareResult) {
|
||||||
coEvery { stopLiveLocationShare() } returns result
|
coEvery { stopLiveLocationShare() } returns result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue