@@ -107,33 +107,72 @@ describe('auth() => Phone', function () {
107
107
108
108
it ( 'successfully runs verification complete handler' , async function ( ) {
109
109
const testPhone = getRandomPhoneNumber ( ) ;
110
+ const thenCb = sinon . spy ( ) ;
111
+ await firebase . auth ( ) . verifyPhoneNumber ( testPhone ) . then ( thenCb ) ;
112
+ thenCb . should . be . calledOnce ( ) ;
113
+ const successAuthSnapshot = thenCb . args [ 0 ] [ 0 ] ;
114
+ if ( device . getPlatform ( ) === 'ios' ) {
115
+ successAuthSnapshot . state . should . equal ( 'sent' ) ;
116
+ } else {
117
+ successAuthSnapshot . state . should . equal ( 'timeout' ) ;
118
+ }
119
+ } ) ;
120
+
121
+ it ( 'successfully runs and calls success callback' , async function ( ) {
122
+ const testPhone = getRandomPhoneNumber ( ) ;
123
+ const successCb = sinon . spy ( ) ;
124
+ const observerCb = sinon . spy ( ) ;
125
+ const errorCb = sinon . spy ( ) ;
126
+
110
127
await firebase
111
128
. auth ( )
112
129
. verifyPhoneNumber ( testPhone )
113
- . then ( $ => $ ) ;
114
-
115
- return Promise . resolve ( ) ;
130
+ . on ( 'state_changed' , observerCb , errorCb , successCb ) ;
131
+
132
+ await Utils . spyToBeCalledOnceAsync ( successCb ) ;
133
+ errorCb . should . be . callCount ( 0 ) ;
134
+ successCb . should . be . calledOnce ( ) ;
135
+ let observerAuthSnapshot = observerCb . args [ 0 ] [ 0 ] ;
136
+ const successAuthSnapshot = successCb . args [ 0 ] [ 0 ] ;
137
+ successAuthSnapshot . verificationId . should . be . a . String ( ) ;
138
+ if ( device . getPlatform ( ) === 'ios' ) {
139
+ observerCb . should . be . calledOnce ( ) ;
140
+ successAuthSnapshot . state . should . equal ( 'sent' ) ;
141
+ } else {
142
+ // android waits for SMS auto retrieval which does not work on an emulator
143
+ // it gets a sent and a timeout message on observer, just the timeout on success
144
+ observerCb . should . be . calledTwice ( ) ;
145
+ observerAuthSnapshot = observerCb . args [ 1 ] [ 0 ] ;
146
+ successAuthSnapshot . state . should . equal ( 'timeout' ) ;
147
+ }
148
+ JSON . stringify ( successAuthSnapshot ) . should . equal ( JSON . stringify ( observerAuthSnapshot ) ) ;
116
149
} ) ;
117
150
118
- it ( 'successfully runs and adds emitters' , async function ( ) {
119
- const testPhone = await getRandomPhoneNumber ( ) ;
120
- const obervserCb = ( ) => { } ;
121
- const errorCb = ( ) => { } ;
122
- const successCb = ( ) => {
123
- return Promise . resolve ( ) ;
124
- } ;
151
+ // TODO determine why this is not stable on the emulator, is it also not stable on real device?
152
+ xit ( 'successfully runs and calls error callback' , async function ( ) {
153
+ const successCb = sinon . spy ( ) ;
154
+ const observerCb = sinon . spy ( ) ;
155
+ const errorCb = sinon . spy ( ) ;
125
156
126
157
await firebase
127
158
. auth ( )
128
- . verifyPhoneNumber ( testPhone )
129
- . on ( 'state_changed' , obervserCb , errorCb , successCb , ( ) => { } ) ;
159
+ . verifyPhoneNumber ( 'notaphonenumber' )
160
+ . on ( 'state_changed' , observerCb , errorCb , successCb ) ;
161
+
162
+ await Utils . spyToBeCalledOnceAsync ( errorCb ) ;
163
+ errorCb . should . be . calledOnce ( ) ;
164
+ observerCb . should . be . calledOnce ( ) ;
165
+ // const observerEvent = observerCb.args[0][0];
166
+ successCb . should . be . callCount ( 0 ) ;
167
+ // const errorEvent = errorCb.args[0][0];
168
+ // errorEvent.error.should.containEql('auth/invalid-phone-number');
169
+ // JSON.stringify(errorEvent).should.equal(JSON.stringify(observerEvent));
130
170
} ) ;
131
171
132
172
it ( 'catches an error and emits an error event' , async function ( ) {
133
- return firebase
134
- . auth ( )
135
- . verifyPhoneNumber ( 'test' )
136
- . catch ( ( ) => Promise . resolve ( ) ) ;
173
+ const catchCb = sinon . spy ( ) ;
174
+ await firebase . auth ( ) . verifyPhoneNumber ( 'badphonenumber' ) . catch ( catchCb ) ;
175
+ catchCb . should . be . calledOnce ( ) ;
137
176
} ) ;
138
177
} ) ;
139
178
} ) ;
0 commit comments