@@ -17,7 +17,7 @@ jest.mock('../apns-cert-config');
1717jest . mock ( '@aws-amplify/amplify-prompts' ) ;
1818const prompterMock = prompter as jest . Mocked < typeof prompter > ;
1919
20- const mockPinpointClient = mockClient ( PinpointClient as any ) ;
20+ const mockPinpointClient = mockClient ( PinpointClient ) ;
2121
2222class NoErrorThrownError extends Error { }
2323// wrapper to avoid conditional error checks
@@ -48,8 +48,20 @@ describe('channel-APNS', () => {
4848 mockServiceOutput [ channelName ] = mockChannelOutput ;
4949
5050 const mockPinpointResponseErr = new Error ( 'channel-APNS.test.js error' ) ;
51- const mockPinpointResponseData = {
52- APNSChannelResponse : { Enabled : true , ApplicationId : 'test-app-id' } ,
51+ const mockApnsChannelResponseData = {
52+ APNSChannelResponse : {
53+ Enabled : true ,
54+ ApplicationId : 'test-app-id' ,
55+ Platform : 'APNS' as const ,
56+ } ,
57+ } ;
58+
59+ const mockApnsSandboxChannelResponseData = {
60+ APNSSandboxChannelResponse : {
61+ Enabled : true ,
62+ ApplicationId : 'test-app-id' ,
63+ Platform : 'APNS_SANDBOX' as const ,
64+ } ,
5365 } ;
5466
5567 const mockAPNSChannelResponseData = ( status : boolean , action : ChannelAction , output : $TSAny ) : IChannelAPIResponse => ( {
@@ -74,7 +86,7 @@ describe('channel-APNS', () => {
7486 serviceMeta : {
7587 output : mockServiceOutput ,
7688 } ,
77- pinpointClient : mockPinpointClient as any ,
89+ pinpointClient : mockPinpointClient as unknown as PinpointClient ,
7890 } ,
7991 print : {
8092 info : jest . fn ( ) ,
@@ -96,73 +108,73 @@ describe('channel-APNS', () => {
96108 } ) ;
97109
98110 test ( 'configure' , async ( ) => {
99- mockPinpointClient . on ( UpdateApnsChannelCommand as any ) . resolves ( mockPinpointResponseData as any ) ;
100- mockPinpointClient . on ( UpdateApnsSandboxChannelCommand as any ) . resolves ( mockPinpointResponseData as any ) ;
111+ mockPinpointClient . on ( UpdateApnsChannelCommand ) . resolves ( mockApnsChannelResponseData ) ;
112+ mockPinpointClient . on ( UpdateApnsSandboxChannelCommand ) . resolves ( mockApnsSandboxChannelResponseData ) ;
101113
102114 mockChannelOutput . Enabled = true ;
103115 prompterMock . yesOrNo . mockResolvedValueOnce ( true ) ;
104116 await channelAPNS . configure ( mockContext ) ;
105- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
117+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
106118
107119 mockChannelOutput . Enabled = true ;
108120 prompterMock . yesOrNo . mockResolvedValueOnce ( false ) ;
109121 prompterMock . pick . mockResolvedValueOnce ( 'Certificate' ) ;
110122 await channelAPNS . configure ( mockContext ) ;
111- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
123+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
112124
113125 mockChannelOutput . Enabled = false ;
114126 prompterMock . yesOrNo . mockResolvedValueOnce ( true ) ;
115127 prompterMock . pick . mockResolvedValueOnce ( 'Certificate' ) ;
116128 await channelAPNS . configure ( mockContext ) ;
117- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
129+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
118130 } ) ;
119131
120132 test ( 'enable' , async ( ) => {
121- mockPinpointClient . on ( UpdateApnsChannelCommand as any ) . resolves ( mockPinpointResponseData as any ) ;
122- mockPinpointClient . on ( UpdateApnsSandboxChannelCommand as any ) . resolves ( mockPinpointResponseData as any ) ;
133+ mockPinpointClient . on ( UpdateApnsChannelCommand ) . resolves ( mockApnsChannelResponseData ) ;
134+ mockPinpointClient . on ( UpdateApnsSandboxChannelCommand ) . resolves ( mockApnsSandboxChannelResponseData ) ;
123135
124136 prompterMock . pick . mockResolvedValueOnce ( 'Certificate' ) ;
125137 const disableData = await channelAPNS . enable ( mockContext , 'successMessage' ) ;
126- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
127- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsSandboxChannelCommand as any ) ;
128- expect ( disableData ) . toEqual ( mockAPNSChannelResponseData ( true , ChannelAction . ENABLE , mockPinpointResponseData . APNSChannelResponse ) ) ;
138+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
139+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsSandboxChannelCommand ) ;
140+ expect ( disableData ) . toEqual ( mockAPNSChannelResponseData ( true , ChannelAction . ENABLE , mockApnsChannelResponseData . APNSChannelResponse ) ) ;
129141
130142 prompterMock . pick . mockResolvedValueOnce ( 'Key' ) ;
131143 const enableData = await channelAPNS . enable ( mockContext , 'successMessage' ) ;
132- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
133- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsSandboxChannelCommand as any ) ;
134- expect ( enableData ) . toEqual ( mockAPNSChannelResponseData ( true , ChannelAction . ENABLE , mockPinpointResponseData . APNSChannelResponse ) ) ;
144+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
145+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsSandboxChannelCommand ) ;
146+ expect ( enableData ) . toEqual ( mockAPNSChannelResponseData ( true , ChannelAction . ENABLE , mockApnsChannelResponseData . APNSChannelResponse ) ) ;
135147 } ) ;
136148
137149 test ( 'enable unsuccessful' , async ( ) => {
138- mockPinpointClient . on ( UpdateApnsChannelCommand as any ) . rejects ( mockPinpointResponseErr ) ;
150+ mockPinpointClient . on ( UpdateApnsChannelCommand ) . rejects ( mockPinpointResponseErr ) ;
139151
140152 prompterMock . pick . mockResolvedValueOnce ( 'Certificate' ) ;
141153 const errCert : AmplifyFault = await getError ( async ( ) => channelAPNS . enable ( mockContext , 'successMessage' ) ) ;
142- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
154+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
143155 expect ( errCert ?. downstreamException ?. message ) . toContain ( mockPinpointResponseErr . message ) ;
144156
145157 prompterMock . pick . mockResolvedValueOnce ( 'Key' ) ;
146158 const errKey : AmplifyFault = await getError ( async ( ) => channelAPNS . enable ( mockContext , 'successMessage' ) ) ;
147- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
159+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
148160 expect ( errKey ?. downstreamException ?. message ) . toContain ( mockPinpointResponseErr . message ) ;
149161 } ) ;
150162
151163 test ( 'disable' , async ( ) => {
152- mockPinpointClient . on ( UpdateApnsChannelCommand as any ) . resolves ( mockPinpointResponseData as any ) ;
153- mockPinpointClient . on ( UpdateApnsSandboxChannelCommand as any ) . resolves ( mockPinpointResponseData as any ) ;
164+ mockPinpointClient . on ( UpdateApnsChannelCommand ) . resolves ( mockApnsChannelResponseData ) ;
165+ mockPinpointClient . on ( UpdateApnsSandboxChannelCommand ) . resolves ( mockApnsSandboxChannelResponseData ) ;
154166
155167 const data = await channelAPNS . disable ( mockContext ) ;
156- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
157- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsSandboxChannelCommand as any ) ;
158- expect ( data ) . toEqual ( mockAPNSChannelResponseData ( true , ChannelAction . DISABLE , mockPinpointResponseData . APNSChannelResponse ) ) ;
168+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
169+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsSandboxChannelCommand ) ;
170+ expect ( data ) . toEqual ( mockAPNSChannelResponseData ( true , ChannelAction . DISABLE , mockApnsChannelResponseData . APNSChannelResponse ) ) ;
159171 } ) ;
160172
161173 test ( 'disable unsuccessful' , async ( ) => {
162- mockPinpointClient . on ( UpdateApnsChannelCommand as any ) . rejects ( mockPinpointResponseErr ) ;
174+ mockPinpointClient . on ( UpdateApnsChannelCommand ) . rejects ( mockPinpointResponseErr ) ;
163175
164176 const errKey : AmplifyFault = await getError ( async ( ) => channelAPNS . disable ( mockContext ) ) ;
165- expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand as any ) ;
177+ expect ( mockPinpointClient ) . toHaveReceivedCommand ( UpdateApnsChannelCommand ) ;
166178 expect ( errKey ?. downstreamException ?. message ) . toContain ( mockPinpointResponseErr . message ) ;
167179 } ) ;
168180} ) ;
0 commit comments