Skip to content

Commit

Permalink
ktlint --format
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrmz committed Mar 14, 2024
1 parent 24e1a97 commit b369a18
Show file tree
Hide file tree
Showing 32 changed files with 571 additions and 597 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package id.passage.android

internal class IntegrationTestConfig {

companion object {
const val appId = "ADFxfSU7wg3loThFZ9cig3SG"

Check failure on line 5 in passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt#L5 <standard:property-naming>

Property name should use the screaming snake case notation when the value can not be changed
Raw output
passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt:5:19: error: Property name should use the screaming snake case notation when the value can not be changed (standard:property-naming)
const val apiBaseUrl = "https://auth-uat.passage.dev/v1"

Check failure on line 6 in passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt#L6 <standard:property-naming>

Property name should use the screaming snake case notation when the value can not be changed
Raw output
passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt:6:19: error: Property name should use the screaming snake case notation when the value can not be changed (standard:property-naming)
const val existingUserEmail = "[email protected]"

Check failure on line 7 in passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt#L7 <standard:property-naming>

Property name should use the screaming snake case notation when the value can not be changed
Raw output
passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt:7:19: error: Property name should use the screaming snake case notation when the value can not be changed (standard:property-naming)
const val emailWaitTimeMilliseconds: Long = 5000

Check failure on line 8 in passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt#L8 <standard:property-naming>

Property name should use the screaming snake case notation when the value can not be changed
Raw output
passage/src/androidTest/java/id/passage/android/IntegrationTestConfig.kt:8:19: error: Property name should use the screaming snake case notation when the value can not be changed (standard:property-naming)
}

}
25 changes: 13 additions & 12 deletions passage/src/androidTest/java/id/passage/android/MailosaurClient.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import okhttp3.OkHttpClient
import okhttp3.Request
import kotlinx.serialization.Serializable

Check failure on line 1 in passage/src/androidTest/java/id/passage/android/MailosaurClient.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] passage/src/androidTest/java/id/passage/android/MailosaurClient.kt#L1 <standard:filename>

File 'MailosaurClient.kt' contains a single top level declaration and should be named 'MailosaurAPIClient.kt'
Raw output
passage/src/androidTest/java/id/passage/android/MailosaurClient.kt:1:1: error: File 'MailosaurClient.kt' contains a single top level declaration and should be named 'MailosaurAPIClient.kt' (standard:filename)
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import java.util.Base64

@Serializable
Expand All @@ -27,7 +27,7 @@ private data class ListMessage(
val from: List<NameEmail>,
val to: List<NameEmail>,
val cc: List<String>,
val bcc: List<String>
val bcc: List<String>,
)

@Serializable
Expand All @@ -43,11 +43,10 @@ private data class GetMessageResponse(
val to: List<NameEmail>,
val cc: List<String>,
val bcc: List<String>,
val html: MessageHTML
val html: MessageHTML,
)

internal object MailosaurAPIClient {

internal const val serverId = "ncor7c1m"

Check failure on line 50 in passage/src/androidTest/java/id/passage/android/MailosaurClient.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] passage/src/androidTest/java/id/passage/android/MailosaurClient.kt#L50 <standard:property-naming>

Property name should use the screaming snake case notation when the value can not be changed
Raw output
passage/src/androidTest/java/id/passage/android/MailosaurClient.kt:50:24: error: Property name should use the screaming snake case notation when the value can not be changed (standard:property-naming)

private const val apiURL = "https://mailosaur.com/api/messages"

Check failure on line 52 in passage/src/androidTest/java/id/passage/android/MailosaurClient.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] passage/src/androidTest/java/id/passage/android/MailosaurClient.kt#L52 <standard:property-naming>

