forked from GitLiveApp/firebase-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthTest.kt
47 lines (37 loc) · 1.35 KB
/
AuthTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseAuthInvalidUserException
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
class AuthTest : FirebaseTest() {
private fun createAuth(): FirebaseAuth {
return FirebaseAuth(app).apply {
useEmulator("localhost", 9099)
}
}
@Test
fun `should authenticate via anonymous auth`() = runTest {
val auth = createAuth()
auth.signInAnonymously().await()
assertEquals(true, auth.currentUser?.isAnonymous)
}
@Test
fun `should authenticate via email and password`() = runTest {
val auth = createAuth()
auth.signInWithEmailAndPassword("[email protected]", "securepassword").await()
assertEquals(false, auth.currentUser?.isAnonymous)
}
@Test
fun `should throw exception on invalid password`() {
val auth = createAuth()
val exception = assertThrows(FirebaseAuthInvalidUserException::class.java) {
runBlocking {
auth.signInWithEmailAndPassword("[email protected]", "wrongpassword").await()
}
}
assertEquals("INVALID_PASSWORD", exception.errorCode)
}
}