Skip to content

Commit d65329d

Browse files
committed
Merge remote-tracking branch 'origin/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 # test/unit/utils.js
2 parents 41174bc + 496b37f commit d65329d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+9664
-3235
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

.jshintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"node": true
2+
"node": true,
3+
"esversion": 6
34
}

.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: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ 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)
22+
- [Messaging](#messaging)
23+
- [`respondNext(methodName, result)`](#respondnextmethodname-result---undefined)
24+
- [`failNext(methodName, err)`](#failnextmethodname-err---undefined)
25+
- [`on(methodName, callback)`](#onmethodname-callback---undefined)
2126

2227
## Core
2328

@@ -117,7 +122,7 @@ function onValue (_snapshot_) {
117122
}
118123
ref.on('value', onValue);
119124
ref.set({
120-
foo: 'bar';
125+
foo: 'bar',
121126
});
122127
ref.flush();
123128
console.assert(ref.getData().foo === 'bar', 'data has foo');
@@ -169,26 +174,46 @@ ref.flush(); // added foo after null
169174

170175
Authentication methods for simulating changes to the auth state of a Firebase reference.
171176

172-
##### `changeAuthState(authData)` -> `undefined`
177+
##### `changeAuthState(user)` -> `undefined`
173178

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`.
179+
Changes the active authentication credentials to the `authData` object.
180+
Before changing the authentication state, `changeAuthState` checks the
181+
`user` object against the current authentication data.
182+
`onAuthStateChanged` listeners will only be triggered if the data is not
183+
deeply equal.
175184

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

178189
Example:
179190

180191
```js
181-
ref.changeAuthState({
192+
ref.changeAuthState(new MockUser(ref, {
182193
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-
});
194+
195+
emailVerified: true,
196+
displayName: 'Mr. Meeseeks',
197+
phoneNumber: '+1-508-123-4567',
198+
photoURL: 'https://example.com/image.png',
199+
isAnonymous: false,
200+
providerId: 'github',
201+
providerData: [],
202+
refreshToken: '123e4567-e89b-12d3-a456-426655440000',
203+
metadata: {}, // firebase-mock offers limited support for this field
204+
customClaims: {
205+
isAdmin: true,
206+
// etc.
207+
},
208+
_idtoken: 'theToken',
209+
_tokenValidity: {
210+
authTime: '2019-11-22T08:46:15Z',
211+
issuedAtTime: '2019-11-22T08:46:15Z',
212+
expirationTime: '2019-11-22T09:46:15Z',
213+
},
214+
}));
190215
ref.flush();
191-
console.assert(ref.getAuth().auth.myAuthProperty, 'authData has custom property');
216+
console.assert(ref.getAuth().displayName === 'Mr. Meeseeks', 'Auth name is correct');
192217
```
193218

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

202227
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.
203228

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

206238
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.
@@ -214,3 +246,31 @@ Instead of using `Date.now()`, MockFirebase will call the `fn` you provide to ge
214246
##### `Firebase.restoreClock()` -> `undefined`
215247

216248
After calling `Firebase.setClock`, calling `Firebase.restoreClock` will restore the default timestamp behavior.
249+
250+
## Messaging
251+
252+
API reference of `MockMessaging`.
253+
254+
##### `respondNext(methodName, result)` -> `undefined`
255+
256+
When `methodName` is next invoked, the `Promise` (that is returned from the `methodName`) will be resolved with the specified `result`. This is useful for testing specific results of firebase messaging (e. g. partial success of sending messaging). The result will be triggered with the next `flush`.
257+
258+
If no result is specified, `methodName` will resolve a default response.
259+
260+
`result` must not be undefined.
261+
262+
<hr>
263+
264+
##### `failNext(methodName, err)` -> `undefined`
265+
266+
When `methodName` is next invoked, the `Promise` will be rejected with the specified `err`. This is useful for simulating validation or any other errors. The error will be triggered with the next `flush`.
267+
268+
`err` must be a proper `Error` object and not a string or any other primitive.
269+
270+
<hr>
271+
272+
##### `on(methodName, callback)` -> `undefined`
273+
274+
When `methodName` is next invoked, the `callback` will be triggered. The callback gets an array as argument. The array contains all arguments, that were passed on invoking `methodName`. This is useful to assert the input arguments of `methodName`.
275+
276+
See [docs.js](/test/unit/docs.js) for an example.

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
- Support for Firebase Messaging (Admin API)
11+
12+
### Changed
13+
- `MockStorageFile.download()` now allows omitting the destination arg;
14+
in that case, it simply resolves the `Promise` with the file contents
15+
and does not write it anywhere else.
16+
17+
### Fixed
18+
- `onAuthStateChanged` now correctly calls its callback immediately with
19+
the current auth state.
20+
- `MockStorage.bucket()` and `MockStorageBucket.file()` now return the
21+
existing artifact if one exists, rather than overwriting it with a new
22+
one.
23+
- `DataSnapshot.child` now correctly splits child paths by '/'
24+
characters
25+
- Boolean values are now allowed in RTDB priority fields and as
26+
arguments to `Query.startAt`, `Query.endAt`, and `Query.equalTo`.
27+
28+
29+
[Unreleased]: https://github.com/dmurvihill/firebase-mock/compare/v2.2.10...HEAD

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Firebase Mock supports the client-side [JavaScript API](https://firebase.google.
3535
* Authentication
3636
* [Basic](tutorials/admin/authentication.md)
3737
* [JWT Tokens](tutorials/admin/tokens.md)
38+
* [Messaging](tutorials/admin/messaging.md)
3839
* [Realtime Database](tutorials/admin/rtdb.md)
3940
* [Firestore](tutorials/admin/firestore.md)
4041
* [Storage](tutorials/admin/storage.md)

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)