Skip to content

Commit 632fc1d

Browse files
committed
fix failing tests
1 parent 60a0b3d commit 632fc1d

File tree

4 files changed

+45
-529
lines changed

4 files changed

+45
-529
lines changed

auth/src/main/java/com/firebase/ui/auth/compose/mfa/SmsEnrollmentHandler.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
package com.firebase.ui.auth.compose.mfa
1616

17+
import android.app.Activity
1718
import com.firebase.ui.auth.compose.configuration.auth_provider.AuthProvider
19+
import com.firebase.ui.auth.compose.mfa.SmsEnrollmentHandler.Companion.RESEND_DELAY_SECONDS
1820
import com.google.firebase.auth.FirebaseAuth
1921
import com.google.firebase.auth.FirebaseUser
20-
import com.google.firebase.auth.MultiFactorAssertion
2122
import com.google.firebase.auth.PhoneAuthCredential
2223
import com.google.firebase.auth.PhoneAuthProvider
2324
import com.google.firebase.auth.PhoneMultiFactorGenerator
@@ -61,6 +62,7 @@ import kotlinx.coroutines.tasks.await
6162
* @see AuthProvider.Phone.verifyPhoneNumberAwait
6263
*/
6364
class SmsEnrollmentHandler(
65+
private val activity: Activity,
6466
private val auth: FirebaseAuth,
6567
private val user: FirebaseUser
6668
) {
@@ -98,6 +100,7 @@ class SmsEnrollmentHandler(
98100
val multiFactorSession = user.multiFactor.session.await()
99101
val result = phoneProvider.verifyPhoneNumberAwait(
100102
auth = auth,
103+
activity = activity,
101104
phoneNumber = phoneNumber,
102105
multiFactorSession = multiFactorSession,
103106
forceResendingToken = null
@@ -145,6 +148,7 @@ class SmsEnrollmentHandler(
145148
val multiFactorSession = user.multiFactor.session.await()
146149
val result = phoneProvider.verifyPhoneNumberAwait(
147150
auth = auth,
151+
activity = activity,
148152
phoneNumber = session.phoneNumber,
149153
multiFactorSession = multiFactorSession,
150154
forceResendingToken = session.forceResendingToken

auth/src/test/java/com/firebase/ui/auth/compose/configuration/auth_provider/PhoneAuthProviderFirebaseAuthUITest.kt

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.mockito.MockitoAnnotations
4242
import org.mockito.kotlin.any
4343
import org.mockito.kotlin.anyOrNull
4444
import org.mockito.kotlin.eq
45+
import org.mockito.kotlin.timeout
4546
import org.robolectric.RobolectricTestRunner
4647
import org.robolectric.annotation.Config
4748

@@ -121,17 +122,19 @@ class PhoneAuthProviderFirebaseAuthUITest {
121122

122123
`when`(
123124
mockPhoneAuthVerifier.verifyPhoneNumber(
124-
any(),
125-
any(),
126-
any(),
127-
anyOrNull(),
128-
anyOrNull(),
129-
eq(true)
125+
auth = any(),
126+
activity = anyOrNull(),
127+
phoneNumber = any(),
128+
timeout = eq(60L),
129+
forceResendingToken = anyOrNull(),
130+
multiFactorSession = anyOrNull(),
131+
isInstantVerificationEnabled = eq(true)
130132
)
131133
).thenReturn(AuthProvider.Phone.VerifyPhoneNumberResult.AutoVerified(mockCredential))
132134

133135
instance.verifyPhoneNumber(
134136
provider = phoneProvider,
137+
activity = null,
135138
phoneNumber = "+1234567890",
136139
verifier = mockPhoneAuthVerifier
137140
)
@@ -157,12 +160,13 @@ class PhoneAuthProviderFirebaseAuthUITest {
157160

158161
`when`(
159162
mockPhoneAuthVerifier.verifyPhoneNumber(
160-
any(),
161-
any(),
162-
any(),
163-
anyOrNull(),
164-
anyOrNull(),
165-
eq(true)
163+
auth = any(),
164+
activity = anyOrNull(),
165+
phoneNumber = any(),
166+
timeout = eq(60L),
167+
forceResendingToken = anyOrNull(),
168+
multiFactorSession = anyOrNull(),
169+
isInstantVerificationEnabled = eq(true)
166170
)
167171
).thenReturn(
168172
AuthProvider.Phone.VerifyPhoneNumberResult.NeedsManualVerification(
@@ -173,6 +177,7 @@ class PhoneAuthProviderFirebaseAuthUITest {
173177

174178
instance.verifyPhoneNumber(
175179
provider = phoneProvider,
180+
activity = null,
176181
phoneNumber = "+1234567890",
177182
verifier = mockPhoneAuthVerifier
178183
)
@@ -200,12 +205,13 @@ class PhoneAuthProviderFirebaseAuthUITest {
200205

201206
`when`(
202207
mockPhoneAuthVerifier.verifyPhoneNumber(
203-
any(),
204-
any(),
205-
any(),
206-
eq(mockToken),
207-
anyOrNull(),
208-
eq(true)
208+
auth = any(),
209+
activity = anyOrNull(),
210+
phoneNumber = any(),
211+
timeout = eq(60L),
212+
forceResendingToken = eq(mockToken),
213+
multiFactorSession = anyOrNull(),
214+
isInstantVerificationEnabled = eq(true)
209215
)
210216
).thenReturn(
211217
AuthProvider.Phone.VerifyPhoneNumberResult.NeedsManualVerification(
@@ -216,6 +222,7 @@ class PhoneAuthProviderFirebaseAuthUITest {
216222

217223
instance.verifyPhoneNumber(
218224
provider = phoneProvider,
225+
activity = null,
219226
phoneNumber = "+1234567890",
220227
forceResendingToken = mockToken,
221228
verifier = mockPhoneAuthVerifier
@@ -242,12 +249,13 @@ class PhoneAuthProviderFirebaseAuthUITest {
242249

243250
`when`(
244251
mockPhoneAuthVerifier.verifyPhoneNumber(
245-
any(),
246-
any(),
247-
any(),
248-
anyOrNull(),
249-
anyOrNull(),
250-
eq(false)
252+
auth = any(),
253+
activity = anyOrNull(),
254+
phoneNumber = any(),
255+
timeout = eq(60L),
256+
forceResendingToken = anyOrNull(),
257+
multiFactorSession = anyOrNull(),
258+
isInstantVerificationEnabled = eq(false)
251259
)
252260
).thenReturn(
253261
AuthProvider.Phone.VerifyPhoneNumberResult.NeedsManualVerification(
@@ -258,14 +266,16 @@ class PhoneAuthProviderFirebaseAuthUITest {
258266

259267
instance.verifyPhoneNumber(
260268
provider = phoneProvider,
269+
activity = null,
261270
phoneNumber = "+1234567890",
262271
verifier = mockPhoneAuthVerifier
263272
)
264273

265274
verify(mockPhoneAuthVerifier).verifyPhoneNumber(
266275
any(),
276+
anyOrNull(),
267277
any(),
268-
any(),
278+
eq(60L),
269279
anyOrNull(),
270280
anyOrNull(),
271281
eq(false)

auth/src/test/java/com/firebase/ui/auth/compose/mfa/SmsEnrollmentHandlerTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.firebase.ui.auth.compose.mfa
1616

17+
import android.app.Activity
1718
import com.google.firebase.auth.FirebaseAuth
1819
import com.google.firebase.auth.FirebaseUser
1920
import com.google.firebase.auth.MultiFactor
@@ -42,6 +43,8 @@ import org.robolectric.annotation.Config
4243
@Config(manifest = Config.NONE)
4344
class SmsEnrollmentHandlerTest {
4445

46+
@Mock
47+
private lateinit var mockActivity: Activity
4548
@Mock
4649
private lateinit var mockAuth: FirebaseAuth
4750
@Mock
@@ -54,7 +57,7 @@ class SmsEnrollmentHandlerTest {
5457
fun setUp() {
5558
MockitoAnnotations.openMocks(this)
5659
`when`(mockUser.multiFactor).thenReturn(mockMultiFactor)
57-
handler = SmsEnrollmentHandler(mockAuth, mockUser)
60+
handler = SmsEnrollmentHandler(mockActivity, mockAuth, mockUser)
5861
}
5962

6063
// isValidCodeFormat tests
@@ -153,7 +156,7 @@ class SmsEnrollmentHandlerTest {
153156
@Test
154157
fun `handler is created with correct auth and user references`() {
155158
// Verify handler can be instantiated
156-
val newHandler = SmsEnrollmentHandler(mockAuth, mockUser)
159+
val newHandler = SmsEnrollmentHandler(mockActivity, mockAuth, mockUser)
157160
// Basic smoke test - if we get here, construction succeeded
158161
assertTrue(newHandler.isValidCodeFormat("123456"))
159162
}

0 commit comments

Comments
 (0)