Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed May 5, 2024
1 parent 59a9fd7 commit 98820ad
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion GoTrue/src/commonTest/kotlin/AuthTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import io.github.jan.supabase.gotrue.MemorySessionManager
import io.github.jan.supabase.gotrue.SessionStatus
import io.github.jan.supabase.gotrue.auth
import io.github.jan.supabase.gotrue.minimalSettings
import io.github.jan.supabase.gotrue.providers.Github
import io.github.jan.supabase.gotrue.user.UserSession
import io.github.jan.supabase.testing.createMockedSupabaseClient
import io.github.jan.supabase.testing.pathAfterVersion
import io.github.jan.supabase.testing.respondJson
import io.ktor.http.Url
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -68,7 +71,13 @@ class AuthTest {
fun testImportExpiredSession() {
runTest {
val newSession = userSession()
val client = createMockedSupabaseClient(configuration = configuration) {
val client = createMockedSupabaseClient(configuration = {
install(Auth) {
minimalSettings(
alwaysAutoRefresh = true
)
}
}) {
respondJson(newSession)
}
client.auth.awaitInitialization()
Expand Down Expand Up @@ -106,6 +115,44 @@ class AuthTest {
}
}

@Test
fun testGetOAuthUrl() {
runTest {
val expectedProvider = Github
val expectedRedirectUrl = "https://example.com/auth/callback"
val endpoint = "authorize/custom/endpoint"
val supabaseUrl = "https://id.supabase.co"
val client = createMockedSupabaseClient(supabaseUrl = supabaseUrl, configuration = configuration)
client.auth.awaitInitialization()
val url = Url(client.auth.getOAuthUrl(expectedProvider, expectedRedirectUrl, endpoint) {
queryParams["key"] = "value"
scopes.add("scope1")
scopes.add("scope2")
})
assertEquals(
endpoint,
url.pathAfterVersion().substring(1)
)
assertEquals(
expectedProvider.name,
url.parameters["provider"]
)
assertEquals(
expectedRedirectUrl,
url.parameters["redirect_to"]
)
assertEquals(
"value",
url.parameters["key"]
)
assertEquals(
"scope1 scope2",
url.parameters["scopes"]
)
}

}

}

fun userSession(expiresIn: Long = 3600) = UserSession(
Expand Down

0 comments on commit 98820ad

Please sign in to comment.