@@ -184,24 +184,16 @@ describe('core/credentials/email', () => {
184184 } ) ;
185185 } ) ;
186186
187- it ( 'calls sign in with password with recaptcha forced refresh succeed ' , async ( ) => {
187+ it ( 'calls sign in with password with recaptcha forced refresh' , async ( ) => {
188188 if ( typeof window === 'undefined' ) {
189189 return ;
190190 }
191- // Mock recaptcha js loading method and manually set window.recaptcha
191+ // Mock recaptcha js loading method but not set window.recaptcha to simulate recaptcha token retrieval failure
192192 sinon
193193 . stub ( jsHelpers , '_loadJS' )
194194 . returns ( Promise . resolve ( new Event ( '' ) ) ) ;
195- const recaptcha = new MockGreCAPTCHATopLevel ( ) ;
196- window . grecaptcha = recaptcha ;
197- const stub = sinon . stub ( recaptcha . enterprise , 'execute' ) ;
198-
199- // Force first verification call to fail to simulate verification error
200- // Second verifcation should succeed with site key refreshed
201- stub . onCall ( 0 ) . rejects ( ) ;
202- stub . onCall ( 1 ) . returns ( Promise . resolve ( 'recaptcha-response' ) ) ;
203195
204- mockEndpointWithParams (
196+ const getRecaptchaConfigMock = mockEndpointWithParams (
205197 Endpoint . GET_RECAPTCHA_CONFIG ,
206198 {
207199 clientType : RecaptchaClientType . WEB ,
@@ -212,19 +204,12 @@ describe('core/credentials/email', () => {
212204 await auth . initializeRecaptchaConfig ( ) ;
213205 auth . _agentRecaptchaConfig ! . siteKey = 'cached-site-key' ;
214206
215- const idTokenResponse = await credential . _getIdTokenResponse ( auth ) ;
216- expect ( idTokenResponse . idToken ) . to . eq ( 'id-token' ) ;
217- expect ( idTokenResponse . refreshToken ) . to . eq ( 'refresh-token' ) ;
218- expect ( idTokenResponse . expiresIn ) . to . eq ( '1234' ) ;
219- expect ( idTokenResponse . localId ) . to . eq ( serverUser . localId ) ;
220- expect ( apiMock . calls [ 0 ] . request ) . to . eql ( {
221- captchaResponse : 'recaptcha-response' ,
222- clientType : RecaptchaClientType . WEB ,
223- email : 'some-email' ,
224- password : 'some-password' ,
225- recaptchaVersion : RecaptchaVersion . ENTERPRISE ,
226- returnSecureToken : true
227- } ) ;
207+ await expect ( credential . _getIdTokenResponse ( auth ) ) . to . be . rejectedWith (
208+ 'No reCAPTCHA enterprise script loaded.'
209+ ) ;
210+ // Should call getRecaptchaConfig once to refresh the cached recaptcha config
211+ expect ( getRecaptchaConfigMock . calls . length ) . to . eq ( 2 ) ;
212+ expect ( auth . _agentRecaptchaConfig ?. siteKey ) . to . eq ( 'site-key' ) ;
228213 } ) ;
229214
230215 it ( 'calls fallback to recaptcha flow when receiving MISSING_RECAPTCHA_TOKEN error' , async ( ) => {
0 commit comments