Skip to content

Commit

Permalink
Add VerifyClientTest.kt.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubuid committed Aug 5, 2024
1 parent b46af08 commit d6e395d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.koin.core.KoinApplication

internal class VerifyClient(private val koinApp: KoinApplication = wcKoinApp) : VerifyInterface {
private val verifyRepository by lazy { koinApp.koin.get<VerifyRepository>() }
internal class VerifyClient(
private val koinApp: KoinApplication = wcKoinApp,
private val scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
) : VerifyInterface {
private val verifyRepository by lazy { koinApp.koin.get<VerifyRepository>() }

override fun initialize() {
koinApp.modules(verifyModule())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.walletconnect.android.internal

import com.walletconnect.android.verify.client.VerifyClient
import com.walletconnect.android.verify.domain.VerifyRepository
import com.walletconnect.android.verify.domain.VerifyResult
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.koin.core.KoinApplication
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.dsl.module

class VerifyClientTest {
private lateinit var koinApp: KoinApplication
private var verifyRepository: VerifyRepository = mockk(relaxed = true)
private lateinit var verifyClient: VerifyClient
private val testDispatcher = StandardTestDispatcher()
private val testScope = TestScope(testDispatcher)

@Before
fun setup() {
koinApp = startKoin {
modules(module {
single { verifyRepository }
})
}
verifyClient = VerifyClient(koinApp, testScope)
}

@After
fun tearDown() {
stopKoin()
}

@Test
fun `resolve should call resolve on verifyRepository`() = runTest {
val attestationId = "attestationId"
val metadataUrl = "https://metadata.url"
val onSuccess = mockk<(VerifyResult) -> Unit>(relaxed = true)
val onError = mockk<(Throwable) -> Unit>(relaxed = true)

verifyClient.resolve(attestationId, metadataUrl, onSuccess, onError)

coVerify { verifyRepository.resolve(attestationId, metadataUrl, onSuccess, onError) }
}

@Test
fun `resolveV2 should call resolveV2 on verifyRepository`() = runTest {
val attestation = "attestation"
val metadataUrl = "https://metadata.url"
val onSuccess = mockk<(VerifyResult) -> Unit>(relaxed = true)
val onError = mockk<(Throwable) -> Unit>(relaxed = true)

verifyClient.resolveV2(attestation, metadataUrl, onSuccess, onError)

coVerify { verifyRepository.resolveV2(attestation, metadataUrl, onSuccess, onError) }
}
}

0 comments on commit d6e395d

Please sign in to comment.