11var ParsePushAdapter = require ( '../src/index' ) . ParsePushAdapter ;
2+ var randomString = require ( '../src/PushAdapterUtils' ) . randomString ;
23var APNS = require ( '../src/APNS' ) ;
34var GCM = require ( '../src/GCM' ) ;
5+ var MockAPNConnection = require ( './MockAPNConnection' ) ;
46
57describe ( 'ParsePushAdapter' , ( ) => {
8+
9+ beforeEach ( ( ) => {
10+ jasmine . mockLibrary ( 'apn' , 'Connection' , MockAPNConnection ) ;
11+ } ) ;
12+
13+ afterEach ( ( ) => {
14+ jasmine . restoreLibrary ( 'apn' , 'Connection' ) ;
15+ } ) ;
16+
617 it ( 'can be initialized' , ( done ) => {
718 // Make mock config
819 var pushConfig = {
@@ -278,22 +289,22 @@ describe('ParsePushAdapter', () => {
278289 {
279290 deviceType : 'ios' ,
280291 deviceToken : '0d72a1baa92a2febd9a254cbd6584f750c70b2350af5fc9052d1d12584b738e6' ,
281- appIdentifier : 'invalidiosbundleId '
292+ appIdentifier : 'iosbundleId '
282293 } ,
283294 {
284295 deviceType : 'ios' ,
285296 deviceToken : 'ff3943ed0b2090c47e5d6f07d8f202a10427941d7897fda5a6b18c6d9fd07d48' ,
286- appIdentifier : 'invalidiosbundleId '
297+ appIdentifier : 'iosbundleId '
287298 } ,
288299 {
289300 deviceType : 'osx' ,
290301 deviceToken : '5cda62a8d88eb48d9111a6c436f2e326a053eb0cd72dfc3a0893089342602235' ,
291- appIdentifier : 'invalidosxbundleId '
302+ appIdentifier : 'osxbundleId '
292303 } ,
293304 {
294305 deviceType : 'tvos' ,
295306 deviceToken : '3e72a1baa92a2febd9a254cbd6584f750c70b2350af5fc9052d1d12584b738e6' ,
296- appIdentifier : 'invalidiosbundleId ' // ios and tvos share the same bundleid
307+ appIdentifier : 'iosbundleId ' // ios and tvos share the same bundleid
297308 } ,
298309 {
299310 deviceType : 'win' ,
@@ -312,10 +323,19 @@ describe('ParsePushAdapter', () => {
312323 // 2x iOS, 1x android, 1x osx, 1x tvos
313324 expect ( results . length ) . toBe ( 5 ) ;
314325 results . forEach ( ( result ) => {
315- expect ( result . transmitted ) . toBe ( false ) ;
316326 expect ( typeof result . device ) . toBe ( 'object' ) ;
317- expect ( typeof result . device . deviceType ) . toBe ( 'string' ) ;
318- expect ( typeof result . device . deviceToken ) . toBe ( 'string' ) ;
327+ if ( ! result . device ) {
328+ fail ( 'result should have device' ) ;
329+ return ;
330+ }
331+ const device = result . device ;
332+ expect ( typeof device . deviceType ) . toBe ( 'string' ) ;
333+ expect ( typeof device . deviceToken ) . toBe ( 'string' ) ;
334+ if ( device . deviceType === 'ios' || device . deviceType === 'osx' ) {
335+ expect ( result . transmitted ) . toBe ( true ) ;
336+ } else {
337+ expect ( result . transmitted ) . toBe ( false ) ;
338+ }
319339 } )
320340 done ( ) ;
321341 } ) . catch ( ( err ) => {
@@ -324,6 +344,41 @@ describe('ParsePushAdapter', () => {
324344 } )
325345 } ) ;
326346
347+ it ( 'properly marks not transmitter when sender is missing' , ( done ) => {
348+ var pushConfig = {
349+ android : {
350+ senderId : 'senderId' ,
351+ apiKey : 'apiKey'
352+ }
353+ } ;
354+ var installations = [ {
355+ deviceType : 'ios' ,
356+ deviceToken : '0d72a1baa92a2febd9a254cbd6584f750c70b2350af5fc9052d1d12584b738e6' ,
357+ appIdentifier : 'invalidiosbundleId'
358+ } ,
359+ {
360+ deviceType : 'ios' ,
361+ deviceToken : 'ff3943ed0b2090c47e5d6f07d8f202a10427941d7897fda5a6b18c6d9fd07d48' ,
362+ appIdentifier : 'invalidiosbundleId'
363+ } ]
364+ var parsePushAdapter = new ParsePushAdapter ( pushConfig ) ;
365+ parsePushAdapter . send ( { data : { alert : 'some' } } , installations ) . then ( ( results ) => {
366+ expect ( results . length ) . toBe ( 2 ) ;
367+ results . forEach ( ( result ) => {
368+ expect ( result . transmitted ) . toBe ( false ) ;
369+ expect ( typeof result . device ) . toBe ( 'object' ) ;
370+ expect ( typeof result . device . deviceType ) . toBe ( 'string' ) ;
371+ expect ( typeof result . device . deviceToken ) . toBe ( 'string' ) ;
372+ expect ( result . response . error . indexOf ( 'Can not find sender for push type ios, ' ) ) . toBe ( 0 ) ;
373+ } ) ;
374+ done ( ) ;
375+ } ) ;
376+ } ) ;
377+
378+ it ( 'random string throws with size <=0' , ( ) => {
379+ expect ( ( ) => randomString ( 0 ) ) . toThrow ( ) ;
380+ } ) ;
381+
327382 function makeDevice ( deviceToken , deviceType , appIdentifier ) {
328383 return {
329384 deviceToken : deviceToken ,
0 commit comments