@@ -636,4 +636,107 @@ describe('hooks/useNotifications.ts', () => {
636
636
} ) ;
637
637
} ) ;
638
638
} ) ;
639
+
640
+ describe ( 'markRepoNotificationsDone' , ( ) => {
641
+ const repoSlug = 'manosim/gitify' ;
642
+ const id = 'notification-123' ;
643
+
644
+ describe ( 'github.com' , ( ) => {
645
+ const accounts = { ...mockAccounts , enterpriseAccounts : [ ] } ;
646
+ const hostname = 'github.com' ;
647
+
648
+ it ( "should mark a repository's notifications as done with success - github.com" , async ( ) => {
649
+ nock ( 'https://api.github.com/' )
650
+ . delete ( `/notifications/threads/${ id } ` )
651
+ . reply ( 200 ) ;
652
+
653
+ const { result } = renderHook ( ( ) => useNotifications ( false ) ) ;
654
+
655
+ act ( ( ) => {
656
+ result . current . markRepoNotificationsDone (
657
+ accounts ,
658
+ repoSlug ,
659
+ hostname ,
660
+ ) ;
661
+ } ) ;
662
+
663
+ await waitFor ( ( ) => {
664
+ expect ( result . current . isFetching ) . toBe ( false ) ;
665
+ } ) ;
666
+
667
+ expect ( result . current . notifications . length ) . toBe ( 0 ) ;
668
+ } ) ;
669
+
670
+ it ( "should mark a repository's notifications as done with failure - github.com" , async ( ) => {
671
+ nock ( 'https://api.github.com/' )
672
+ . delete ( `/notifications/threads/${ id } ` )
673
+ . reply ( 400 ) ;
674
+
675
+ const { result } = renderHook ( ( ) => useNotifications ( false ) ) ;
676
+
677
+ act ( ( ) => {
678
+ result . current . markRepoNotificationsDone (
679
+ accounts ,
680
+ repoSlug ,
681
+ hostname ,
682
+ ) ;
683
+ } ) ;
684
+
685
+ await waitFor ( ( ) => {
686
+ expect ( result . current . isFetching ) . toBe ( false ) ;
687
+ } ) ;
688
+
689
+ expect ( result . current . notifications . length ) . toBe ( 0 ) ;
690
+ } ) ;
691
+ } ) ;
692
+
693
+ describe ( 'enterprise' , ( ) => {
694
+ const accounts = { ...mockAccounts , token : null } ;
695
+ const hostname = 'github.gitify.io' ;
696
+
697
+ it ( "should mark a repository's notifications as done with success - enterprise" , async ( ) => {
698
+ nock ( 'https://api.github.com/' )
699
+ . delete ( `/notifications/threads/${ id } ` )
700
+ . reply ( 200 ) ;
701
+
702
+ const { result } = renderHook ( ( ) => useNotifications ( false ) ) ;
703
+
704
+ act ( ( ) => {
705
+ result . current . markRepoNotificationsDone (
706
+ accounts ,
707
+ repoSlug ,
708
+ hostname ,
709
+ ) ;
710
+ } ) ;
711
+
712
+ await waitFor ( ( ) => {
713
+ expect ( result . current . isFetching ) . toBe ( false ) ;
714
+ } ) ;
715
+
716
+ expect ( result . current . notifications . length ) . toBe ( 0 ) ;
717
+ } ) ;
718
+
719
+ it ( "should mark a repository's notifications as done with failure - enterprise" , async ( ) => {
720
+ nock ( 'https://api.github.com/' )
721
+ . delete ( `/notifications/threads/${ id } ` )
722
+ . reply ( 400 ) ;
723
+
724
+ const { result } = renderHook ( ( ) => useNotifications ( false ) ) ;
725
+
726
+ act ( ( ) => {
727
+ result . current . markRepoNotificationsDone (
728
+ accounts ,
729
+ repoSlug ,
730
+ hostname ,
731
+ ) ;
732
+ } ) ;
733
+
734
+ await waitFor ( ( ) => {
735
+ expect ( result . current . isFetching ) . toBe ( false ) ;
736
+ } ) ;
737
+
738
+ expect ( result . current . notifications . length ) . toBe ( 0 ) ;
739
+ } ) ;
740
+ } ) ;
741
+ } ) ;
639
742
} ) ;
0 commit comments