9
9
import com .firebase .ui .auth .testhelpers .TestConstants ;
10
10
import com .firebase .ui .auth .testhelpers .TestHelper ;
11
11
import com .firebase .ui .auth .viewmodel .email .RecoverPasswordHandler ;
12
+ import com .google .firebase .auth .ActionCodeSettings ;
12
13
import com .google .firebase .auth .EmailAuthProvider ;
13
14
import com .google .firebase .auth .FirebaseAuth ;
14
15
@@ -39,6 +40,8 @@ public class RecoverPasswordHandlerTest {
39
40
40
41
private RecoverPasswordHandler mHandler ;
41
42
43
+ private ActionCodeSettings mPasswordResetSettings ;
44
+
42
45
@ Before
43
46
public void setUp () {
44
47
TestHelper .initialize ();
@@ -49,6 +52,12 @@ public void setUp() {
49
52
FlowParameters testParams = TestHelper .getFlowParameters (Collections .singletonList (
50
53
EmailAuthProvider .PROVIDER_ID ));
51
54
mHandler .initializeForTesting (testParams , mMockAuth , null , null );
55
+
56
+ mPasswordResetSettings = ActionCodeSettings .newBuilder ()
57
+ .setAndroidPackageName ("com.firebase.uidemo" , true , null )
58
+ .setHandleCodeInApp (true )
59
+ .setUrl ("https://google.com" )
60
+ .build ();
52
61
}
53
62
54
63
@ Test
@@ -59,7 +68,7 @@ public void testReset_sendsRecoverEmail() {
59
68
60
69
// Begin observation, then send the email
61
70
mHandler .getOperation ().observeForever (mObserver );
62
- mHandler .startReset (TestConstants .EMAIL );
71
+ mHandler .startReset (TestConstants .EMAIL , null );
63
72
64
73
// Should get in-progress resource
65
74
verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isLoading ()));
@@ -79,7 +88,7 @@ public void testReset_propagatesFailure() {
79
88
80
89
// Begin observation, then send the email
81
90
mHandler .getOperation ().observeForever (mObserver );
82
- mHandler .startReset (TestConstants .EMAIL );
91
+ mHandler .startReset (TestConstants .EMAIL , null );
83
92
84
93
// Should get in-progress resource
85
94
verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isLoading ()));
@@ -91,4 +100,43 @@ public void testReset_propagatesFailure() {
91
100
verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isFailure ()));
92
101
}
93
102
103
+ @ Test
104
+ public void testReset_sendsCustomRecoverEmail () {
105
+ // Send password email succeeds
106
+ when (mMockAuth .sendPasswordResetEmail (TestConstants .EMAIL , mPasswordResetSettings ))
107
+ .thenReturn (AutoCompleteTask .<Void >forSuccess (null ));
108
+
109
+ // Begin observation, then send the email
110
+ mHandler .getOperation ().observeForever (mObserver );
111
+ mHandler .startReset (TestConstants .EMAIL , mPasswordResetSettings );
112
+
113
+ // Should get in-progress resource
114
+ verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isLoading ()));
115
+
116
+ // Firebase auth should be called
117
+ verify (mMockAuth ).sendPasswordResetEmail (TestConstants .EMAIL , mPasswordResetSettings );
118
+
119
+ // Should get the success resource
120
+ verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isSuccess ()));
121
+ }
122
+
123
+ @ Test
124
+ public void testCustomReset_propagatesFailure () {
125
+ // Send password email fails
126
+ when (mMockAuth .sendPasswordResetEmail (TestConstants .EMAIL , mPasswordResetSettings ))
127
+ .thenReturn (AutoCompleteTask .<Void >forFailure (new Exception ("FAILED" )));
128
+
129
+ // Begin observation, then send the email
130
+ mHandler .getOperation ().observeForever (mObserver );
131
+ mHandler .startReset (TestConstants .EMAIL , mPasswordResetSettings );
132
+
133
+ // Should get in-progress resource
134
+ verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isLoading ()));
135
+
136
+ // Firebase auth should be called
137
+ verify (mMockAuth ).sendPasswordResetEmail (TestConstants .EMAIL , mPasswordResetSettings );
138
+
139
+ // Should get the success resource
140
+ verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isFailure ()));
141
+ }
94
142
}
0 commit comments