Skip to content

Commit

Permalink
matching variable name with type
Browse files Browse the repository at this point in the history
  • Loading branch information
ouchadam committed May 9, 2022
1 parent 35cf34c commit 474ea13
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.data.WellKnown
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult

private val A_LOGIN_OR_REGISTER_ACTION = OnboardingAction.AuthenticateAction.LoginDirect("@a-user:id.org", "a-password", "a-device-name")
private val A_DIRECT_LOGIN_ACTION = OnboardingAction.AuthenticateAction.LoginDirect("@a-user:id.org", "a-password", "a-device-name")
private val A_WELLKNOWN_SUCCESS_RESULT = WellknownResult.Prompt("https://homeserverurl.com", identityServerUrl = null, WellKnown())
private val A_WELLKNOWN_FAILED_WITH_CONTENT_RESULT = WellknownResult.FailPrompt("https://homeserverurl.com", WellKnown())
private val A_WELLKNOWN_FAILED_WITHOUT_CONTENT_RESULT = WellknownResult.FailPrompt(null, null)
private val NO_HOMESERVER_CONFIG: HomeServerConnectionConfig? = null
private val A_FALLBACK_CONFIG: HomeServerConnectionConfig = HomeServerConnectionConfig(
homeServerUri = FakeUri("https://${A_LOGIN_OR_REGISTER_ACTION.matrixId.getDomain()}").instance,
homeServerUri = FakeUri("https://${A_DIRECT_LOGIN_ACTION.matrixId.getDomain()}").instance,
homeServerUriBase = FakeUri(A_WELLKNOWN_SUCCESS_RESULT.homeServerUrl).instance,
identityServerUri = null
)
Expand All @@ -54,41 +54,41 @@ class DirectLoginUseCaseTest {

@Test
fun `when logging in directly, then returns success with direct session result`() = runTest {
fakeAuthenticationService.givenWellKnown(A_LOGIN_OR_REGISTER_ACTION.matrixId, config = NO_HOMESERVER_CONFIG, result = A_WELLKNOWN_SUCCESS_RESULT)
val (username, password, initialDeviceName) = A_LOGIN_OR_REGISTER_ACTION
fakeAuthenticationService.givenWellKnown(A_DIRECT_LOGIN_ACTION.matrixId, config = NO_HOMESERVER_CONFIG, result = A_WELLKNOWN_SUCCESS_RESULT)
val (username, password, initialDeviceName) = A_DIRECT_LOGIN_ACTION
fakeAuthenticationService.givenDirectAuthentication(A_FALLBACK_CONFIG, username, password, initialDeviceName, result = fakeSession)

val result = useCase.execute(A_LOGIN_OR_REGISTER_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)
val result = useCase.execute(A_DIRECT_LOGIN_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)

result shouldBeEqualTo Result.success(fakeSession)
}

@Test
fun `given wellknown fails with content, when logging in directly, then returns success with direct session result`() = runTest {
fakeAuthenticationService.givenWellKnown(
A_LOGIN_OR_REGISTER_ACTION.matrixId,
A_DIRECT_LOGIN_ACTION.matrixId,
config = NO_HOMESERVER_CONFIG,
result = A_WELLKNOWN_FAILED_WITH_CONTENT_RESULT
)
val (username, password, initialDeviceName) = A_LOGIN_OR_REGISTER_ACTION
val (username, password, initialDeviceName) = A_DIRECT_LOGIN_ACTION
fakeAuthenticationService.givenDirectAuthentication(A_FALLBACK_CONFIG, username, password, initialDeviceName, result = fakeSession)

val result = useCase.execute(A_LOGIN_OR_REGISTER_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)
val result = useCase.execute(A_DIRECT_LOGIN_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)

result shouldBeEqualTo Result.success(fakeSession)
}

@Test
fun `given wellknown fails without content, when logging in directly, then returns well known error`() = runTest {
fakeAuthenticationService.givenWellKnown(
A_LOGIN_OR_REGISTER_ACTION.matrixId,
A_DIRECT_LOGIN_ACTION.matrixId,
config = NO_HOMESERVER_CONFIG,
result = A_WELLKNOWN_FAILED_WITHOUT_CONTENT_RESULT
)
val (username, password, initialDeviceName) = A_LOGIN_OR_REGISTER_ACTION
val (username, password, initialDeviceName) = A_DIRECT_LOGIN_ACTION
fakeAuthenticationService.givenDirectAuthentication(A_FALLBACK_CONFIG, username, password, initialDeviceName, result = fakeSession)

val result = useCase.execute(A_LOGIN_OR_REGISTER_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)
val result = useCase.execute(A_DIRECT_LOGIN_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)

result should { this.isFailure }
result should { this.exceptionOrNull() is Exception }
Expand All @@ -97,20 +97,20 @@ class DirectLoginUseCaseTest {

@Test
fun `given wellknown throws, when logging in directly, then returns failure result with original cause`() = runTest {
fakeAuthenticationService.givenWellKnownThrows(A_LOGIN_OR_REGISTER_ACTION.matrixId, config = NO_HOMESERVER_CONFIG, cause = AN_ERROR)
fakeAuthenticationService.givenWellKnownThrows(A_DIRECT_LOGIN_ACTION.matrixId, config = NO_HOMESERVER_CONFIG, cause = AN_ERROR)

val result = useCase.execute(A_LOGIN_OR_REGISTER_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)
val result = useCase.execute(A_DIRECT_LOGIN_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)

result shouldBeEqualTo Result.failure(AN_ERROR)
}

@Test
fun `given direct authentication throws, when logging in directly, then returns failure result with original cause`() = runTest {
fakeAuthenticationService.givenWellKnown(A_LOGIN_OR_REGISTER_ACTION.matrixId, config = NO_HOMESERVER_CONFIG, result = A_WELLKNOWN_SUCCESS_RESULT)
val (username, password, initialDeviceName) = A_LOGIN_OR_REGISTER_ACTION
fakeAuthenticationService.givenWellKnown(A_DIRECT_LOGIN_ACTION.matrixId, config = NO_HOMESERVER_CONFIG, result = A_WELLKNOWN_SUCCESS_RESULT)
val (username, password, initialDeviceName) = A_DIRECT_LOGIN_ACTION
fakeAuthenticationService.givenDirectAuthenticationThrows(A_FALLBACK_CONFIG, username, password, initialDeviceName, cause = AN_ERROR)

val result = useCase.execute(A_LOGIN_OR_REGISTER_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)
val result = useCase.execute(A_DIRECT_LOGIN_ACTION, homeServerConnectionConfig = NO_HOMESERVER_CONFIG)

result shouldBeEqualTo Result.failure(AN_ERROR)
}
Expand Down

0 comments on commit 474ea13

Please sign in to comment.