@@ -197,7 +197,44 @@ describe('Authentication', () => {
197197 expect ( result . current . data . errors as ClaimCheckErrors ) ;
198198 } ) ;
199199
200- it ( 'accepts a custom claims validator' , async ( ) => {
200+ it ( 'accepts a custom claims validator and returns invalid hasRequiredClaims state' , async ( ) => {
201+ const withClaimsCustomToken = {
202+ uid : 'aUserWithCustomClaims' ,
203+ claims : { someClaim : false , someOtherClaim : false }
204+ } ;
205+
206+ const claimsValidator : ClaimsValidator = userClaims => {
207+ const validClaimsSet = [ 'someClaim' , 'someOtherClaim' ] ;
208+ let hasAnyClaim = false ;
209+
210+ for ( const claim of validClaimsSet ) {
211+ if ( userClaims [ claim ] === true ) {
212+ hasAnyClaim = true ;
213+ break ;
214+ }
215+ }
216+
217+ return {
218+ hasRequiredClaims : hasAnyClaim ,
219+ errors : hasAnyClaim ? { } : validClaimsSet
220+ } ;
221+ } ;
222+
223+ const { result, waitFor : waitForHookCondition } = renderHook ( ( ) => useSigninCheck ( { validateCustomClaims : claimsValidator } ) , {
224+ wrapper : Provider
225+ } ) ;
226+
227+ await hooksAct ( async ( ) => {
228+ await app . auth ( ) . signInWithCustomToken ( JSON . stringify ( withClaimsCustomToken ) ) ;
229+ } ) ;
230+
231+ await waitForHookCondition ( ( ) => result . current . status === 'success' ) ;
232+
233+ expect ( result . current . data . signedIn ) . toEqual ( true ) ;
234+ expect ( result . current . data . hasRequiredClaims ) . toEqual ( false ) ;
235+ } ) ;
236+
237+ it ( 'accepts a custom claims validator and returns valid hasRequiredClaims state' , async ( ) => {
201238 const withClaimsCustomToken = {
202239 uid : 'aUserWithCustomClaims' ,
203240 claims : { someClaim : true , someOtherClaim : false }
0 commit comments