forked from dmurvihill/firebase-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs.js
118 lines (109 loc) · 3.11 KB
/
docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict';
/* jshint browser:true */
/* globals expect:false */
describe('API.md', () => {
describe('Auth example for changeAuthState', () => {
let ref;
beforeEach(() => {
const Authentication = require('../../src').MockAuthentication;
ref = new Authentication();
});
it('works as described', () => {
const MockUser = require('../../src/user');
ref.changeAuthState(new MockUser(ref, {
uid: 'theUid',
email: 'me@example.com',
emailVerified: true,
displayName: 'Mr. Meeseeks',
phoneNumber: '+1-508-123-4567',
photoURL: 'https://example.com/image.png',
isAnonymous: false,
providerId: 'github',
providerData: [],
refreshToken: '123e4567-e89b-12d3-a456-426655440000',
metadata: {}, // firebase-mock offers limited support for this field
customClaims: {
isAdmin: true,
// etc.
},
_idtoken: 'theToken',
_tokenValidity: {
authTime: '2019-11-22T08:46:15Z',
issuedAtTime: '2019-11-22T08:46:15Z',
expirationTime: '2019-11-22T09:46:15Z',
},
}));
ref.flush();
console.assert(ref.getAuth().displayName === 'Mr. Meeseeks', 'Auth name is correct');
});
});
describe('Messaging examples', () => {
let mockMessaging;
beforeEach(() => {
const Messaging = require('../../').MockMessaging;
mockMessaging = new Messaging();
});
it('send messages', () => {
var message = {
notification: {
title: 'message title',
body: 'foobar'
}
};
var result = mockMessaging.send(message);
mockMessaging.flush();
result.then(function (messageId) {
console.assert(messageId !== '', 'message id is ' + messageId);
});
});
it('returns custom message responses', () => {
var messages = [
{
notification: {
title: 'message title',
body: 'foobar'
}
},
{
notification: {
title: 'message title',
body: 'second message'
}
}
];
var batchResponse = {
failureCount: 1,
responses: [
{
error: "something went wrong",
success: false,
},
{
messageId: "12345",
success: true,
},
],
successCount: 1,
};
mockMessaging.respondNext('sendAll', batchResponse);
var result = mockMessaging.sendAll(messages);
mockMessaging.flush();
result.then(function (response) {
console.assert(response === batchResponse, 'custom batch response is returned');
});
});
it('callback on sending messages', () => {
var message = {
notification: {
title: 'message title',
body: 'foobar'
}
};
mockMessaging.on('send', function(args) {
console.assert(args[0] === message, 'message argument is correct');
});
mockMessaging.send(message);
mockMessaging.flush();
});
});
});