Skip to content

Commit 35f1094

Browse files
committed
Merge branch 'master' into add-user-json
# Conflicts: # src/user.js
2 parents 3f4c2cc + 746646c commit 35f1094

32 files changed

+1766
-262
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
node_modules
44
coverage
55
browser
6+
.vscode

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_js:
44
- "4.5"
55
- "5.12"
66
- "6.4"
7+
- "8"
78
before_script:
89
- gulp lint
910
script:

API.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ Only `MockFirebase` methods are included here. For details on normal Firebase AP
1212
- [`fakeEvent(event [, key] [, data] [, previousChild] [, priority])`](#fakeeventevent--key--data--previouschild--priority---ref)
1313
- [`getFlushQueue()`](#getflushqueue---array)
1414
- [Auth](#auth)
15-
- [`changeAuthState(user)`](#changeauthstateauthdata---undefined)
16-
- [`getUserByEmail(email)`](#getemailuseremail---objectnull)
17-
- [`getUser(uid)`](#getemailuseremail---objectnull)
15+
- [`changeAuthState(user)`](#changeauthstateuser---undefined)
16+
- [`getUserByEmail(email)`](#getuserbyemailemail---promiseobject)
17+
- [`getUser(uid)`](#getuseruid---promiseobject)
18+
- [`updateUser(user)`](#updateuseruser---promisemockuser)
1819
- [Server Timestamps](#server-timestamps)
1920
- [`setClock(fn)`](#firebasesetclockfn---undefined)
2021
- [`restoreClock()`](#firebasesetclockfn---undefined)
@@ -117,7 +118,7 @@ function onValue (_snapshot_) {
117118
}
118119
ref.on('value', onValue);
119120
ref.set({
120-
foo: 'bar';
121+
foo: 'bar',
121122
});
122123
ref.flush();
123124
console.assert(ref.getData().foo === 'bar', 'data has foo');
@@ -169,26 +170,46 @@ ref.flush(); // added foo after null
169170

170171
Authentication methods for simulating changes to the auth state of a Firebase reference.
171172

172-
##### `changeAuthState(authData)` -> `undefined`
173+
##### `changeAuthState(user)` -> `undefined`
173174

174-
Changes the active authentication credentials to the `authData` object. Before changing the authentication state, `changeAuthState` checks whether the `authData` object is deeply equal to the current authentication data. `onAuth` listeners will only be triggered if the data is not deeply equal. To simulate no user being authenticated, pass `null` for `authData`. This operation is queued until the next `flush`.
175+
Changes the active authentication credentials to the `authData` object.
176+
Before changing the authentication state, `changeAuthState` checks the
177+
`user` object against the current authentication data.
178+
`onAuthStateChanged` listeners will only be triggered if the data is not
179+
deeply equal.
175180

176-
`authData` should adhere to the [documented schema](https://www.firebase.com/docs/web/api/firebase/onauth.html).
181+
`user` should be a `MockUser` object or an object with the same fields
182+
as `MockUser`. To simulate no user being authenticated, pass `null` for
183+
`user`. This operation is queued until the next `flush`.
177184

178185
Example:
179186

180187
```js
181-
ref.changeAuthState({
188+
ref.changeAuthState(new MockUser(ref, {
182189
uid: 'theUid',
183-
provider: 'github',
184-
token: 'theToken',
185-
expires: Math.floor(new Date() / 1000) + 24 * 60 * 60, // expire in 24 hours
186-
auth: {
187-
myAuthProperty: true
188-
}
189-
});
190+
191+
emailVerified: true,
192+
displayName: 'Mr. Meeseeks',
193+
phoneNumber: '+1-508-123-4567',
194+
photoURL: 'https://example.com/image.png',
195+
isAnonymous: false,
196+
providerId: 'github',
197+
providerData: [],
198+
refreshToken: '123e4567-e89b-12d3-a456-426655440000',
199+
metadata: {}, // firebase-mock offers limited support for this field
200+
customClaims: {
201+
isAdmin: true,
202+
// etc.
203+
},
204+
_idtoken: 'theToken',
205+
_tokenValidity: {
206+
authTime: '2019-11-22T08:46:15Z',
207+
issuedAtTime: '2019-11-22T08:46:15Z',
208+
expirationTime: '2019-11-22T09:46:15Z',
209+
},
210+
}));
190211
ref.flush();
191-
console.assert(ref.getAuth().auth.myAuthProperty, 'authData has custom property');
212+
console.assert(ref.getAuth().displayName === 'Mr. Meeseeks', 'Auth name is correct');
192213
```
193214

194215
<hr>
@@ -201,6 +222,13 @@ Finds a user previously created with [`createUser`](https://www.firebase.com/doc
201222

202223
Finds a user previously created with [`createUser`](https://www.firebase.com/docs/web/api/firebase/createuser.html). If no user was created with the specified `email`, the promise is rejected.
203224

225+
##### `updateUser(user)` -> `Promise<MockUser>`
226+
227+
Replace the existing user with a new one, by matching uid. Throws an
228+
error if no user exists whose uid matches the given user's uid. Resolves
229+
with the updated user when complete. This operation is queued until the
230+
next flush.
231+
204232
## Server Timestamps
205233

206234
MockFirebase allow you to simulate the behavior of [server timestamps](https://www.firebase.com/docs/web/api/servervalue/timestamp.html) when using a real Firebase instance. Unless you use `Firebase.setClock`, `Firebase.ServerValue.TIMESTAMP` will be transformed to the current date (`Date.now()`) when your data change is flushed.

0 commit comments

Comments
 (0)