mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-26 19:08:44 +03:00
Adds validation failed test for SessionParamsCreator
This commit is contained in:
parent
bcd802d335
commit
489670cf6b
3 changed files with 23 additions and 8 deletions
|
@ -47,6 +47,7 @@ class DefaultSessionParamsCreatorTest : DefaultSessionParamsCreatorTestBase() {
|
|||
@Test
|
||||
fun `given credentials homeServerUri is equal to homeServerConnectionConfig, when create, then do not validate`() = runBlockingTest {
|
||||
val homeServerConnectionConfigWithCredentialsUri = homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri())
|
||||
|
||||
val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfigWithCredentialsUri, LoginType.UNKNOWN)
|
||||
|
||||
fakeIsValidClientServerApiTask.verifyNoExecution()
|
||||
|
@ -59,4 +60,14 @@ class DefaultSessionParamsCreatorTest : DefaultSessionParamsCreatorTestBase() {
|
|||
|
||||
assertExpectedSessionParamsWithIdentityServer(output)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given home server validation fails, when create, then do not use home server uri from credentials`() = runBlockingTest {
|
||||
fakeIsValidClientServerApiTask.givenValidationFails()
|
||||
|
||||
val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfig, LoginType.UNKNOWN)
|
||||
|
||||
fakeIsValidClientServerApiTask.verifyExecutionWithConfig(homeServerConnectionConfig)
|
||||
assertExpectedSessionParams(output)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,18 +21,18 @@ import org.amshove.kluent.shouldBeEqualTo
|
|||
import org.matrix.android.sdk.api.auth.data.DiscoveryInformation
|
||||
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
import org.matrix.android.sdk.internal.auth.login.LoginType
|
||||
import org.matrix.android.sdk.test.fixtures.CredentialsFixture
|
||||
import org.matrix.android.sdk.test.fixtures.DiscoveryInformationFixture
|
||||
import org.matrix.android.sdk.test.fixtures.CredentialsFixture.aCredentials
|
||||
import org.matrix.android.sdk.test.fixtures.DiscoveryInformationFixture.aDiscoveryInformation
|
||||
import org.matrix.android.sdk.test.fixtures.HomeServerConnectionConfigFixture.aHomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.test.fixtures.WellKnownBaseConfigFixture
|
||||
import org.matrix.android.sdk.test.fixtures.WellKnownBaseConfigFixture.aWellKnownBaseConfig
|
||||
|
||||
abstract class DefaultSessionParamsCreatorTestBase {
|
||||
|
||||
protected val discoveryWithHomeServer = DiscoveryInformationFixture.aDiscoveryInformation(homeServer = WellKnownBaseConfigFixture.aWellKnownBaseConfig("http://homeserver_url/"))
|
||||
private val discoveryWithIdentityServer = DiscoveryInformationFixture.aDiscoveryInformation(identityServer = WellKnownBaseConfigFixture.aWellKnownBaseConfig("http://identity_server_url/"))
|
||||
protected val credentials = CredentialsFixture.aCredentials()
|
||||
protected val credentialsWithHomeServer = CredentialsFixture.aCredentials(discoveryInformation = discoveryWithHomeServer)
|
||||
protected val credentialsWithIdentityServer = CredentialsFixture.aCredentials(discoveryInformation = discoveryWithIdentityServer)
|
||||
protected val discoveryWithHomeServer = aDiscoveryInformation(homeServer = aWellKnownBaseConfig("http://homeserver_url/"))
|
||||
private val discoveryWithIdentityServer = aDiscoveryInformation(identityServer = aWellKnownBaseConfig("http://identity_server_url/"))
|
||||
protected val credentials = aCredentials()
|
||||
protected val credentialsWithHomeServer = aCredentials(discoveryInformation = discoveryWithHomeServer)
|
||||
protected val credentialsWithIdentityServer = aCredentials(discoveryInformation = discoveryWithIdentityServer)
|
||||
protected val homeServerConnectionConfig = aHomeServerConnectionConfig()
|
||||
|
||||
protected fun assertExpectedSessionParams(sessionParams: SessionParams) {
|
||||
|
|
|
@ -31,6 +31,10 @@ internal class FakeIsValidClientServerApiTask {
|
|||
|
||||
val instance: IsValidClientServerApiTask = mockk()
|
||||
|
||||
fun givenValidationFails() {
|
||||
coEvery { instance.execute(any()) } returns false
|
||||
}
|
||||
|
||||
fun verifyExecutionWithConfig(config: HomeServerConnectionConfig) {
|
||||
coVerify { instance.execute(Params(config)) }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue