@@ -7,16 +7,18 @@ import * as Paho from '../src/vendor/paho-mqtt';
77
88const pahoClientMockCache = { } ;
99
10+ const mockConnect = jest . fn ( ( options ) => {
11+ options . onSuccess ( ) ;
12+ } ) ;
13+
1014const pahoClientMock = jest . fn ( ) . mockImplementation ( ( host , clientId ) => {
1115 if ( pahoClientMockCache [ clientId ] ) {
1216 return pahoClientMockCache [ clientId ] ;
1317 }
1418
1519 var client = { } as any ;
1620
17- client . connect = jest . fn ( ( options ) => {
18- options . onSuccess ( ) ;
19- } ) ;
21+ client . connect = mockConnect ;
2022 client . send = jest . fn ( ( topic , message ) => {
2123 client . onMessageArrived ( { destinationName : topic , payloadString : message } ) ;
2224 } ) ;
@@ -213,6 +215,32 @@ describe('PubSub', () => {
213215 } ) ;
214216 } ) ;
215217
218+ describe ( 'MqttOverWSProvider local testing config' , ( ) => {
219+ test ( 'ssl should be disabled in the case of local testing' , async ( ) => {
220+ mockConnect . mockClear ( ) ;
221+ const pubsub = new PubSub ( ) ;
222+
223+ const mqttOverWSProvider = new MqttOverWSProvider ( {
224+ aws_pubsub_region : 'region' ,
225+ aws_appsync_dangerously_connect_to_http_endpoint_for_testing : true
226+ } ) ;
227+ pubsub . addPluggable ( mqttOverWSProvider ) ;
228+
229+ await testPubSubAsync ( pubsub , 'topicA' , 'my message MqttOverWSProvider' , {
230+ provider : 'MqttOverWSProvider' ,
231+ } ) ;
232+
233+ expect ( mqttOverWSProvider . isSSLEnabled ) . toBe ( false ) ;
234+ expect ( mockConnect ) . toBeCalledWith ( {
235+ useSSL : false ,
236+ mqttVersion : 3 ,
237+ onSuccess : expect . any ( Function ) ,
238+ onFailure : expect . any ( Function )
239+ } ) ;
240+
241+ } ) ;
242+ } ) ;
243+
216244 describe ( 'multiple providers' , ( ) => {
217245 test ( 'subscribe and publish to specific provider' , async ( ) => {
218246 const pubsub = new PubSub ( ) ;
0 commit comments