Skip to content

Commit 226a6db

Browse files
committed
Merge branch 'master' into timestamp
# Conflicts: # package-lock.json # src/firestore-document-snapshot.js # src/firestore-document.js # src/firestore-query.js # src/utils.js # test/unit/firestore-collection.js
2 parents 47f0600 + d1bdb43 commit 226a6db

39 files changed

+4400
-619
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.

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
### Added
9+
- Changelog
10+
11+
### Changed
12+
- `MockStorageFile.download()` now allows omitting the destination arg;
13+
in that case, it simply resolves the `Promise` with the file contents
14+
and does not write it anywhere else.
15+
16+
### Fixed
17+
- `onAuthStateChanged` now correctly calls its callback immediately with
18+
the current auth state.
19+
- `MockStorage.bucket()` and `MockStorageBucket.file()` now return the
20+
existing artifact if one exists, rather than overwriting it with a new
21+
one.
22+
- `DataSnapshot.child` now correctly splits child paths by '/'
23+
characters
24+
25+
26+
[Unreleased]: https://github.com/dmurvihill/firebase-mock/compare/v2.2.10...HEAD

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "firebase-mock",
3-
"version": "2.2.10",
3+
"version": "2.3.0",
44
"homepage": "https://github.com/soumak77/firebase-mock",
55
"authors": [
66
"Kato"

0 commit comments

Comments
 (0)