@@ -140,4 +140,46 @@ describe('User', function () {
140140 return expect ( user . getIdToken ( true ) ) . to . eventually . not . equal ( token ) ;
141141 } ) ;
142142 } ) ;
143+
144+ describe ( '#toJSON' , ( ) => {
145+ describe ( 'most fields' , ( ) => {
146+ it ( 'should be the same' , ( ) => {
147+ const user = new User ( auth , { } ) ;
148+ const json = user . toJSON ( ) ;
149+ [
150+ 'uid' ,
151+ 'email' ,
152+ 'emailVerified' ,
153+ 'displayName' ,
154+ 'photoURL' ,
155+ 'phoneNumber' ,
156+ 'providerData' ,
157+ ] . forEach ( k => expect ( json [ k ] ) . to . deep . equal ( user [ k ] ) ) ;
158+ } ) ;
159+ } ) ;
160+
161+ describe ( '.metadata' , ( ) => {
162+ it ( 'keys should be missing if omitted' , ( ) => {
163+ const user = new User ( auth , { } ) ;
164+ expect ( user . toJSON ( ) ) . not . to . haveOwnProperty ( 'lastLoginAt' ) ;
165+ expect ( user . toJSON ( ) ) . not . to . haveOwnProperty ( 'createdAt' ) ;
166+ } ) ;
167+
168+ it ( 'should populate to lastLogin if present' , ( ) => {
169+ const metadata = {
170+ lastLoginAt : new Date ( 11 ) . getTime ( ) . toString ( 10 ) ,
171+ } ;
172+ const user = new User ( auth , { metadata : metadata , } ) ;
173+ expect ( user . toJSON ( ) . lastLoginAt ) . to . equal ( metadata . lastLoginAt ) ;
174+ } ) ;
175+
176+ it ( 'should populate to createdAt if present' , ( ) => {
177+ const metadata = {
178+ createdAt : new Date ( 12 ) . getTime ( ) . toString ( 10 ) ,
179+ } ;
180+ const user = new User ( auth , { metadata : metadata , } ) ;
181+ expect ( user . toJSON ( ) . createdAt ) . to . equal ( metadata . createdAt ) ;
182+ } ) ;
183+ } ) ;
184+ } ) ;
143185} ) ;
0 commit comments