@@ -21,13 +21,16 @@ let randomProjectRef = () => crypto.randomUUID()
21
21
let mockServer : Server
22
22
let projectRef : string
23
23
let url : string
24
-
24
+ const version = crypto . randomUUID ( )
25
25
beforeEach ( ( ) => {
26
26
projectRef = randomProjectRef ( )
27
27
url = `wss://${ projectRef } /socket`
28
28
mockServer = new Server ( url )
29
29
socket = new RealtimeClient ( url , {
30
30
transport : MockWebSocket ,
31
+ headers : {
32
+ 'X-Client-Info' : version ,
33
+ } ,
31
34
} )
32
35
} )
33
36
@@ -399,27 +402,14 @@ describe('setAuth', () => {
399
402
await socket . setAuth ( token )
400
403
401
404
assert . strictEqual ( socket . accessTokenValue , token )
405
+
402
406
assert . ok ( pushStub1 . calledWith ( 'access_token' , { access_token : token } ) )
403
407
assert . ok ( ! pushStub2 . calledWith ( 'access_token' , { access_token : token } ) )
404
408
assert . ok ( pushStub3 . calledWith ( 'access_token' , { access_token : token } ) )
405
- assert . ok (
406
- payloadStub1 . calledWith ( {
407
- access_token : token ,
408
- version : '0.0.0-automated' ,
409
- } )
410
- )
411
- assert . ok (
412
- payloadStub2 . calledWith ( {
413
- access_token : token ,
414
- version : '0.0.0-automated' ,
415
- } )
416
- )
417
- assert . ok (
418
- payloadStub3 . calledWith ( {
419
- access_token : token ,
420
- version : '0.0.0-automated' ,
421
- } )
422
- )
409
+
410
+ assert . ok ( payloadStub1 . calledWith ( { access_token : token , version } ) )
411
+ assert . ok ( payloadStub2 . calledWith ( { access_token : token , version } ) )
412
+ assert . ok ( payloadStub3 . calledWith ( { access_token : token , version } ) )
423
413
} )
424
414
425
415
test ( "does not send message if token hasn't changed" , async ( ) => {
@@ -429,7 +419,7 @@ describe('setAuth', () => {
429
419
430
420
channel1 . joinedOnce = true
431
421
432
- const pushStub1 = sinon . stub ( channel1 , '_push' )
422
+ sinon . stub ( channel1 , '_push' )
433
423
434
424
const payloadStub1 = sinon . stub ( channel1 , 'updateJoinPayload' )
435
425
const token = generateJWT ( '1h' )
@@ -438,13 +428,7 @@ describe('setAuth', () => {
438
428
await socket . setAuth ( token )
439
429
440
430
assert . strictEqual ( socket . accessTokenValue , token )
441
-
442
- assert . ok (
443
- payloadStub1 . calledOnceWith ( {
444
- access_token : token ,
445
- version : '0.0.0-automated' ,
446
- } )
447
- )
431
+ assert . ok ( payloadStub1 . calledOnceWith ( { access_token : token , version } ) )
448
432
} )
449
433
450
434
test ( "sets access token, updates channels' join payload, and pushes token to channels if is not a jwt" , async ( ) => {
@@ -477,30 +461,16 @@ describe('setAuth', () => {
477
461
! pushStub2 . calledWith ( 'access_token' , { access_token : new_token } )
478
462
)
479
463
assert . ok ( pushStub3 . calledWith ( 'access_token' , { access_token : new_token } ) )
480
- assert . ok (
481
- payloadStub1 . calledWith ( {
482
- access_token : new_token ,
483
- version : '0.0.0-automated' ,
484
- } )
485
- )
486
- assert . ok (
487
- payloadStub2 . calledWith ( {
488
- access_token : new_token ,
489
- version : '0.0.0-automated' ,
490
- } )
491
- )
492
- assert . ok (
493
- payloadStub3 . calledWith ( {
494
- access_token : new_token ,
495
- version : '0.0.0-automated' ,
496
- } )
497
- )
464
+ assert . ok ( payloadStub1 . calledWith ( { access_token : new_token , version } ) )
465
+ assert . ok ( payloadStub2 . calledWith ( { access_token : new_token , version } ) )
466
+ assert . ok ( payloadStub3 . calledWith ( { access_token : new_token , version } ) )
498
467
} )
499
468
500
469
test ( "sets access token using callback, updates channels' join payload, and pushes token to channels" , async ( ) => {
501
470
let new_token = generateJWT ( '1h' )
502
471
let new_socket = new RealtimeClient ( url , {
503
472
transport : MockWebSocket ,
473
+ headers : { 'X-Client-Info' : version } ,
504
474
accessToken : ( ) => Promise . resolve ( token ) ,
505
475
} )
506
476
@@ -532,24 +502,9 @@ describe('setAuth', () => {
532
502
! pushStub2 . calledWith ( 'access_token' , { access_token : new_token } )
533
503
)
534
504
assert . ok ( pushStub3 . calledWith ( 'access_token' , { access_token : new_token } ) )
535
- assert . ok (
536
- payloadStub1 . calledWith ( {
537
- access_token : new_token ,
538
- version : '0.0.0-automated' ,
539
- } )
540
- )
541
- assert . ok (
542
- payloadStub2 . calledWith ( {
543
- access_token : new_token ,
544
- version : '0.0.0-automated' ,
545
- } )
546
- )
547
- assert . ok (
548
- payloadStub3 . calledWith ( {
549
- access_token : new_token ,
550
- version : '0.0.0-automated' ,
551
- } )
552
- )
505
+ assert . ok ( payloadStub1 . calledWith ( { access_token : new_token , version } ) )
506
+ assert . ok ( payloadStub2 . calledWith ( { access_token : new_token , version } ) )
507
+ assert . ok ( payloadStub3 . calledWith ( { access_token : new_token , version } ) )
553
508
} )
554
509
555
510
test ( "overrides access token, updates channels' join payload, and pushes token to channels" , ( ) => {
@@ -581,24 +536,9 @@ describe('setAuth', () => {
581
536
! pushStub2 . calledWith ( 'access_token' , { access_token : new_token } )
582
537
)
583
538
assert . ok ( pushStub3 . calledWith ( 'access_token' , { access_token : new_token } ) )
584
- assert . ok (
585
- payloadStub1 . calledWith ( {
586
- access_token : new_token ,
587
- version : '0.0.0-automated' ,
588
- } )
589
- )
590
- assert . ok (
591
- payloadStub2 . calledWith ( {
592
- access_token : new_token ,
593
- version : '0.0.0-automated' ,
594
- } )
595
- )
596
- assert . ok (
597
- payloadStub3 . calledWith ( {
598
- access_token : new_token ,
599
- version : '0.0.0-automated' ,
600
- } )
601
- )
539
+ assert . ok ( payloadStub1 . calledWith ( { access_token : new_token , version } ) )
540
+ assert . ok ( payloadStub2 . calledWith ( { access_token : new_token , version } ) )
541
+ assert . ok ( payloadStub3 . calledWith ( { access_token : new_token , version } ) )
602
542
} )
603
543
} )
604
544
0 commit comments