Skip to content

Commit 3f4c2cc

Browse files
committed
Add tests
1 parent 93c7f14 commit 3f4c2cc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/unit/user.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)