@@ -12,6 +12,7 @@ import {
1212import { ConnectionState as CS } from '../src/types/PubSub' ;
1313
1414import { AWSAppSyncRealTimeProvider } from '../src/Providers/AWSAppSyncRealTimeProvider' ;
15+ import { isCustomDomain } from '../src/Providers/AWSWebSocketProvider/appsyncUrl' ;
1516
1617// Mock all calls to signRequest
1718jest . mock ( '@aws-amplify/core/internals/aws-client-utils' , ( ) => {
@@ -20,7 +21,7 @@ jest.mock('@aws-amplify/core/internals/aws-client-utils', () => {
2021 ) ;
2122 return {
2223 ...original ,
23- signRequest : ( _request , _options ) => {
24+ signRequest : ( _request : any , _options : any ) => {
2425 return {
2526 method : 'test' ,
2627 headers : { test : 'test' } ,
@@ -46,7 +47,7 @@ jest.mock('@aws-amplify/core', () => {
4647 } ;
4748 return {
4849 ...original ,
49- fetchAuthSession : ( _request , _options ) => {
50+ fetchAuthSession : ( _request : any , _options : any ) => {
5051 return Promise . resolve ( session ) ;
5152 } ,
5253 Amplify : {
@@ -66,24 +67,19 @@ jest.mock('@aws-amplify/core', () => {
6667describe ( 'AWSAppSyncRealTimeProvider' , ( ) => {
6768 describe ( 'isCustomDomain()' , ( ) => {
6869 test ( 'Custom domain returns `true`' , ( ) => {
69- const provider = new AWSAppSyncRealTimeProvider ( ) ;
70- const result = ( provider as any ) . isCustomDomain (
71- 'https://unit-test.testurl.com/graphql' ,
72- ) ;
70+ const result = isCustomDomain ( 'https://unit-test.testurl.com/graphql' ) ;
7371 expect ( result ) . toBe ( true ) ;
7472 } ) ;
7573
7674 test ( 'Non-custom domain returns `false`' , ( ) => {
77- const provider = new AWSAppSyncRealTimeProvider ( ) ;
78- const result = ( provider as any ) . isCustomDomain (
75+ const result = isCustomDomain (
7976 'https://12345678901234567890123456.appsync-api.us-west-2.amazonaws.com/graphql' ,
8077 ) ;
8178 expect ( result ) . toBe ( false ) ;
8279 } ) ;
8380
8481 test ( 'Non-custom domain in the amazonaws.com.cn subdomain space returns `false`' , ( ) => {
85- const provider = new AWSAppSyncRealTimeProvider ( ) ;
86- const result = ( provider as any ) . isCustomDomain (
82+ const result = isCustomDomain (
8783 'https://12345678901234567890123456.appsync-api.cn-north-1.amazonaws.com.cn/graphql' ,
8884 ) ;
8985 expect ( result ) . toBe ( false ) ;
@@ -136,10 +132,12 @@ describe('AWSAppSyncRealTimeProvider', () => {
136132 // Saving this spy and resetting it by hand causes badness
137133 // Saving it causes new websockets to be reachable across past tests that have not fully closed
138134 // Resetting it proactively causes those same past tests to be dealing with null while they reach a settled state
139- jest . spyOn ( provider , 'getNewWebSocket' ) . mockImplementation ( ( ) => {
140- fakeWebSocketInterface . newWebSocket ( ) ;
141- return fakeWebSocketInterface . webSocket as WebSocket ;
142- } ) ;
135+ jest
136+ . spyOn ( provider as any , '_getNewWebSocket' )
137+ . mockImplementation ( ( ) => {
138+ fakeWebSocketInterface . newWebSocket ( ) ;
139+ return fakeWebSocketInterface . webSocket as WebSocket ;
140+ } ) ;
143141
144142 // Reduce retry delay for tests to 100ms
145143 Object . defineProperty ( constants , 'MAX_DELAY_MS' , {
@@ -228,7 +226,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
228226 expect . assertions ( 1 ) ;
229227
230228 const newSocketSpy = jest
231- . spyOn ( provider , 'getNewWebSocket ' )
229+ . spyOn ( provider as any , '_getNewWebSocket ' )
232230 . mockImplementation ( ( ) => {
233231 fakeWebSocketInterface . newWebSocket ( ) ;
234232 return fakeWebSocketInterface . webSocket as WebSocket ;
@@ -254,7 +252,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
254252 expect . assertions ( 1 ) ;
255253
256254 const newSocketSpy = jest
257- . spyOn ( provider , 'getNewWebSocket ' )
255+ . spyOn ( provider as any , '_getNewWebSocket ' )
258256 . mockImplementation ( ( ) => {
259257 fakeWebSocketInterface . newWebSocket ( ) ;
260258 return fakeWebSocketInterface . webSocket as WebSocket ;
@@ -280,7 +278,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
280278 expect . assertions ( 1 ) ;
281279
282280 const newSocketSpy = jest
283- . spyOn ( provider , 'getNewWebSocket ' )
281+ . spyOn ( provider as any , '_getNewWebSocket ' )
284282 . mockImplementation ( ( ) => {
285283 fakeWebSocketInterface . newWebSocket ( ) ;
286284 return fakeWebSocketInterface . webSocket as WebSocket ;
@@ -307,7 +305,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
307305 expect . assertions ( 1 ) ;
308306
309307 const newSocketSpy = jest
310- . spyOn ( provider , 'getNewWebSocket ' )
308+ . spyOn ( provider as any , '_getNewWebSocket ' )
311309 . mockImplementation ( ( ) => {
312310 fakeWebSocketInterface . newWebSocket ( ) ;
313311 return fakeWebSocketInterface . webSocket ;
@@ -349,7 +347,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
349347 expect . assertions ( 1 ) ;
350348
351349 const newSocketSpy = jest
352- . spyOn ( provider , 'getNewWebSocket ' )
350+ . spyOn ( provider as any , '_getNewWebSocket ' )
353351 . mockImplementation ( ( ) => {
354352 fakeWebSocketInterface . newWebSocket ( ) ;
355353 return fakeWebSocketInterface . webSocket ;
@@ -545,7 +543,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
545543 await fakeWebSocketInterface ?. standardConnectionHandshake ( ) ;
546544
547545 await fakeWebSocketInterface ?. sendDataMessage ( {
548- type : MESSAGE_TYPES . GQL_DATA ,
546+ type : MESSAGE_TYPES . DATA ,
549547 payload : { data : { } } ,
550548 } ) ;
551549
@@ -571,7 +569,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
571569 connectionTimeoutMs : 100 ,
572570 } ) ;
573571 await fakeWebSocketInterface ?. sendDataMessage ( {
574- type : MESSAGE_TYPES . GQL_DATA ,
572+ type : MESSAGE_TYPES . DATA ,
575573 payload : { data : { } } ,
576574 } ) ;
577575
@@ -597,7 +595,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
597595 connectionTimeoutMs : 100 ,
598596 } ) ;
599597 await fakeWebSocketInterface ?. sendDataMessage ( {
600- type : MESSAGE_TYPES . GQL_DATA ,
598+ type : MESSAGE_TYPES . DATA ,
601599 payload : { data : { } } ,
602600 } ) ;
603601 expect ( mockNext ) . toHaveBeenCalled ( ) ;
@@ -677,7 +675,9 @@ describe('AWSAppSyncRealTimeProvider', () => {
677675 } ) ,
678676 ) ;
679677
680- expect ( socketCloseSpy ) . toHaveBeenNthCalledWith ( 1 , 3001 ) ;
678+ await delay ( 1 ) ;
679+
680+ expect ( socketCloseSpy ) . toHaveBeenCalledWith ( 3001 ) ;
681681 } ) ;
682682
683683 test ( 'subscription observer error is triggered when a connection is formed' , async ( ) => {
@@ -931,7 +931,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
931931
932932 await fakeWebSocketInterface ?. standardConnectionHandshake ( ) ;
933933 await fakeWebSocketInterface ?. sendDataMessage ( {
934- type : MESSAGE_TYPES . GQL_DATA ,
934+ type : MESSAGE_TYPES . DATA ,
935935 payload : { data : { } } ,
936936 } ) ;
937937 await subscription . unsubscribe ( ) ;
@@ -1181,7 +1181,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
11811181 } ) ;
11821182
11831183 test ( 'authenticating with AWS_LAMBDA/custom w/ custom header function that accepts request options' , async ( ) => {
1184- expect . assertions ( 2 ) ;
1184+ expect . assertions ( 3 ) ;
11851185
11861186 provider
11871187 . subscribe ( {
0 commit comments