Property name should use the screaming snake case notation when the value can not be changed
Raw output
passage/src/androidTest/java/id/passage/android/MailosaurClient.kt:52:23: error: Property name should use the screaming snake case notation when the value can not be changed (standard:property-naming)
Expand All @@ -69,10 +68,11 @@ internal object MailosaurAPIClient {
private fun buildRequest(url: String): Request {
return try {
val parsedUrl = url.toHttpUrlOrNull() ?: throw Exception("Bad url path")
val request = Request.Builder()
.url(parsedUrl)
.addHeader("Authorization", authHeader)
.build()
val request =
Request.Builder()
.url(parsedUrl)
.addHeader("Authorization", authHeader)
.build()
request
} catch (e: Exception) {
throw Exception("Bad url path")
Expand All @@ -86,9 +86,10 @@ internal object MailosaurAPIClient {
val message = getMessage(messages[0].id)
val incomingURL = message.html.links[0].href
val components = java.net.URL(incomingURL).query
val magicLink = components.split("&")
.find { it.startsWith("psg_magic_link=") }
?.substringAfter("psg_magic_link=")
val magicLink =
components.split("&")
.find { it.startsWith("psg_magic_link=") }
?.substringAfter("psg_magic_link=")
magicLink ?: ""
} catch (e: Exception) {
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class OneTimePasscodeTests {

private lateinit var passage: Passage

@Before
Expand All @@ -36,87 +35,94 @@ internal class OneTimePasscodeTests {
}

@After
fun teardown() = runTest {
passage.signOutCurrentUser()
}

@get:Rule
var activityRule: ActivityScenarioRule<TestActivity?>? = ActivityScenarioRule(
TestActivity::class.java
)

@Test
fun testRegisterOTPValid() = runTest {
val date = System.currentTimeMillis()
val identifier = "authentigator+$date@passage.id"
try {
passage.newRegisterOneTimePasscode(identifier)
} catch (e: Exception) {
fail("Test failed due to unexpected exception: ${e.message}")
fun teardown() =
runTest {
passage.signOutCurrentUser()
}
}

@Test
fun testRegisterOTPNotValid() = runTest {
val identifier = "INVALID_IDENTIFIER"
try {
passage.newRegisterOneTimePasscode(identifier)
fail("Test should throw NewRegisterOneTimePasscodeInvalidIdentifierException")
} catch (e: Exception) {
assertThat(e is NewRegisterOneTimePasscodeInvalidIdentifierException)
}
}
@get:Rule
var activityRule: ActivityScenarioRule<TestActivity?>? =
ActivityScenarioRule(
TestActivity::class.java,
)

@Test
fun testActivateRegisterOTPValid() = runTest {
runBlocking {
fun testRegisterOTPValid() =
runTest {
val date = System.currentTimeMillis()
val identifier = "authentigator+$date@${MailosaurAPIClient.serverId}.mailosaur.net"
val identifier = "authentigator+$date@passage.id"
try {
val otpId = passage.newRegisterOneTimePasscode(identifier).otpId
delay(emailWaitTimeMilliseconds)
val otp = MailosaurAPIClient.getMostRecentOneTimePasscode()
passage.oneTimePasscodeActivate(otp, otpId)
passage.newRegisterOneTimePasscode(identifier)
} catch (e: Exception) {
fail("Test failed due to unexpected exception: ${e.message}")
}
}
}

@Test
fun testLoginOTPValid() = runTest {
val identifier = existingUserEmail
try {
passage.newLoginOneTimePasscode(identifier)
} catch (e: Exception) {
fail("Test failed due to unexpected exception: ${e.message}")
fun testRegisterOTPNotValid() =
runTest {
val identifier = "INVALID_IDENTIFIER"
try {
passage.newRegisterOneTimePasscode(identifier)
fail("Test should throw NewRegisterOneTimePasscodeInvalidIdentifierException")
} catch (e: Exception) {
assertThat(e is NewRegisterOneTimePasscodeInvalidIdentifierException)
}
}
}

@Test
fun testLoginOTPNotValid() = runTest {
val identifier = "INVALID_IDENTIFIER"
try {
passage.newLoginOneTimePasscode(identifier)
fail("Test should throw NewLoginOneTimePasscodeInvalidIdentifierException")
} catch (e: Exception) {
assertThat(e is NewLoginOneTimePasscodeInvalidIdentifierException)
fun testActivateRegisterOTPValid() =
runTest {
runBlocking {
val date = System.currentTimeMillis()
val identifier = "authentigator+$date@${MailosaurAPIClient.serverId}.mailosaur.net"
try {
val otpId = passage.newRegisterOneTimePasscode(identifier).otpId
delay(emailWaitTimeMilliseconds)
val otp = MailosaurAPIClient.getMostRecentOneTimePasscode()
passage.oneTimePasscodeActivate(otp, otpId)
} catch (e: Exception) {
fail("Test failed due to unexpected exception: ${e.message}")
}
}
}
}

@Test
fun testActivateLoginOTPValid() = runTest {
val identifier = existingUserEmail
runBlocking {
fun testLoginOTPValid() =
runTest {
val identifier = existingUserEmail
try {
val otpId = passage.newLoginOneTimePasscode(identifier).otpId
delay(emailWaitTimeMilliseconds)
val otp = MailosaurAPIClient.getMostRecentOneTimePasscode()
passage.oneTimePasscodeActivate(otp, otpId)
passage.newLoginOneTimePasscode(identifier)
} catch (e: Exception) {
fail("Test failed due to unexpected exception: ${e.message}")
}
}
}

@Test
fun testLoginOTPNotValid() =
runTest {
val identifier = "INVALID_IDENTIFIER"
try {
passage.newLoginOneTimePasscode(identifier)
fail("Test should throw NewLoginOneTimePasscodeInvalidIdentifierException")
} catch (e: Exception) {
assertThat(e is NewLoginOneTimePasscodeInvalidIdentifierException)
}
}

@Test
fun testActivateLoginOTPValid() =
runTest {
val identifier = existingUserEmail
runBlocking {
try {
val otpId = passage.newLoginOneTimePasscode(identifier).otpId
delay(emailWaitTimeMilliseconds)
val otp = MailosaurAPIClient.getMostRecentOneTimePasscode()
passage.oneTimePasscodeActivate(otp, otpId)
} catch (e: Exception) {
fail("Test failed due to unexpected exception: ${e.message}")
}
}
}
}
110 changes: 57 additions & 53 deletions passage/src/androidTest/java/id/passage/android/SocialTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@ package id.passage.android

import android.content.Intent
import androidx.browser.customtabs.CustomTabsIntent.SHARE_STATE_DEFAULT
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.intent.matcher.IntentMatchers.hasDataString
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.google.common.truth.Truth.assertThat
import id.passage.android.IntegrationTestConfig.Companion.apiBaseUrl
import id.passage.android.IntegrationTestConfig.Companion.appId
import id.passage.android.exceptions.FinishSocialAuthenticationInvalidRequestException
import junit.framework.TestCase.fail
import kotlinx.coroutines.test.runTest
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class SocialTests {

private lateinit var passage: Passage

@Before
Expand All @@ -42,58 +41,63 @@ internal class SocialTests {
}

@After
fun teardown() = runTest {
Intents.release()
}
fun teardown() =
runTest {
Intents.release()
}

@get:Rule
var activityRule: ActivityScenarioRule<TestActivity?>? = ActivityScenarioRule(
TestActivity::class.java
)
var activityRule: ActivityScenarioRule<TestActivity?>? =
ActivityScenarioRule(
TestActivity::class.java,
)

@Test
fun testAuthorizeWith() = runTest {
try {
val expectedBasePath = "$apiBaseUrl/apps/${appId}/social/authorize"
val expectedRedirectUri = "redirect_uri=https%3A%2F%2Ftry-uat.passage.dev"
val expectedCodeChallengeMethod = "code_challenge_method=S256"
val expectedConnectionType = "connection_type=github"
val expectedState = "state="
val expectedCodeChallenge = "code_challenge="
fun testAuthorizeWith() =
runTest {
try {
val expectedBasePath = "$apiBaseUrl/apps/$appId/social/authorize"
val expectedRedirectUri = "redirect_uri=https%3A%2F%2Ftry-uat.passage.dev"
val expectedCodeChallengeMethod = "code_challenge_method=S256"
val expectedConnectionType = "connection_type=github"
val expectedState = "state="
val expectedCodeChallenge = "code_challenge="

passage.authorizeWith(PassageSocialConnection.github)
passage.authorizeWith(PassageSocialConnection.github)

intended(allOf(
// Web browser is open
hasAction(Intent.ACTION_VIEW),
// Web browser is a Custom Chrome Tab
hasExtra("androidx.browser.customtabs.extra.SHARE_STATE", SHARE_STATE_DEFAULT),
// Web browser url has expected base path
hasDataString(containsString(expectedBasePath)),
// Web browser url contains expected query params and values
hasDataString(containsString(expectedRedirectUri)),
hasDataString(containsString(expectedCodeChallengeMethod)),
hasDataString(containsString(expectedConnectionType)),
hasDataString(containsString(expectedState)),
hasDataString(containsString(expectedCodeChallenge)),
))
} catch (e: Exception) {
fail("Test failed due to unexpected exception: ${e.message}")
} finally {
// Simulate a back press to dismiss the Custom Chrome Tab
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).pressBack()
intended(
allOf(
// Web browser is open
hasAction(Intent.ACTION_VIEW),
// Web browser is a Custom Chrome Tab
hasExtra("androidx.browser.customtabs.extra.SHARE_STATE", SHARE_STATE_DEFAULT),
// Web browser url has expected base path
hasDataString(containsString(expectedBasePath)),
// Web browser url contains expected query params and values
hasDataString(containsString(expectedRedirectUri)),
hasDataString(containsString(expectedCodeChallengeMethod)),
hasDataString(containsString(expectedConnectionType)),
hasDataString(containsString(expectedState)),
hasDataString(containsString(expectedCodeChallenge)),
),
)
} catch (e: Exception) {
fail("Test failed due to unexpected exception: ${e.message}")
} finally {
// Simulate a back press to dismiss the Custom Chrome Tab
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).pressBack()
}
}
}

@Test
fun testFinishAuthorizationInvalidRequest() = runTest {
try {
val invalidAuthCode = "INVALID_AUTH_CODE"
passage.finishSocialAuthentication(invalidAuthCode)
fail("Test should throw FinishSocialAuthenticationInvalidRequestException")
} catch (e: Exception) {
assertThat(e is FinishSocialAuthenticationInvalidRequestException)
fun testFinishAuthorizationInvalidRequest() =
runTest {
try {
val invalidAuthCode = "INVALID_AUTH_CODE"
passage.finishSocialAuthentication(invalidAuthCode)
fail("Test should throw FinishSocialAuthenticationInvalidRequestException")
} catch (e: Exception) {
assertThat(e is FinishSocialAuthenticationInvalidRequestException)
}
}
}

}
Loading

0 comments on commit b369a18

Please sign in to comment.