@@ -188,6 +188,37 @@ describe('QSSService', () => {
188188 return ( await localDbService . getCurrentCommunity ( ) ) !
189189 }
190190
191+ const mockSuccessfulSignIn = ( ) : void => {
192+ mockedGetAuthConnection = jest
193+ . spyOn ( qssAuthConnManager , 'getConnection' )
194+ . mockImplementation ( ( _teamId : string ) : QSSAuthConnection => {
195+ return {
196+ active : true ,
197+ joinStatus : JoinStatus . JOINED ,
198+ connStatus : QSSAuthConnStatus . CONNECTED ,
199+ on : ( ...args : any [ ] ) => { } ,
200+ removeAllListeners : ( ...args : any [ ] ) => { } ,
201+ } as any
202+ } )
203+
204+ mockedSendMessage = jest
205+ . spyOn ( qssClient , 'sendMessage' )
206+ . mockImplementation (
207+ async < T > ( event : WebsocketEvents , payload : unknown , withAck = false ) : Promise < T | undefined > => {
208+ logger . debug ( 'Sending event to QSS' , event , payload , withAck )
209+ switch ( event ) {
210+ case WebsocketEvents . SIGN_IN_COMMUNITY :
211+ return {
212+ ts : DateTime . utc ( ) . toMillis ( ) ,
213+ status : CommunityOperationStatus . SUCCESS ,
214+ } as T
215+ default :
216+ return undefined
217+ }
218+ }
219+ )
220+ }
221+
191222 describe ( 'connect' , ( ) => {
192223 it ( 'connects to QSS when enabled and an endpoint string is provided' , async ( ) => {
193224 await initCommunity ( )
@@ -197,85 +228,6 @@ describe('QSSService', () => {
197228 expect ( qssService . canConnect ) . toBeTruthy ( )
198229 } )
199230
200- it ( 'emits the NSE QSS URL from the endpoint passed to connect on iOS' , async ( ) => {
201- const originalPlatform = process . platform
202- Object . defineProperty ( process , 'platform' , { value : 'ios' } )
203-
204- try {
205- await localDbService . setCommunity ( {
206- ...community ,
207- teamId : 'team-id' ,
208- qssEnabled : true ,
209- } )
210- await localDbService . setCurrentCommunityId ( community . id )
211-
212- mockedAllowed = jest . spyOn ( qssService , 'qssAllowed' , 'get' ) . mockReturnValue ( true )
213- const emitSpy = jest . spyOn ( qssService [ 'socketService' ] . serverIoProvider . io , 'emit' )
214-
215- await qssService . connect ( 'wss://community.example/ws' )
216-
217- expect ( emitSpy ) . toHaveBeenCalledWith ( SocketEvents . NSE_QSS_URL_UPDATED , {
218- teamId : 'team-id' ,
219- qssUrl : 'https://community.example/ws' ,
220- } )
221- } finally {
222- Object . defineProperty ( process , 'platform' , { value : originalPlatform } )
223- }
224- } )
225-
226- it ( 'emits the NSE QSS URL from the stored endpoint when connect is called without one on iOS' , async ( ) => {
227- const originalPlatform = process . platform
228- Object . defineProperty ( process , 'platform' , { value : 'ios' } )
229-
230- try {
231- await localDbService . setCommunity ( {
232- ...community ,
233- teamId : 'team-id' ,
234- qssEnabled : true ,
235- } )
236- await localDbService . setCurrentCommunityId ( community . id )
237-
238- qssService . _qssEndpoint = 'ws://configured.example/ws'
239- mockedAllowed = jest . spyOn ( qssService , 'qssAllowed' , 'get' ) . mockReturnValue ( true )
240- const emitSpy = jest . spyOn ( qssService [ 'socketService' ] . serverIoProvider . io , 'emit' )
241-
242- await qssService . connect ( undefined )
243-
244- expect ( emitSpy ) . toHaveBeenCalledWith ( SocketEvents . NSE_QSS_URL_UPDATED , {
245- teamId : 'team-id' ,
246- qssUrl : 'http://configured.example/ws' ,
247- } )
248- } finally {
249- Object . defineProperty ( process , 'platform' , { value : originalPlatform } )
250- }
251- } )
252-
253- it ( 'skips NSE QSS URL emission when connect uses a non-ws endpoint on iOS' , async ( ) => {
254- const originalPlatform = process . platform
255- Object . defineProperty ( process , 'platform' , { value : 'ios' } )
256-
257- try {
258- await localDbService . setCommunity ( {
259- ...community ,
260- teamId : 'team-id' ,
261- qssEnabled : true ,
262- } )
263- await localDbService . setCurrentCommunityId ( community . id )
264-
265- mockedAllowed = jest . spyOn ( qssService , 'qssAllowed' , 'get' ) . mockReturnValue ( true )
266- const emitSpy = jest . spyOn ( qssService [ 'socketService' ] . serverIoProvider . io , 'emit' )
267-
268- await qssService . connect ( 'https://community.example/api' )
269-
270- expect ( emitSpy ) . not . toHaveBeenCalledWith (
271- SocketEvents . NSE_QSS_URL_UPDATED ,
272- expect . objectContaining ( { teamId : 'team-id' } )
273- )
274- } finally {
275- Object . defineProperty ( process , 'platform' , { value : originalPlatform } )
276- }
277- } )
278-
279231 it ( `doesn't connect to QSS when not enabled and an endpoint string is provided` , async ( ) => {
280232 await initCommunity ( )
281233 mockedAllowed = jest . spyOn ( qssService , 'qssAllowed' , 'get' ) . mockReturnValue ( false )
@@ -570,33 +522,7 @@ describe('QSSService', () => {
570522 await initCommunity ( )
571523 const initStatusOrig = await qssService . getQssInitStatus ( )
572524 expect ( initStatusOrig . qssSetup ) . toBeFalsy ( )
573- mockedGetAuthConnection = jest
574- . spyOn ( qssAuthConnManager , 'getConnection' )
575- . mockImplementation ( ( teamId : string ) : QSSAuthConnection => {
576- return {
577- active : true ,
578- joinStatus : JoinStatus . JOINED ,
579- connStatus : QSSAuthConnStatus . CONNECTED ,
580- on : ( ...args : any [ ] ) => { } ,
581- } as any
582- } )
583-
584- mockedSendMessage = jest
585- . spyOn ( qssClient , 'sendMessage' )
586- . mockImplementation (
587- async < T > ( event : WebsocketEvents , payload : unknown , withAck = false ) : Promise < T | undefined > => {
588- logger . debug ( 'Sending event to QSS' , event , payload , withAck )
589- switch ( event ) {
590- case WebsocketEvents . SIGN_IN_COMMUNITY :
591- return {
592- ts : DateTime . utc ( ) . toMillis ( ) ,
593- status : CommunityOperationStatus . SUCCESS ,
594- } as T
595- default :
596- return undefined
597- }
598- }
599- )
525+ mockSuccessfulSignIn ( )
600526 mockedAllowed = jest . spyOn ( qssService , 'qssAllowed' , 'get' ) . mockReturnValue ( true )
601527 await qssService . connect ( 'ws://localhost:3000' )
602528 expect ( qssService . connected ) . toBeTruthy ( )
@@ -625,6 +551,94 @@ describe('QSSService', () => {
625551 expect ( initStatus . qssSetup ) . toBeTruthy ( )
626552 } )
627553
554+ it ( 'emits the NSE QSS URL from the endpoint passed to connect on iOS after successful sign in' , async ( ) => {
555+ const originalPlatform = process . platform
556+ Object . defineProperty ( process , 'platform' , { value : 'ios' } )
557+
558+ try {
559+ await localDbService . setCommunity ( {
560+ ...community ,
561+ teamId : 'team-id' ,
562+ qssEnabled : true ,
563+ } )
564+ await localDbService . setCurrentCommunityId ( community . id )
565+ await localDbService . setIdentity ( userIdentity )
566+
567+ mockSuccessfulSignIn ( )
568+ mockedAllowed = jest . spyOn ( qssService , 'qssAllowed' , 'get' ) . mockReturnValue ( true )
569+ const emitSpy = jest . spyOn ( qssService [ 'socketService' ] . serverIoProvider . io , 'emit' )
570+
571+ await qssService . connect ( 'wss://community.example/ws' )
572+ await qssService . signInToCommunity ( sigchainService . activeChain . team ! . id , sigchainService . activeChain )
573+
574+ expect ( emitSpy ) . toHaveBeenCalledWith ( SocketEvents . NSE_QSS_URL_UPDATED , {
575+ teamId : 'team-id' ,
576+ qssUrl : 'https://community.example/ws' ,
577+ } )
578+ } finally {
579+ Object . defineProperty ( process , 'platform' , { value : originalPlatform } )
580+ }
581+ } )
582+
583+ it ( 'emits the NSE QSS URL from the stored endpoint when connect is called without one on iOS after successful sign in' , async ( ) => {
584+ const originalPlatform = process . platform
585+ Object . defineProperty ( process , 'platform' , { value : 'ios' } )
586+
587+ try {
588+ await localDbService . setCommunity ( {
589+ ...community ,
590+ teamId : 'team-id' ,
591+ qssEnabled : true ,
592+ } )
593+ await localDbService . setCurrentCommunityId ( community . id )
594+ await localDbService . setIdentity ( userIdentity )
595+
596+ qssService . _qssEndpoint = 'ws://configured.example/ws'
597+ mockSuccessfulSignIn ( )
598+ mockedAllowed = jest . spyOn ( qssService , 'qssAllowed' , 'get' ) . mockReturnValue ( true )
599+ const emitSpy = jest . spyOn ( qssService [ 'socketService' ] . serverIoProvider . io , 'emit' )
600+
601+ await qssService . connect ( undefined )
602+ await qssService . signInToCommunity ( sigchainService . activeChain . team ! . id , sigchainService . activeChain )
603+
604+ expect ( emitSpy ) . toHaveBeenCalledWith ( SocketEvents . NSE_QSS_URL_UPDATED , {
605+ teamId : 'team-id' ,
606+ qssUrl : 'http://configured.example/ws' ,
607+ } )
608+ } finally {
609+ Object . defineProperty ( process , 'platform' , { value : originalPlatform } )
610+ }
611+ } )
612+
613+ it ( 'skips NSE QSS URL emission when sign in uses a non-ws endpoint on iOS' , async ( ) => {
614+ const originalPlatform = process . platform
615+ Object . defineProperty ( process , 'platform' , { value : 'ios' } )
616+
617+ try {
618+ await localDbService . setCommunity ( {
619+ ...community ,
620+ teamId : 'team-id' ,
621+ qssEnabled : true ,
622+ } )
623+ await localDbService . setCurrentCommunityId ( community . id )
624+ await localDbService . setIdentity ( userIdentity )
625+
626+ mockSuccessfulSignIn ( )
627+ mockedAllowed = jest . spyOn ( qssService , 'qssAllowed' , 'get' ) . mockReturnValue ( true )
628+ const emitSpy = jest . spyOn ( qssService [ 'socketService' ] . serverIoProvider . io , 'emit' )
629+
630+ await qssService . connect ( 'https://community.example/api' )
631+ await qssService . signInToCommunity ( sigchainService . activeChain . team ! . id , sigchainService . activeChain )
632+
633+ expect ( emitSpy ) . not . toHaveBeenCalledWith (
634+ SocketEvents . NSE_QSS_URL_UPDATED ,
635+ expect . objectContaining ( { teamId : 'team-id' } )
636+ )
637+ } finally {
638+ Object . defineProperty ( process , 'platform' , { value : originalPlatform } )
639+ }
640+ } )
641+
628642 it ( `doesn't sign in to community when QSS is not connected` , async ( ) => {
629643 await initCommunity ( )
630644 const initStatusOrig = await qssService . getQssInitStatus ( )
0 commit comments