@@ -6,7 +6,8 @@ import { AppSyncRealTimeSubscriptionHandshakeLink } from '../../src/realtime-sub
66const query = gql `subscription { someSubscription { aField } }`
77
88class myWebSocket implements WebSocket {
9- binaryType : BinaryType ; bufferedAmount : number ;
9+ binaryType : BinaryType ;
10+ bufferedAmount : number ;
1011 extensions : string ;
1112 onclose : ( this : WebSocket , ev : CloseEvent ) => any ;
1213 onerror : ( this : WebSocket , ev : Event ) => any ;
@@ -49,8 +50,22 @@ describe("RealTime subscription link", () => {
4950 type : AUTH_TYPE . API_KEY ,
5051 apiKey : 'xxxxx'
5152 } ,
52- region : 'us-east-1' ,
53- url : 'https://xxxxx.appsync-api.amazonaws.com/graphql'
53+ region : 'us-west-2' ,
54+ url : 'https://firsttesturl12345678901234.appsync-api.us-west-2.amazonaws.com/graphql'
55+ } ) ;
56+
57+ expect ( link ) . toBeInstanceOf ( AppSyncRealTimeSubscriptionHandshakeLink ) ;
58+ } ) ;
59+
60+ test ( "Can instantiate link with custom domain" , ( ) => {
61+ expect . assertions ( 1 ) ;
62+ const link = new AppSyncRealTimeSubscriptionHandshakeLink ( {
63+ auth : {
64+ type : AUTH_TYPE . API_KEY ,
65+ apiKey : 'xxxxx'
66+ } ,
67+ region : 'us-west-2' ,
68+ url : 'https://test1.testcustomdomain.com/graphql'
5469 } ) ;
5570
5671 expect ( link ) . toBeInstanceOf ( AppSyncRealTimeSubscriptionHandshakeLink ) ;
@@ -62,7 +77,7 @@ describe("RealTime subscription link", () => {
6277 return "2019-11-13T18:47:04.733Z" ;
6378 } ) ) ;
6479 AppSyncRealTimeSubscriptionHandshakeLink . createWebSocket = jest . fn ( ( url , protocol ) => {
65- expect ( url ) . toBe ( 'wss://xxxxx .appsync-realtime-api.amazonaws.com/graphql?header=eyJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSIsIngtYW16LWRhdGUiOiIyMDE5MTExM1QxODQ3MDRaIiwieC1hcGkta2V5IjoieHh4eHgifQ= =&payload=e30=' ) ;
80+ expect ( url ) . toBe ( 'wss://apikeytesturl1234567890123 .appsync-realtime-api.us-west-2. amazonaws.com/graphql?header=eyJob3N0IjoiYXBpa2V5dGVzdHVybDEyMzQ1Njc4OTAxMjMuYXBwc3luYy1hcGkudXMtd2VzdC0yLmFtYXpvbmF3cy5jb20iLCJ4LWFtei1kYXRlIjoiMjAxOTExMTNUMTg0NzA0WiIsIngtYXBpLWtleSI6Inh4eHh4In0 =&payload=e30=' ) ;
6681 expect ( protocol ) . toBe ( 'graphql-ws' ) ;
6782 done ( ) ;
6883 return new myWebSocket ( ) ;
@@ -72,13 +87,50 @@ describe("RealTime subscription link", () => {
7287 type : AUTH_TYPE . API_KEY ,
7388 apiKey : 'xxxxx'
7489 } ,
75- region : 'us-east-1 ' ,
76- url : 'https://xxxxx .appsync-api.amazonaws.com/graphql'
90+ region : 'us-west-2 ' ,
91+ url : 'https://apikeytesturl1234567890123 .appsync-api.us-west-2 .amazonaws.com/graphql'
7792 } ) ;
7893
7994 execute ( link , { query } ) . subscribe ( {
8095 error : ( err ) => {
81- console . log ( { err } ) ;
96+ console . log ( JSON . stringify ( err ) ) ;
97+ fail ;
98+ } ,
99+ next : ( data ) => {
100+ console . log ( { data } ) ;
101+ done ( ) ;
102+ } ,
103+ complete : ( ) => {
104+ console . log ( 'done with this' ) ;
105+ done ( ) ;
106+ }
107+
108+ } ) ;
109+ } ) ;
110+
111+ test ( "Initialize WebSocket correctly for API KEY with custom domain" , ( done ) => {
112+ expect . assertions ( 2 ) ;
113+ jest . spyOn ( Date . prototype , 'toISOString' ) . mockImplementation ( jest . fn ( ( ) => {
114+ return "2019-11-13T18:47:04.733Z" ;
115+ } ) ) ;
116+ AppSyncRealTimeSubscriptionHandshakeLink . createWebSocket = jest . fn ( ( url , protocol ) => {
117+ expect ( url ) . toBe ( 'wss://apikeytest.testcustomdomain.com/graphql/realtime?header=eyJob3N0IjoiYXBpa2V5dGVzdC50ZXN0Y3VzdG9tZG9tYWluLmNvbSIsIngtYW16LWRhdGUiOiIyMDE5MTExM1QxODQ3MDRaIiwieC1hcGkta2V5IjoieHh4eHgifQ==&payload=e30=' ) ;
118+ expect ( protocol ) . toBe ( 'graphql-ws' ) ;
119+ done ( ) ;
120+ return new myWebSocket ( ) ;
121+ } ) ;
122+ const link = new AppSyncRealTimeSubscriptionHandshakeLink ( {
123+ auth : {
124+ type : AUTH_TYPE . API_KEY ,
125+ apiKey : 'xxxxx'
126+ } ,
127+ region : 'us-west-2' ,
128+ url : 'https://apikeytest.testcustomdomain.com/graphql'
129+ } ) ;
130+
131+ execute ( link , { query } ) . subscribe ( {
132+ error : ( err ) => {
133+ console . log ( JSON . stringify ( err ) ) ;
82134 fail ;
83135 } ,
84136 next : ( data ) => {
@@ -99,7 +151,7 @@ describe("RealTime subscription link", () => {
99151 return "2019-11-13T18:47:04.733Z" ;
100152 } ) ) ;
101153 AppSyncRealTimeSubscriptionHandshakeLink . createWebSocket = jest . fn ( ( url , protocol ) => {
102- expect ( url ) . toBe ( 'wss://xxxxx .appsync-realtime-api.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSJ9 &payload=e30=' ) ;
154+ expect ( url ) . toBe ( 'wss://cognitouserpooltesturl1234 .appsync-realtime-api.us-west-2. amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoiY29nbml0b3VzZXJwb29sdGVzdHVybDEyMzQuYXBwc3luYy1hcGkudXMtd2VzdC0yLmFtYXpvbmF3cy5jb20ifQ== &payload=e30=' ) ;
103155 expect ( protocol ) . toBe ( 'graphql-ws' ) ;
104156 done ( ) ;
105157 return new myWebSocket ( ) ;
@@ -109,13 +161,50 @@ describe("RealTime subscription link", () => {
109161 type : AUTH_TYPE . AMAZON_COGNITO_USER_POOLS ,
110162 jwtToken : 'token'
111163 } ,
112- region : 'us-east-1 ' ,
113- url : 'https://xxxxx .appsync-api.amazonaws.com/graphql'
164+ region : 'us-west-2 ' ,
165+ url : 'https://cognitouserpooltesturl1234 .appsync-api.us-west-2 .amazonaws.com/graphql'
114166 } ) ;
115167
116168 execute ( link , { query } ) . subscribe ( {
117169 error : ( err ) => {
118- console . log ( { err } ) ;
170+ console . log ( JSON . stringify ( err ) ) ;
171+ fail ;
172+ } ,
173+ next : ( data ) => {
174+ console . log ( { data } ) ;
175+ done ( ) ;
176+ } ,
177+ complete : ( ) => {
178+ console . log ( 'done with this' ) ;
179+ done ( ) ;
180+ }
181+
182+ } ) ;
183+ } ) ;
184+
185+ test ( "Initialize WebSocket correctly for COGNITO USER POOLS with custom domain" , ( done ) => {
186+ expect . assertions ( 2 ) ;
187+ jest . spyOn ( Date . prototype , 'toISOString' ) . mockImplementation ( jest . fn ( ( ) => {
188+ return "2019-11-13T18:47:04.733Z" ;
189+ } ) ) ;
190+ AppSyncRealTimeSubscriptionHandshakeLink . createWebSocket = jest . fn ( ( url , protocol ) => {
191+ expect ( url ) . toBe ( 'wss://cognitouserpools.testcustomdomain.com/graphql/realtime?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoiY29nbml0b3VzZXJwb29scy50ZXN0Y3VzdG9tZG9tYWluLmNvbSJ9&payload=e30=' ) ;
192+ expect ( protocol ) . toBe ( 'graphql-ws' ) ;
193+ done ( ) ;
194+ return new myWebSocket ( ) ;
195+ } ) ;
196+ const link = new AppSyncRealTimeSubscriptionHandshakeLink ( {
197+ auth : {
198+ type : AUTH_TYPE . AMAZON_COGNITO_USER_POOLS ,
199+ jwtToken : 'token'
200+ } ,
201+ region : 'us-west-2' ,
202+ url : 'https://cognitouserpools.testcustomdomain.com/graphql'
203+ } ) ;
204+
205+ execute ( link , { query } ) . subscribe ( {
206+ error : ( err ) => {
207+ console . log ( JSON . stringify ( err ) ) ;
119208 fail ;
120209 } ,
121210 next : ( data ) => {
@@ -136,7 +225,44 @@ describe("RealTime subscription link", () => {
136225 return "2019-11-13T18:47:04.733Z" ;
137226 } ) ) ;
138227 AppSyncRealTimeSubscriptionHandshakeLink . createWebSocket = jest . fn ( ( url , protocol ) => {
139- expect ( url ) . toBe ( 'wss://xxxxx.appsync-realtime-api.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSJ9&payload=e30=' ) ;
228+ expect ( url ) . toBe ( 'wss://openidconnecttesturl123456.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0Ijoib3BlbmlkY29ubmVjdHRlc3R1cmwxMjM0NTYuYXBwc3luYy1hcGkudXMtd2VzdC0yLmFtYXpvbmF3cy5jb20ifQ==&payload=e30=' ) ;
229+ expect ( protocol ) . toBe ( 'graphql-ws' ) ;
230+ done ( ) ;
231+ return new myWebSocket ( ) ;
232+ } ) ;
233+ const link = new AppSyncRealTimeSubscriptionHandshakeLink ( {
234+ auth : {
235+ type : AUTH_TYPE . OPENID_CONNECT ,
236+ jwtToken : 'token'
237+ } ,
238+ region : 'us-west-2' ,
239+ url : 'https://openidconnecttesturl123456.appsync-api.us-west-2.amazonaws.com/graphql'
240+ } ) ;
241+
242+ execute ( link , { query } ) . subscribe ( {
243+ error : ( err ) => {
244+ console . log ( JSON . stringify ( err ) ) ;
245+ fail ;
246+ } ,
247+ next : ( data ) => {
248+ console . log ( { data } ) ;
249+ done ( ) ;
250+ } ,
251+ complete : ( ) => {
252+ console . log ( 'done with this' ) ;
253+ done ( ) ;
254+ }
255+
256+ } ) ;
257+ } ) ;
258+
259+ test ( "Initialize WebSocket correctly for OPENID_CONNECT with custom domain" , ( done ) => {
260+ expect . assertions ( 2 ) ;
261+ jest . spyOn ( Date . prototype , 'toISOString' ) . mockImplementation ( jest . fn ( ( ) => {
262+ return "2019-11-13T18:47:04.733Z" ;
263+ } ) ) ;
264+ AppSyncRealTimeSubscriptionHandshakeLink . createWebSocket = jest . fn ( ( url , protocol ) => {
265+ expect ( url ) . toBe ( 'wss://openidconnecttesturl.testcustomdomain.com/graphql/realtime?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0Ijoib3BlbmlkY29ubmVjdHRlc3R1cmwudGVzdGN1c3RvbWRvbWFpbi5jb20ifQ==&payload=e30=' ) ;
140266 expect ( protocol ) . toBe ( 'graphql-ws' ) ;
141267 done ( ) ;
142268 return new myWebSocket ( ) ;
@@ -146,13 +272,13 @@ describe("RealTime subscription link", () => {
146272 type : AUTH_TYPE . OPENID_CONNECT ,
147273 jwtToken : 'token'
148274 } ,
149- region : 'us-east-1 ' ,
150- url : 'https://xxxxx.appsync-api.amazonaws .com/graphql'
275+ region : 'us-west-2 ' ,
276+ url : 'https://openidconnecttesturl.testcustomdomain .com/graphql'
151277 } ) ;
152278
153279 execute ( link , { query } ) . subscribe ( {
154280 error : ( err ) => {
155- console . log ( { err } ) ;
281+ console . log ( JSON . stringify ( err ) ) ;
156282 fail ;
157283 } ,
158284 next : ( data ) => {
@@ -173,7 +299,41 @@ describe("RealTime subscription link", () => {
173299 return "2019-11-13T18:47:04.733Z" ;
174300 } ) ) ;
175301 AppSyncRealTimeSubscriptionHandshakeLink . createWebSocket = jest . fn ( ( url , protocol ) => {
176- expect ( url ) . toBe ( 'wss://xxxxx.appsync-realtime-api.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSJ9&payload=e30=' ) ;
302+ expect ( url ) . toBe ( 'wss://awslambdatesturl1234567890.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoiYXdzbGFtYmRhdGVzdHVybDEyMzQ1Njc4OTAuYXBwc3luYy1hcGkudXMtd2VzdC0yLmFtYXpvbmF3cy5jb20ifQ==&payload=e30=' ) ;
303+ expect ( protocol ) . toBe ( 'graphql-ws' ) ;
304+ done ( ) ;
305+ return new myWebSocket ( ) ;
306+ } ) ;
307+ const link = new AppSyncRealTimeSubscriptionHandshakeLink ( {
308+ auth : {
309+ type : AUTH_TYPE . AWS_LAMBDA ,
310+ token : 'token'
311+ } ,
312+ region : 'us-west-2' ,
313+ url : 'https://awslambdatesturl1234567890.appsync-api.us-west-2.amazonaws.com/graphql'
314+ } ) ;
315+
316+ execute ( link , { query } ) . subscribe ( {
317+ error : ( err ) => {
318+ fail ;
319+ } ,
320+ next : ( data ) => {
321+ done ( ) ;
322+ } ,
323+ complete : ( ) => {
324+ done ( ) ;
325+ }
326+
327+ } ) ;
328+ } )
329+
330+ test ( 'Initialize WebSocket correctly for AWS_LAMBDA with custom domain' , ( done ) => {
331+ expect . assertions ( 2 ) ;
332+ jest . spyOn ( Date . prototype , 'toISOString' ) . mockImplementation ( jest . fn ( ( ) => {
333+ return "2019-11-13T18:47:04.733Z" ;
334+ } ) ) ;
335+ AppSyncRealTimeSubscriptionHandshakeLink . createWebSocket = jest . fn ( ( url , protocol ) => {
336+ expect ( url ) . toBe ( 'wss://awslambdatesturl.testcustomdomain.com/graphql/realtime?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoiYXdzbGFtYmRhdGVzdHVybC50ZXN0Y3VzdG9tZG9tYWluLmNvbSJ9&payload=e30=' ) ;
177337 expect ( protocol ) . toBe ( 'graphql-ws' ) ;
178338 done ( ) ;
179339 return new myWebSocket ( ) ;
@@ -183,8 +343,8 @@ describe("RealTime subscription link", () => {
183343 type : AUTH_TYPE . AWS_LAMBDA ,
184344 token : 'token'
185345 } ,
186- region : 'us-east-1 ' ,
187- url : 'https://xxxxx.appsync-api.amazonaws .com/graphql'
346+ region : 'us-west-2 ' ,
347+ url : 'https://awslambdatesturl.testcustomdomain .com/graphql'
188348 } ) ;
189349
190350 execute ( link , { query } ) . subscribe ( {
0 commit comments