1
- import { afterEach } from 'vitest' ;
1
+ import { afterEach , expect } from 'vitest' ;
2
2
import {
3
3
createRetransmissionHandler ,
4
4
fetchSubscriptionErrorHandler ,
@@ -18,7 +18,6 @@ import {
18
18
dummySubscriptionHealth ,
19
19
dummySubscriptionMetrics ,
20
20
} from '@/dummy/subscription' ;
21
- import { expect } from 'vitest' ;
22
21
import {
23
22
expectNotificationDispatched ,
24
23
notificationStoreSpy ,
@@ -391,6 +390,39 @@ describe('useSubscription', () => {
391
390
} ) ;
392
391
} ) ;
393
392
393
+ [ 200 , 500 ] . forEach ( ( statusCode ) => {
394
+ it ( `should correctly manage the state of retransmission with status code ${ statusCode } ` , async ( ) => {
395
+ // given
396
+ server . use (
397
+ createRetransmissionHandler ( {
398
+ topicName : dummySubscription . topicName ,
399
+ subscriptionName : dummySubscription . name ,
400
+ statusCode,
401
+ delayMs : 100 ,
402
+ } ) ,
403
+ ) ;
404
+ server . listen ( ) ;
405
+
406
+ const { retransmitMessages, retransmitting } = useSubscription (
407
+ dummySubscription . topicName ,
408
+ dummySubscription . name ,
409
+ ) ;
410
+
411
+ expect ( retransmitting . value ) . toBeFalsy ( ) ;
412
+
413
+ // when
414
+ retransmitMessages ( new Date ( ) . toISOString ( ) ) ;
415
+
416
+ // then
417
+ await waitFor ( ( ) => {
418
+ expect ( retransmitting . value ) . toBeTruthy ( ) ;
419
+ } ) ;
420
+ await waitFor ( ( ) => {
421
+ expect ( retransmitting . value ) . toBeFalsy ( ) ;
422
+ } ) ;
423
+ } ) ;
424
+ } ) ;
425
+
394
426
it ( 'should show message that skipping all messages was successful' , async ( ) => {
395
427
// given
396
428
server . use (
@@ -448,6 +480,39 @@ describe('useSubscription', () => {
448
480
} ) ;
449
481
} ) ;
450
482
} ) ;
483
+
484
+ [ 200 , 500 ] . forEach ( ( statusCode ) => {
485
+ it ( `should correctly manage the state of skipping all messages with status code ${ statusCode } ` , async ( ) => {
486
+ // given
487
+ server . use (
488
+ createRetransmissionHandler ( {
489
+ topicName : dummySubscription . topicName ,
490
+ subscriptionName : dummySubscription . name ,
491
+ statusCode,
492
+ delayMs : 100 ,
493
+ } ) ,
494
+ ) ;
495
+ server . listen ( ) ;
496
+
497
+ const { skipAllMessages, skippingAllMessages } = useSubscription (
498
+ dummySubscription . topicName ,
499
+ dummySubscription . name ,
500
+ ) ;
501
+
502
+ expect ( skippingAllMessages . value ) . toBeFalsy ( ) ;
503
+
504
+ // when
505
+ skipAllMessages ( ) ;
506
+
507
+ // then
508
+ await waitFor ( ( ) => {
509
+ expect ( skippingAllMessages . value ) . toBeTruthy ( ) ;
510
+ } ) ;
511
+ await waitFor ( ( ) => {
512
+ expect ( skippingAllMessages . value ) . toBeFalsy ( ) ;
513
+ } ) ;
514
+ } ) ;
515
+ } ) ;
451
516
} ) ;
452
517
453
518
function expectErrors (
0 commit comments