17
17
import * as chai from 'chai' ;
18
18
import * as chaiAsPromised from 'chai-as-promised' ;
19
19
import { Message , MulticastMessage , getMessaging } from '../../lib/messaging/index' ;
20
- import { legacyTransportApp } from './setup' ;
21
20
22
21
chai . should ( ) ;
23
22
chai . use ( chaiAsPromised ) ;
24
23
25
24
const expect = chai . expect ;
26
25
27
- // The registration token and notification key have the proper format, but are not guaranteed to
26
+ // The registration token have the proper format, but are not guaranteed to
28
27
// work. The intention of these integration tests is that the endpoints returns the proper payload,
29
28
// but it is hard to ensure these tokens will always be valid. The tests below should still pass
30
29
// even if they are rotated or invalid.
31
30
const registrationToken = 'fGw0qy4TGgk:APA91bGtWGjuhp4WRhHXgbabIYp1jxEKI08ofj_v1bKhWAGJQ4e3arRCW' +
32
31
'zeTfHaLz83mBnDh0aPWB1AykXAVUUGl2h1wT4XI6XazWpvY7RBUSYfoxtqSWGIm2nvWh2BOP1YG501SsRoE' ;
33
- const notificationKey = 'APA91bFYr4cWCkDs_H9VY2Ai6Erw1ABup1NEYqBjz70O8SzxjpALp_bN913XJMlOepaVv9e' +
34
- 'Qs2QrtqX_RZ6cVVv4czgTQXg62qicITR6tQDizaFilDnlVf0' ;
35
32
36
- const registrationTokens = [ registrationToken + '0' , registrationToken + '1' , registrationToken + '2' ] ;
37
33
const topic = 'mock-topic' ;
38
- const condition = '"test0" in topics || ("test1" in topics && "test2" in topics)' ;
39
34
40
35
const invalidTopic = 'topic-$%#^' ;
41
36
@@ -83,30 +78,7 @@ const message: Message = {
83
78
topic : 'foo-bar' ,
84
79
} ;
85
80
86
- const payload = {
87
- data : {
88
- foo : 'bar' ,
89
- } ,
90
- notification : {
91
- title : 'Message title' ,
92
- body : 'Message body' ,
93
- } ,
94
- } ;
95
-
96
- const invalidPayload : any = {
97
- foo : 'bar' ,
98
- } ;
99
-
100
- const options = {
101
- timeToLive : 60 ,
102
- } ;
103
-
104
81
describe ( 'admin.messaging' , ( ) => {
105
-
106
- before ( ( ) => {
107
- getMessaging ( legacyTransportApp ) . enableLegacyHttpTransport ( )
108
- } )
109
-
110
82
it ( 'send(message, dryRun) returns a message ID' , ( ) => {
111
83
return getMessaging ( ) . send ( message , true )
112
84
. then ( ( name ) => {
@@ -115,37 +87,6 @@ describe('admin.messaging', () => {
115
87
} ) ;
116
88
117
89
it ( 'sendEach()' , ( ) => {
118
- const messages : Message [ ] = [ message , message , message ] ;
119
- return getMessaging ( legacyTransportApp ) . sendEach ( messages , true )
120
- . then ( ( response ) => {
121
- expect ( response . responses . length ) . to . equal ( messages . length ) ;
122
- expect ( response . successCount ) . to . equal ( messages . length ) ;
123
- expect ( response . failureCount ) . to . equal ( 0 ) ;
124
- response . responses . forEach ( ( resp ) => {
125
- expect ( resp . success ) . to . be . true ;
126
- expect ( resp . messageId ) . matches ( / ^ p r o j e c t s \/ .* \/ m e s s a g e s \/ .* $ / ) ;
127
- } ) ;
128
- } ) ;
129
- } ) ;
130
-
131
- it ( 'sendEach(500)' , ( ) => {
132
- const messages : Message [ ] = [ ] ;
133
- for ( let i = 0 ; i < 500 ; i ++ ) {
134
- messages . push ( { topic : `foo-bar-${ i % 10 } ` } ) ;
135
- }
136
- return getMessaging ( legacyTransportApp ) . sendEach ( messages , true )
137
- . then ( ( response ) => {
138
- expect ( response . responses . length ) . to . equal ( messages . length ) ;
139
- expect ( response . successCount ) . to . equal ( messages . length ) ;
140
- expect ( response . failureCount ) . to . equal ( 0 ) ;
141
- response . responses . forEach ( ( resp ) => {
142
- expect ( resp . success ) . to . be . true ;
143
- expect ( resp . messageId ) . matches ( / ^ p r o j e c t s \/ .* \/ m e s s a g e s \/ .* $ / ) ;
144
- } ) ;
145
- } ) ;
146
- } ) ;
147
-
148
- it ( 'sendEach() using HTTP2' , ( ) => {
149
90
const messages : Message [ ] = [ message , message , message ] ;
150
91
return getMessaging ( ) . sendEach ( messages , true )
151
92
. then ( ( response ) => {
@@ -159,7 +100,7 @@ describe('admin.messaging', () => {
159
100
} ) ;
160
101
} ) ;
161
102
162
- it ( 'sendEach(500) using HTTP2 ' , ( ) => {
103
+ it ( 'sendEach(500)' , ( ) => {
163
104
const messages : Message [ ] = [ ] ;
164
105
for ( let i = 0 ; i < 500 ; i ++ ) {
165
106
messages . push ( { topic : `foo-bar-${ i % 10 } ` } ) ;
@@ -176,57 +117,7 @@ describe('admin.messaging', () => {
176
117
} ) ;
177
118
} ) ;
178
119
179
- it ( 'sendAll()' , ( ) => {
180
- const messages : Message [ ] = [ message , message , message ] ;
181
- return getMessaging ( ) . sendAll ( messages , true )
182
- . then ( ( response ) => {
183
- expect ( response . responses . length ) . to . equal ( messages . length ) ;
184
- expect ( response . successCount ) . to . equal ( messages . length ) ;
185
- expect ( response . failureCount ) . to . equal ( 0 ) ;
186
- response . responses . forEach ( ( resp ) => {
187
- expect ( resp . success ) . to . be . true ;
188
- expect ( resp . messageId ) . matches ( / ^ p r o j e c t s \/ .* \/ m e s s a g e s \/ .* $ / ) ;
189
- } ) ;
190
- } ) ;
191
- } ) ;
192
-
193
- it ( 'sendAll(500)' , ( ) => {
194
- const messages : Message [ ] = [ ] ;
195
- for ( let i = 0 ; i < 500 ; i ++ ) {
196
- messages . push ( { topic : `foo-bar-${ i % 10 } ` } ) ;
197
- }
198
- return getMessaging ( ) . sendAll ( messages , true )
199
- . then ( ( response ) => {
200
- expect ( response . responses . length ) . to . equal ( messages . length ) ;
201
- expect ( response . successCount ) . to . equal ( messages . length ) ;
202
- expect ( response . failureCount ) . to . equal ( 0 ) ;
203
- response . responses . forEach ( ( resp ) => {
204
- expect ( resp . success ) . to . be . true ;
205
- expect ( resp . messageId ) . matches ( / ^ p r o j e c t s \/ .* \/ m e s s a g e s \/ .* $ / ) ;
206
- } ) ;
207
- } ) ;
208
- } ) ;
209
-
210
120
it ( 'sendEachForMulticast()' , ( ) => {
211
- const multicastMessage : MulticastMessage = {
212
- data : message . data ,
213
- android : message . android ,
214
- tokens : [ 'not-a-token' , 'also-not-a-token' ] ,
215
- } ;
216
- return getMessaging ( legacyTransportApp ) . sendEachForMulticast ( multicastMessage , true )
217
- . then ( ( response ) => {
218
- expect ( response . responses . length ) . to . equal ( 2 ) ;
219
- expect ( response . successCount ) . to . equal ( 0 ) ;
220
- expect ( response . failureCount ) . to . equal ( 2 ) ;
221
- response . responses . forEach ( ( resp ) => {
222
- expect ( resp . success ) . to . be . false ;
223
- expect ( resp . messageId ) . to . be . undefined ;
224
- expect ( resp . error ) . to . have . property ( 'code' , 'messaging/invalid-argument' ) ;
225
- } ) ;
226
- } ) ;
227
- } ) ;
228
-
229
- it ( 'sendEachForMulticast() using HTTP2' , ( ) => {
230
121
const multicastMessage : MulticastMessage = {
231
122
data : message . data ,
232
123
android : message . android ,
@@ -245,85 +136,6 @@ describe('admin.messaging', () => {
245
136
} ) ;
246
137
} ) ;
247
138
248
- it ( 'sendMulticast()' , ( ) => {
249
- const multicastMessage : MulticastMessage = {
250
- data : message . data ,
251
- android : message . android ,
252
- tokens : [ 'not-a-token' , 'also-not-a-token' ] ,
253
- } ;
254
- return getMessaging ( ) . sendMulticast ( multicastMessage , true )
255
- . then ( ( response ) => {
256
- expect ( response . responses . length ) . to . equal ( 2 ) ;
257
- expect ( response . successCount ) . to . equal ( 0 ) ;
258
- expect ( response . failureCount ) . to . equal ( 2 ) ;
259
- response . responses . forEach ( ( resp ) => {
260
- expect ( resp . success ) . to . be . false ;
261
- expect ( resp . messageId ) . to . be . undefined ;
262
- expect ( resp . error ) . to . have . property ( 'code' , 'messaging/invalid-argument' ) ;
263
- } ) ;
264
- } ) ;
265
- } ) ;
266
-
267
- it ( 'sendToDevice(token) returns a response with multicast ID' , ( ) => {
268
- return getMessaging ( ) . sendToDevice ( registrationToken , payload , options )
269
- . then ( ( response ) => {
270
- expect ( typeof response . multicastId ) . to . equal ( 'number' ) ;
271
- } ) ;
272
- } ) ;
273
-
274
- it ( 'sendToDevice(token-list) returns a response with multicat ID' , ( ) => {
275
- return getMessaging ( ) . sendToDevice ( registrationTokens , payload , options )
276
- . then ( ( response ) => {
277
- expect ( typeof response . multicastId ) . to . equal ( 'number' ) ;
278
- } ) ;
279
- } ) ;
280
-
281
- it . skip ( 'sendToDeviceGroup() returns a response with success count' , ( ) => {
282
- return getMessaging ( ) . sendToDeviceGroup ( notificationKey , payload , options )
283
- . then ( ( response ) => {
284
- expect ( typeof response . successCount ) . to . equal ( 'number' ) ;
285
- } ) ;
286
- } ) ;
287
-
288
- it ( 'sendToTopic() returns a response with message ID' , ( ) => {
289
- return getMessaging ( ) . sendToTopic ( topic , payload , options )
290
- . then ( ( response ) => {
291
- expect ( typeof response . messageId ) . to . equal ( 'number' ) ;
292
- } ) ;
293
- } ) ;
294
-
295
- it ( 'sendToCondition() returns a response with message ID' , ( ) => {
296
- return getMessaging ( ) . sendToCondition ( condition , payload , options )
297
- . then ( ( response ) => {
298
- expect ( typeof response . messageId ) . to . equal ( 'number' ) ;
299
- } ) ;
300
- } ) ;
301
-
302
- it ( 'sendToDevice(token) fails when called with invalid payload' , ( ) => {
303
- return getMessaging ( ) . sendToDevice ( registrationToken , invalidPayload , options )
304
- . should . eventually . be . rejected . and . have . property ( 'code' , 'messaging/invalid-payload' ) ;
305
- } ) ;
306
-
307
- it ( 'sendToDevice(token-list) fails when called with invalid payload' , ( ) => {
308
- return getMessaging ( ) . sendToDevice ( registrationTokens , invalidPayload , options )
309
- . should . eventually . be . rejected . and . have . property ( 'code' , 'messaging/invalid-payload' ) ;
310
- } ) ;
311
-
312
- it ( 'sendToDeviceGroup() fails when called with invalid payload' , ( ) => {
313
- return getMessaging ( ) . sendToDeviceGroup ( notificationKey , invalidPayload , options )
314
- . should . eventually . be . rejected . and . have . property ( 'code' , 'messaging/invalid-payload' ) ;
315
- } ) ;
316
-
317
- it ( 'sendToTopic() fails when called with invalid payload' , ( ) => {
318
- return getMessaging ( ) . sendToTopic ( topic , invalidPayload , options )
319
- . should . eventually . be . rejected . and . have . property ( 'code' , 'messaging/invalid-payload' ) ;
320
- } ) ;
321
-
322
- it ( 'sendToCondition() fails when called with invalid payload' , ( ) => {
323
- return getMessaging ( ) . sendToCondition ( condition , invalidPayload , options )
324
- . should . eventually . be . rejected . and . have . property ( 'code' , 'messaging/invalid-payload' ) ;
325
- } ) ;
326
-
327
139
it ( 'subscribeToTopic() returns a response with success count' , ( ) => {
328
140
return getMessaging ( ) . subscribeToTopic ( registrationToken , topic )
329
141
. then ( ( response ) => {
0 commit comments