1717import * as chai from 'chai' ;
1818import * as chaiAsPromised from 'chai-as-promised' ;
1919import { Message , MulticastMessage , getMessaging } from '../../lib/messaging/index' ;
20- import { legacyTransportApp } from './setup' ;
2120
2221chai . should ( ) ;
2322chai . use ( chaiAsPromised ) ;
2423
2524const expect = chai . expect ;
2625
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
2827// work. The intention of these integration tests is that the endpoints returns the proper payload,
2928// but it is hard to ensure these tokens will always be valid. The tests below should still pass
3029// even if they are rotated or invalid.
3130const registrationToken = 'fGw0qy4TGgk:APA91bGtWGjuhp4WRhHXgbabIYp1jxEKI08ofj_v1bKhWAGJQ4e3arRCW' +
3231 'zeTfHaLz83mBnDh0aPWB1AykXAVUUGl2h1wT4XI6XazWpvY7RBUSYfoxtqSWGIm2nvWh2BOP1YG501SsRoE' ;
33- const notificationKey = 'APA91bFYr4cWCkDs_H9VY2Ai6Erw1ABup1NEYqBjz70O8SzxjpALp_bN913XJMlOepaVv9e' +
34- 'Qs2QrtqX_RZ6cVVv4czgTQXg62qicITR6tQDizaFilDnlVf0' ;
3532
36- const registrationTokens = [ registrationToken + '0' , registrationToken + '1' , registrationToken + '2' ] ;
3733const topic = 'mock-topic' ;
38- const condition = '"test0" in topics || ("test1" in topics && "test2" in topics)' ;
3934
4035const invalidTopic = 'topic-$%#^' ;
4136
@@ -83,30 +78,7 @@ const message: Message = {
8378 topic : 'foo-bar' ,
8479} ;
8580
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-
10481describe ( 'admin.messaging' , ( ) => {
105-
106- before ( ( ) => {
107- getMessaging ( legacyTransportApp ) . enableLegacyHttpTransport ( )
108- } )
109-
11082 it ( 'send(message, dryRun) returns a message ID' , ( ) => {
11183 return getMessaging ( ) . send ( message , true )
11284 . then ( ( name ) => {
@@ -115,37 +87,6 @@ describe('admin.messaging', () => {
11587 } ) ;
11688
11789 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' , ( ) => {
14990 const messages : Message [ ] = [ message , message , message ] ;
15091 return getMessaging ( ) . sendEach ( messages , true )
15192 . then ( ( response ) => {
@@ -159,7 +100,7 @@ describe('admin.messaging', () => {
159100 } ) ;
160101 } ) ;
161102
162- it ( 'sendEach(500) using HTTP2 ' , ( ) => {
103+ it ( 'sendEach(500)' , ( ) => {
163104 const messages : Message [ ] = [ ] ;
164105 for ( let i = 0 ; i < 500 ; i ++ ) {
165106 messages . push ( { topic : `foo-bar-${ i % 10 } ` } ) ;
@@ -176,57 +117,7 @@ describe('admin.messaging', () => {
176117 } ) ;
177118 } ) ;
178119
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-
210120 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' , ( ) => {
230121 const multicastMessage : MulticastMessage = {
231122 data : message . data ,
232123 android : message . android ,
@@ -245,85 +136,6 @@ describe('admin.messaging', () => {
245136 } ) ;
246137 } ) ;
247138
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-
327139 it ( 'subscribeToTopic() returns a response with success count' , ( ) => {
328140 return getMessaging ( ) . subscribeToTopic ( registrationToken , topic )
329141 . then ( ( response ) => {
0 commit comments