@@ -3,11 +3,13 @@ import { firstValueFrom, of, Subject } from "rxjs";
33
44// eslint-disable-next-line no-restricted-imports
55import { CollectionService , CollectionView } from "@bitwarden/admin-console/common" ;
6+ import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service" ;
67import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction" ;
78import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction" ;
89import { PolicyType } from "@bitwarden/common/admin-console/enums" ;
910import { Organization } from "@bitwarden/common/admin-console/models/domain/organization" ;
1011import { Policy } from "@bitwarden/common/admin-console/models/domain/policy" ;
12+ import { EventType } from "@bitwarden/common/enums" ;
1113import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum" ;
1214import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service" ;
1315import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service" ;
@@ -37,6 +39,7 @@ describe("DefaultVaultItemsTransferService", () => {
3739 let mockI18nService : MockProxy < I18nService > ;
3840 let mockDialogService : MockProxy < DialogService > ;
3941 let mockToastService : MockProxy < ToastService > ;
42+ let mockEventCollectionService : MockProxy < EventCollectionService > ;
4043 let mockConfigService : MockProxy < ConfigService > ;
4144
4245 const userId = "user-id" as UserId ;
@@ -71,6 +74,7 @@ describe("DefaultVaultItemsTransferService", () => {
7174 mockI18nService = mock < I18nService > ( ) ;
7275 mockDialogService = mock < DialogService > ( ) ;
7376 mockToastService = mock < ToastService > ( ) ;
77+ mockEventCollectionService = mock < EventCollectionService > ( ) ;
7478 mockConfigService = mock < ConfigService > ( ) ;
7579
7680 mockI18nService . t . mockImplementation ( ( key ) => key ) ;
@@ -85,6 +89,7 @@ describe("DefaultVaultItemsTransferService", () => {
8589 mockI18nService ,
8690 mockDialogService ,
8791 mockToastService ,
92+ mockEventCollectionService ,
8893 mockConfigService ,
8994 ) ;
9095 } ) ;
@@ -774,6 +779,63 @@ describe("DefaultVaultItemsTransferService", () => {
774779 expect ( mockDialogService . open ) . toHaveBeenCalledTimes ( 4 ) ;
775780 expect ( mockCipherService . shareManyWithServer ) . not . toHaveBeenCalled ( ) ;
776781 } ) ;
782+
783+ describe ( "event logs" , ( ) => {
784+ it ( "logs accepted event when user accepts transfer" , async ( ) => {
785+ const personalCiphers = [ { id : "cipher-1" } as CipherView ] ;
786+ setupMocksForEnforcementScenario ( {
787+ policies : [ policy ] ,
788+ organizations : [ organization ] ,
789+ ciphers : personalCiphers ,
790+ defaultCollection : {
791+ id : collectionId ,
792+ organizationId : organizationId ,
793+ isDefaultCollection : true ,
794+ } as CollectionView ,
795+ } ) ;
796+
797+ mockDialogService . open . mockReturnValueOnce (
798+ createMockDialogRef ( TransferItemsDialogResult . Accepted ) ,
799+ ) ;
800+ mockCipherService . shareManyWithServer . mockResolvedValue ( undefined ) ;
801+
802+ await service . enforceOrganizationDataOwnership ( userId ) ;
803+
804+ expect ( mockEventCollectionService . collect ) . toHaveBeenCalledWith (
805+ EventType . Organization_ItemOrganization_Accepted ,
806+ undefined ,
807+ undefined ,
808+ organizationId ,
809+ ) ;
810+ } ) ;
811+
812+ it ( "logs declined event when user rejects transfer" , async ( ) => {
813+ const personalCiphers = [ { id : "cipher-1" } as CipherView ] ;
814+ setupMocksForEnforcementScenario ( {
815+ policies : [ policy ] ,
816+ organizations : [ organization ] ,
817+ ciphers : personalCiphers ,
818+ defaultCollection : {
819+ id : collectionId ,
820+ organizationId : organizationId ,
821+ isDefaultCollection : true ,
822+ } as CollectionView ,
823+ } ) ;
824+
825+ mockDialogService . open
826+ . mockReturnValueOnce ( createMockDialogRef ( TransferItemsDialogResult . Declined ) )
827+ . mockReturnValueOnce ( createMockDialogRef ( LeaveConfirmationDialogResult . Confirmed ) ) ;
828+
829+ await service . enforceOrganizationDataOwnership ( userId ) ;
830+
831+ expect ( mockEventCollectionService . collect ) . toHaveBeenCalledWith (
832+ EventType . Organization_ItemOrganization_Declined ,
833+ undefined ,
834+ undefined ,
835+ organizationId ,
836+ ) ;
837+ } ) ;
838+ } ) ;
777839 } ) ;
778840
779841 describe ( "transferInProgress$" , ( ) => {
0 commit comments