@@ -463,6 +463,48 @@ describe('User', function() {
463463      return  expect ( user . _refreshIdToken ( ) ) . not . to . be . rejected ; 
464464    } ) ; 
465465  } ) ; 
466+ 
467+   describe ( '#toJSON' ,  ( )  =>  { 
468+     describe ( 'most fields' ,  ( )  =>  { 
469+       it ( 'should be the same' ,  ( )  =>  { 
470+         const  user  =  new  User ( auth ,  { } ) ; 
471+         const  json  =  user . toJSON ( ) ; 
472+         [ 
473+           'uid' , 
474+           'email' , 
475+           'emailVerified' , 
476+           'displayName' , 
477+           'photoURL' , 
478+           'phoneNumber' , 
479+           'providerData' , 
480+         ] . forEach ( k  =>  expect ( json [ k ] ) . to . deep . equal ( user [ k ] ) ) ; 
481+       } ) ; 
482+     } ) ; 
483+ 
484+     describe ( '.metadata' ,  ( )  =>  { 
485+       it ( 'keys should be missing if omitted' ,  ( )  =>  { 
486+         const  user  =  new  User ( auth ,  { } ) ; 
487+         expect ( user . toJSON ( ) ) . not . to . haveOwnProperty ( 'lastLoginAt' ) ; 
488+         expect ( user . toJSON ( ) ) . not . to . haveOwnProperty ( 'createdAt' ) ; 
489+       } ) ; 
490+ 
491+       it ( 'should populate to lastLogin if present' ,  ( )  =>  { 
492+         const  metadata  =  { 
493+           lastLoginAt : new  Date ( 11 ) . getTime ( ) . toString ( 10 ) , 
494+         } ; 
495+         const  user  =  new  User ( auth ,  {  metadata : metadata ,  } ) ; 
496+         expect ( user . toJSON ( ) . lastLoginAt ) . to . equal ( metadata . lastLoginAt ) ; 
497+       } ) ; 
498+ 
499+       it ( 'should populate to createdAt if present' ,  ( )  =>  { 
500+         const  metadata  =  { 
501+           createdAt : new  Date ( 12 ) . getTime ( ) . toString ( 10 ) , 
502+         } ; 
503+         const  user  =  new  User ( auth ,  {  metadata : metadata ,  } ) ; 
504+         expect ( user . toJSON ( ) . createdAt ) . to . equal ( metadata . createdAt ) ; 
505+       } ) ; 
506+     } ) ; 
507+   } ) ; 
466508} ) ; 
467509
468510function  randomTimestamp ( )  { 
0 commit comments