Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Dec 12, 2024
1 parent ac6129a commit 2728e5b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,11 @@ internal constructor(
)
}

@PublishedApi
@InternalStreamChatApi
@StreamHandsOff(
"This method is used to avoid race-condition between plugin initialization and dependency resolution.",
)
internal fun awaitInitializationState(timeoutMilliseconds: Long): InitializationState? {
public fun awaitInitializationState(timeoutMilliseconds: Long): InitializationState? {
var initState: InitializationState? = clientState.initializationState.value
var spendTime = 0L
inheritScope { Job(it) }.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ internal class ChannelListViewModelTest {
fun givenCurrentUser(currentUser: User = User(id = "Jc")) = apply {
whenever(clientState.user) doReturn MutableStateFlow(currentUser)
whenever(clientState.initializationState) doReturn MutableStateFlow(InitializationState.COMPLETE)
whenever(chatClient.awaitInitializationState(any())) doReturn InitializationState.COMPLETE
}

fun givenChannelMutes(channelMutes: List<ChannelMute> = emptyList()) = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ internal class MessageComposerViewModelTest {
whenever(clientState.user) doReturn MutableStateFlow(currentUser)
whenever(chatClient.clientState) doReturn clientState
whenever(clientState.initializationState) doReturn MutableStateFlow(InitializationState.COMPLETE)
whenever(chatClient.awaitInitializationState(any())) doReturn InitializationState.COMPLETE
}

fun givenChannelQuery(channel: Channel = Channel()) = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.amshove.kluent.shouldBeEqualTo
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import org.mockito.kotlin.any
import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
Expand Down Expand Up @@ -136,6 +137,7 @@ internal class ChatClientExtensionTests {
userFlow.value = null
Unit.asCall()
}
on(it.awaitInitializationState(any())) doReturn InitializationState.COMPLETE
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ internal class ChannelListViewModelTest {
whenever(clientState.user) doReturn MutableStateFlow(currentUser)
whenever(clientState.initializationState) doReturn MutableStateFlow(InitializationState.COMPLETE)
whenever(chatClient.getCurrentUser()) doReturn currentUser
whenever(chatClient.awaitInitializationState(any())) doReturn InitializationState.COMPLETE
}

fun givenChannelMutes(channelMutes: List<ChannelMute> = emptyList()) = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ internal class MessageComposerViewModelTest {
whenever(clientState.user) doReturn MutableStateFlow(currentUser)
whenever(chatClient.clientState) doReturn clientState
whenever(clientState.initializationState) doReturn MutableStateFlow(InitializationState.COMPLETE)
whenever(chatClient.awaitInitializationState(any())) doReturn InitializationState.COMPLETE
}

fun givenChannelQuery(channel: Channel = Channel()) = apply {
Expand Down

0 comments on commit 2728e5b

Please sign in to comment.