@@ -12,6 +12,7 @@ import {
12
12
import { ConnectionState as CS } from '../src/types/PubSub' ;
13
13
14
14
import { AWSAppSyncRealTimeProvider } from '../src/Providers/AWSAppSyncRealTimeProvider' ;
15
+ import { isCustomDomain } from '../src/Providers/AWSWebSocketProvider/appsyncUrl' ;
15
16
16
17
// Mock all calls to signRequest
17
18
jest . mock ( '@aws-amplify/core/internals/aws-client-utils' , ( ) => {
@@ -20,7 +21,7 @@ jest.mock('@aws-amplify/core/internals/aws-client-utils', () => {
20
21
) ;
21
22
return {
22
23
...original ,
23
- signRequest : ( _request , _options ) => {
24
+ signRequest : ( _request : any , _options : any ) => {
24
25
return {
25
26
method : 'test' ,
26
27
headers : { test : 'test' } ,
@@ -46,7 +47,7 @@ jest.mock('@aws-amplify/core', () => {
46
47
} ;
47
48
return {
48
49
...original ,
49
- fetchAuthSession : ( _request , _options ) => {
50
+ fetchAuthSession : ( _request : any , _options : any ) => {
50
51
return Promise . resolve ( session ) ;
51
52
} ,
52
53
Amplify : {
@@ -66,24 +67,19 @@ jest.mock('@aws-amplify/core', () => {
66
67
describe ( 'AWSAppSyncRealTimeProvider' , ( ) => {
67
68
describe ( 'isCustomDomain()' , ( ) => {
68
69
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' ) ;
73
71
expect ( result ) . toBe ( true ) ;
74
72
} ) ;
75
73
76
74
test ( 'Non-custom domain returns `false`' , ( ) => {
77
- const provider = new AWSAppSyncRealTimeProvider ( ) ;
78
- const result = ( provider as any ) . isCustomDomain (
75
+ const result = isCustomDomain (
79
76
'https://12345678901234567890123456.appsync-api.us-west-2.amazonaws.com/graphql' ,
80
77
) ;
81
78
expect ( result ) . toBe ( false ) ;
82
79
} ) ;
83
80
84
81
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 (
87
83
'https://12345678901234567890123456.appsync-api.cn-north-1.amazonaws.com.cn/graphql' ,
88
84
) ;
89
85
expect ( result ) . toBe ( false ) ;
@@ -136,10 +132,12 @@ describe('AWSAppSyncRealTimeProvider', () => {
136
132
// Saving this spy and resetting it by hand causes badness
137
133
// Saving it causes new websockets to be reachable across past tests that have not fully closed
138
134
// 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
+ } ) ;
143
141
144
142
// Reduce retry delay for tests to 100ms
145
143
Object . defineProperty ( constants , 'MAX_DELAY_MS' , {
@@ -228,7 +226,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
228
226
expect . assertions ( 1 ) ;
229
227
230
228
const newSocketSpy = jest
231
- . spyOn ( provider , 'getNewWebSocket ' )
229
+ . spyOn ( provider as any , '_getNewWebSocket ' )
232
230
. mockImplementation ( ( ) => {
233
231
fakeWebSocketInterface . newWebSocket ( ) ;
234
232
return fakeWebSocketInterface . webSocket as WebSocket ;
@@ -254,7 +252,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
254
252
expect . assertions ( 1 ) ;
255
253
256
254
const newSocketSpy = jest
257
- . spyOn ( provider , 'getNewWebSocket ' )
255
+ . spyOn ( provider as any , '_getNewWebSocket ' )
258
256
. mockImplementation ( ( ) => {
259
257
fakeWebSocketInterface . newWebSocket ( ) ;
260
258
return fakeWebSocketInterface . webSocket as WebSocket ;
@@ -280,7 +278,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
280
278
expect . assertions ( 1 ) ;
281
279
282
280
const newSocketSpy = jest
283
- . spyOn ( provider , 'getNewWebSocket ' )
281
+ . spyOn ( provider as any , '_getNewWebSocket ' )
284
282
. mockImplementation ( ( ) => {
285
283
fakeWebSocketInterface . newWebSocket ( ) ;
286
284
return fakeWebSocketInterface . webSocket as WebSocket ;
@@ -307,7 +305,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
307
305
expect . assertions ( 1 ) ;
308
306
309
307
const newSocketSpy = jest
310
- . spyOn ( provider , 'getNewWebSocket ' )
308
+ . spyOn ( provider as any , '_getNewWebSocket ' )
311
309
. mockImplementation ( ( ) => {
312
310
fakeWebSocketInterface . newWebSocket ( ) ;
313
311
return fakeWebSocketInterface . webSocket ;
@@ -349,7 +347,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
349
347
expect . assertions ( 1 ) ;
350
348
351
349
const newSocketSpy = jest
352
- . spyOn ( provider , 'getNewWebSocket ' )
350
+ . spyOn ( provider as any , '_getNewWebSocket ' )
353
351
. mockImplementation ( ( ) => {
354
352
fakeWebSocketInterface . newWebSocket ( ) ;
355
353
return fakeWebSocketInterface . webSocket ;
@@ -545,7 +543,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
545
543
await fakeWebSocketInterface ?. standardConnectionHandshake ( ) ;
546
544
547
545
await fakeWebSocketInterface ?. sendDataMessage ( {
548
- type : MESSAGE_TYPES . GQL_DATA ,
546
+ type : MESSAGE_TYPES . DATA ,
549
547
payload : { data : { } } ,
550
548
} ) ;
551
549
@@ -571,7 +569,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
571
569
connectionTimeoutMs : 100 ,
572
570
} ) ;
573
571
await fakeWebSocketInterface ?. sendDataMessage ( {
574
- type : MESSAGE_TYPES . GQL_DATA ,
572
+ type : MESSAGE_TYPES . DATA ,
575
573
payload : { data : { } } ,
576
574
} ) ;
577
575
@@ -597,7 +595,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
597
595
connectionTimeoutMs : 100 ,
598
596
} ) ;
599
597
await fakeWebSocketInterface ?. sendDataMessage ( {
600
- type : MESSAGE_TYPES . GQL_DATA ,
598
+ type : MESSAGE_TYPES . DATA ,
601
599
payload : { data : { } } ,
602
600
} ) ;
603
601
expect ( mockNext ) . toHaveBeenCalled ( ) ;
@@ -677,7 +675,9 @@ describe('AWSAppSyncRealTimeProvider', () => {
677
675
} ) ,
678
676
) ;
679
677
680
- expect ( socketCloseSpy ) . toHaveBeenNthCalledWith ( 1 , 3001 ) ;
678
+ await delay ( 1 ) ;
679
+
680
+ expect ( socketCloseSpy ) . toHaveBeenCalledWith ( 3001 ) ;
681
681
} ) ;
682
682
683
683
test ( 'subscription observer error is triggered when a connection is formed' , async ( ) => {
@@ -931,7 +931,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
931
931
932
932
await fakeWebSocketInterface ?. standardConnectionHandshake ( ) ;
933
933
await fakeWebSocketInterface ?. sendDataMessage ( {
934
- type : MESSAGE_TYPES . GQL_DATA ,
934
+ type : MESSAGE_TYPES . DATA ,
935
935
payload : { data : { } } ,
936
936
} ) ;
937
937
await subscription . unsubscribe ( ) ;
@@ -1181,7 +1181,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
1181
1181
} ) ;
1182
1182
1183
1183
test ( 'authenticating with AWS_LAMBDA/custom w/ custom header function that accepts request options' , async ( ) => {
1184
- expect . assertions ( 2 ) ;
1184
+ expect . assertions ( 3 ) ;
1185
1185
1186
1186
provider
1187
1187
. subscribe ( {
0 commit comments