@@ -20,6 +20,7 @@ describe("CloudSettingsService", () => {
20
20
getSessionToken : ReturnType < typeof vi . fn >
21
21
hasActiveSession : ReturnType < typeof vi . fn >
22
22
on : ReturnType < typeof vi . fn >
23
+ getStoredOrganizationId : ReturnType < typeof vi . fn >
23
24
}
24
25
let mockRefreshTimer : {
25
26
start : ReturnType < typeof vi . fn >
@@ -63,6 +64,7 @@ describe("CloudSettingsService", () => {
63
64
getSessionToken : vi . fn ( ) ,
64
65
hasActiveSession : vi . fn ( ) . mockReturnValue ( false ) ,
65
66
on : vi . fn ( ) ,
67
+ getStoredOrganizationId : vi . fn ( ) . mockReturnValue ( null ) ,
66
68
}
67
69
68
70
mockRefreshTimer = {
@@ -532,4 +534,191 @@ describe("CloudSettingsService", () => {
532
534
expect ( mockContext . globalState . update ) . toHaveBeenCalledWith ( "user-settings" , undefined )
533
535
} )
534
536
} )
537
+
538
+ describe ( "isTaskSyncEnabled" , ( ) => {
539
+ beforeEach ( async ( ) => {
540
+ await cloudSettingsService . initialize ( )
541
+ } )
542
+
543
+ it ( "should return true when org recordTaskMessages is true" , ( ) => {
544
+ // Set up mock settings with org recordTaskMessages = true
545
+ const mockSettings = {
546
+ version : 1 ,
547
+ cloudSettings : {
548
+ recordTaskMessages : true ,
549
+ } ,
550
+ defaultSettings : { } ,
551
+ allowList : { allowAll : true , providers : { } } ,
552
+ }
553
+
554
+ // Mock that user has organization ID (indicating org settings should be used)
555
+ mockAuthService . getStoredOrganizationId . mockReturnValue ( "org-123" )
556
+
557
+ // Use reflection to set private settings
558
+ ; ( cloudSettingsService as unknown as { settings : typeof mockSettings } ) . settings = mockSettings
559
+
560
+ expect ( cloudSettingsService . isTaskSyncEnabled ( ) ) . toBe ( true )
561
+ } )
562
+
563
+ it ( "should return false when org recordTaskMessages is false" , ( ) => {
564
+ // Set up mock settings with org recordTaskMessages = false
565
+ const mockSettings = {
566
+ version : 1 ,
567
+ cloudSettings : {
568
+ recordTaskMessages : false ,
569
+ } ,
570
+ defaultSettings : { } ,
571
+ allowList : { allowAll : true , providers : { } } ,
572
+ }
573
+
574
+ // Mock that user has organization ID (indicating org settings should be used)
575
+ mockAuthService . getStoredOrganizationId . mockReturnValue ( "org-123" )
576
+
577
+ // Use reflection to set private settings
578
+ ; ( cloudSettingsService as unknown as { settings : typeof mockSettings } ) . settings = mockSettings
579
+
580
+ expect ( cloudSettingsService . isTaskSyncEnabled ( ) ) . toBe ( false )
581
+ } )
582
+
583
+ it ( "should fall back to user taskSyncEnabled when org recordTaskMessages is undefined" , ( ) => {
584
+ // Set up mock settings with org recordTaskMessages undefined
585
+ const mockSettings = {
586
+ version : 1 ,
587
+ cloudSettings : { } ,
588
+ defaultSettings : { } ,
589
+ allowList : { allowAll : true , providers : { } } ,
590
+ }
591
+
592
+ const mockUserSettings = {
593
+ version : 1 ,
594
+ features : { } ,
595
+ settings : {
596
+ taskSyncEnabled : true ,
597
+ } ,
598
+ }
599
+
600
+ // Mock that user has no organization ID (indicating user settings should be used)
601
+ mockAuthService . getStoredOrganizationId . mockReturnValue ( null )
602
+
603
+ // Use reflection to set private settings
604
+ ; ( cloudSettingsService as unknown as { settings : typeof mockSettings } ) . settings = mockSettings
605
+ ; ( cloudSettingsService as unknown as { userSettings : typeof mockUserSettings } ) . userSettings =
606
+ mockUserSettings
607
+
608
+ expect ( cloudSettingsService . isTaskSyncEnabled ( ) ) . toBe ( true )
609
+ } )
610
+
611
+ it ( "should return false when user taskSyncEnabled is false" , ( ) => {
612
+ // Set up mock settings with org recordTaskMessages undefined
613
+ const mockSettings = {
614
+ version : 1 ,
615
+ cloudSettings : { } ,
616
+ defaultSettings : { } ,
617
+ allowList : { allowAll : true , providers : { } } ,
618
+ }
619
+
620
+ const mockUserSettings = {
621
+ version : 1 ,
622
+ features : { } ,
623
+ settings : {
624
+ taskSyncEnabled : false ,
625
+ } ,
626
+ }
627
+
628
+ // Mock that user has no organization ID (indicating user settings should be used)
629
+ mockAuthService . getStoredOrganizationId . mockReturnValue ( null )
630
+
631
+ // Use reflection to set private settings
632
+ ; ( cloudSettingsService as unknown as { settings : typeof mockSettings } ) . settings = mockSettings
633
+ ; ( cloudSettingsService as unknown as { userSettings : typeof mockUserSettings } ) . userSettings =
634
+ mockUserSettings
635
+
636
+ expect ( cloudSettingsService . isTaskSyncEnabled ( ) ) . toBe ( false )
637
+ } )
638
+
639
+ it ( "should return true when user taskSyncEnabled is undefined (default)" , ( ) => {
640
+ // Set up mock settings with org recordTaskMessages undefined
641
+ const mockSettings = {
642
+ version : 1 ,
643
+ cloudSettings : { } ,
644
+ defaultSettings : { } ,
645
+ allowList : { allowAll : true , providers : { } } ,
646
+ }
647
+
648
+ const mockUserSettings = {
649
+ version : 1 ,
650
+ features : { } ,
651
+ settings : { } ,
652
+ }
653
+
654
+ // Mock that user has no organization ID (indicating user settings should be used)
655
+ mockAuthService . getStoredOrganizationId . mockReturnValue ( null )
656
+
657
+ // Use reflection to set private settings
658
+ ; ( cloudSettingsService as unknown as { settings : typeof mockSettings } ) . settings = mockSettings
659
+ ; ( cloudSettingsService as unknown as { userSettings : typeof mockUserSettings } ) . userSettings =
660
+ mockUserSettings
661
+
662
+ expect ( cloudSettingsService . isTaskSyncEnabled ( ) ) . toBe ( true )
663
+ } )
664
+
665
+ it ( "should return false when no settings are available" , ( ) => {
666
+ // Mock that user has no organization ID
667
+ mockAuthService . getStoredOrganizationId . mockReturnValue ( null )
668
+
669
+ // Clear both settings
670
+ ; ( cloudSettingsService as unknown as { settings : undefined } ) . settings = undefined
671
+ ; ( cloudSettingsService as unknown as { userSettings : undefined } ) . userSettings = undefined
672
+
673
+ expect ( cloudSettingsService . isTaskSyncEnabled ( ) ) . toBe ( false )
674
+ } )
675
+
676
+ it ( "should return false when only org settings are available but cloudSettings is undefined" , ( ) => {
677
+ const mockSettings = {
678
+ version : 1 ,
679
+ defaultSettings : { } ,
680
+ allowList : { allowAll : true , providers : { } } ,
681
+ }
682
+
683
+ // Mock that user has organization ID (indicating org settings should be used)
684
+ mockAuthService . getStoredOrganizationId . mockReturnValue ( "org-123" )
685
+
686
+ // Use reflection to set private settings
687
+ ; ( cloudSettingsService as unknown as { settings : typeof mockSettings } ) . settings = mockSettings
688
+ ; ( cloudSettingsService as unknown as { userSettings : undefined } ) . userSettings = undefined
689
+
690
+ expect ( cloudSettingsService . isTaskSyncEnabled ( ) ) . toBe ( false )
691
+ } )
692
+
693
+ it ( "should prioritize org settings over user settings" , ( ) => {
694
+ // Set up conflicting settings: org = false, user = true
695
+ const mockSettings = {
696
+ version : 1 ,
697
+ cloudSettings : {
698
+ recordTaskMessages : false ,
699
+ } ,
700
+ defaultSettings : { } ,
701
+ allowList : { allowAll : true , providers : { } } ,
702
+ }
703
+
704
+ const mockUserSettings = {
705
+ version : 1 ,
706
+ features : { } ,
707
+ settings : {
708
+ taskSyncEnabled : true ,
709
+ } ,
710
+ }
711
+
712
+ // Mock that user has organization ID (indicating org settings should be used)
713
+ mockAuthService . getStoredOrganizationId . mockReturnValue ( "org-123" )
714
+
715
+ // Use reflection to set private settings
716
+ ; ( cloudSettingsService as unknown as { settings : typeof mockSettings } ) . settings = mockSettings
717
+ ; ( cloudSettingsService as unknown as { userSettings : typeof mockUserSettings } ) . userSettings =
718
+ mockUserSettings
719
+
720
+ // Should return false (org setting takes precedence)
721
+ expect ( cloudSettingsService . isTaskSyncEnabled ( ) ) . toBe ( false )
722
+ } )
723
+ } )
535
724
} )
0 commit comments