@@ -672,4 +672,107 @@ describe('hooks/useNotifications.ts', () => {
672
672
} ) ;
673
673
} ) ;
674
674
} ) ;
675
+
676
+ describe ( 'markRepoNotificationsDone' , ( ) => {
677
+ const repoSlug = 'manosim/gitify' ;
678
+ const id = 'notification-123' ;
679
+
680
+ describe ( 'github.com' , ( ) => {
681
+ const accounts = { ...mockAccounts , enterpriseAccounts : [ ] } ;
682
+ const hostname = 'github.com' ;
683
+
684
+ it ( "should mark a repository's notifications as done with success - github.com" , async ( ) => {
685
+ nock ( 'https://api.github.com/' )
686
+ . delete ( `/notifications/threads/${ id } ` )
687
+ . reply ( 200 ) ;
688
+
689
+ const { result } = renderHook ( ( ) => useNotifications ( false ) ) ;
690
+
691
+ act ( ( ) => {
692
+ result . current . markRepoNotificationsDone (
693
+ accounts ,
694
+ repoSlug ,
695
+ hostname ,
696
+ ) ;
697
+ } ) ;
698
+
699
+ await waitFor ( ( ) => {
700
+ expect ( result . current . isFetching ) . toBe ( false ) ;
701
+ } ) ;
702
+
703
+ expect ( result . current . notifications . length ) . toBe ( 0 ) ;
704
+ } ) ;
705
+
706
+ it ( "should mark a repository's notifications as done with failure - github.com" , async ( ) => {
707
+ nock ( 'https://api.github.com/' )
708
+ . delete ( `/notifications/threads/${ id } ` )
709
+ . reply ( 400 ) ;
710
+
711
+ const { result } = renderHook ( ( ) => useNotifications ( false ) ) ;
712
+
713
+ act ( ( ) => {
714
+ result . current . markRepoNotificationsDone (
715
+ accounts ,
716
+ repoSlug ,
717
+ hostname ,
718
+ ) ;
719
+ } ) ;
720
+
721
+ await waitFor ( ( ) => {
722
+ expect ( result . current . isFetching ) . toBe ( false ) ;
723
+ } ) ;
724
+
725
+ expect ( result . current . notifications . length ) . toBe ( 0 ) ;
726
+ } ) ;
727
+ } ) ;
728
+
729
+ describe ( 'enterprise' , ( ) => {
730
+ const accounts = { ...mockAccounts , token : null } ;
731
+ const hostname = 'github.gitify.io' ;
732
+
733
+ it ( "should mark a repository's notifications as done with success - enterprise" , async ( ) => {
734
+ nock ( 'https://api.github.com/' )
735
+ . delete ( `/notifications/threads/${ id } ` )
736
+ . reply ( 200 ) ;
737
+
738
+ const { result } = renderHook ( ( ) => useNotifications ( false ) ) ;
739
+
740
+ act ( ( ) => {
741
+ result . current . markRepoNotificationsDone (
742
+ accounts ,
743
+ repoSlug ,
744
+ hostname ,
745
+ ) ;
746
+ } ) ;
747
+
748
+ await waitFor ( ( ) => {
749
+ expect ( result . current . isFetching ) . toBe ( false ) ;
750
+ } ) ;
751
+
752
+ expect ( result . current . notifications . length ) . toBe ( 0 ) ;
753
+ } ) ;
754
+
755
+ it ( "should mark a repository's notifications as done with failure - enterprise" , async ( ) => {
756
+ nock ( 'https://api.github.com/' )
757
+ . delete ( `/notifications/threads/${ id } ` )
758
+ . reply ( 400 ) ;
759
+
760
+ const { result } = renderHook ( ( ) => useNotifications ( false ) ) ;
761
+
762
+ act ( ( ) => {
763
+ result . current . markRepoNotificationsDone (
764
+ accounts ,
765
+ repoSlug ,
766
+ hostname ,
767
+ ) ;
768
+ } ) ;
769
+
770
+ await waitFor ( ( ) => {
771
+ expect ( result . current . isFetching ) . toBe ( false ) ;
772
+ } ) ;
773
+
774
+ expect ( result . current . notifications . length ) . toBe ( 0 ) ;
775
+ } ) ;
776
+ } ) ;
777
+ } ) ;
675
778
} ) ;
0 commit comments