11import { join } from 'path' ;
22import log from 'npmlog' ;
33import apn from '@parse/node-apn' ;
4- import ParsePushAdapterPackage , { ParsePushAdapter as _ParsePushAdapter , FCM as _FCM , APNS as _APNS , WEB as _WEB , EXPO as _EXPO , utils } from '../src/index.js' ;
4+ import ParsePushAdapterPackage , { ParsePushAdapter as _ParsePushAdapter , FCM as _FCM , APNS as _APNS , APNSNative as _APNSNative , WEB as _WEB , EXPO as _EXPO , utils } from '../src/index.js' ;
55const ParsePushAdapter = _ParsePushAdapter ;
66import { randomString } from '../src/PushAdapterUtils.js' ;
77import MockAPNProvider from './MockAPNProvider.js' ;
88import APNS from '../src/APNS.js' ;
9+ import APNSNative from '../src/APNSNative.js' ;
910import WEB from '../src/WEB.js' ;
1011import FCM from '../src/FCM.js' ;
1112import EXPO from '../src/EXPO.js' ;
@@ -20,6 +21,7 @@ describe('ParsePushAdapter', () => {
2021 expect ( typeof ParsePushAdapterPackage ) . toBe ( 'function' ) ;
2122 expect ( typeof _ParsePushAdapter ) . toBe ( 'function' ) ;
2223 expect ( typeof _APNS ) . toBe ( 'function' ) ;
24+ expect ( typeof _APNSNative ) . toBe ( 'function' ) ;
2325 expect ( typeof _FCM ) . toBe ( 'function' ) ;
2426 expect ( typeof _WEB ) . toBe ( 'function' ) ;
2527 expect ( typeof _EXPO ) . toBe ( 'function' ) ;
@@ -121,6 +123,34 @@ describe('ParsePushAdapter', () => {
121123 done ( ) ;
122124 } ) ;
123125
126+ it ( "can be initialized with APNSNative when useNativeAPNs is true" , async ( ) => {
127+ const { generateKeyPairSync } = await import ( 'node:crypto' ) ;
128+ const { privateKey } = generateKeyPairSync ( 'ec' , { namedCurve : 'prime256v1' } ) ;
129+ const testKeyPEM = privateKey . export ( { type : 'pkcs8' , format : 'pem' } ) ;
130+
131+ const pushConfig = {
132+ android : {
133+ firebaseServiceAccount : join ( __dirname , '..' , 'spec' , 'support' , 'fakeServiceAccount.json' )
134+ } ,
135+ ios : {
136+ useNativeAPNs : true ,
137+ token : { key : testKeyPEM , keyId : 'KEYID12345' , teamId : 'TEAMID1234' } ,
138+ production : false ,
139+ topic : 'com.example.app' ,
140+ } ,
141+ } ;
142+
143+ const parsePushAdapter = new ParsePushAdapter ( pushConfig ) ;
144+ const iosSender = parsePushAdapter . senderMap [ 'ios' ] ;
145+ expect ( iosSender instanceof APNS ) . toBe ( false ) ;
146+ expect ( iosSender instanceof APNSNative ) . toBe ( true ) ;
147+ expect ( Array . isArray ( iosSender . providers ) ) . toBe ( true ) ;
148+ expect ( iosSender . providers . length ) . toBe ( 1 ) ;
149+ expect ( iosSender . providers [ 0 ] . topic ) . toBe ( 'com.example.app' ) ;
150+ const androidSender = parsePushAdapter . senderMap [ 'android' ] ;
151+ expect ( androidSender instanceof FCM ) . toBe ( true ) ;
152+ } ) ;
153+
124154 it ( "can be initialized with FCM for apple and FCM for android" , ( done ) => {
125155 const pushConfig = {
126156 android : {
0 commit comments