99 ProviderTokenResponse ,
1010 GenerateEmbeddedLinkResponse ,
1111 CreateOrInviteBatchResponse ,
12+ PatchUserBatchResponse ,
1213 UserPasswordHashed ,
1314} from './types' ;
1415
@@ -36,6 +37,17 @@ const mockMgmtInviteBatchResponse = {
3637 ] ,
3738} ;
3839
40+ const mockMgmtPatchBatchResponse = {
41+ patchedUsers :
[ { loginId :
'user1' , email :
'[email protected] ' } ] , 42+ failedUsers : [
43+ {
44+ failure : 'user not found' ,
45+ user :
{ loginId :
'user2' , email :
'[email protected] ' } , 46+ } ,
47+ ] ,
48+ additionalErrors : { user3 : 'invalid email format' } ,
49+ } ;
50+
3951describe ( 'Management User' , ( ) => {
4052 afterEach ( ( ) => {
4153 jest . clearAllMocks ( ) ;
@@ -575,6 +587,7 @@ describe('Management User', () => {
575587 verifiedPhone : false ,
576588 scim : true ,
577589 ssoAppIds : [ 'sso1' , 'sso2' ] ,
590+ status : 'invited' ,
578591 } ) ;
579592
580593 expect ( mockHttpClient . patch ) . toHaveBeenCalledWith ( apiPaths . user . patch , {
@@ -587,6 +600,120 @@ describe('Management User', () => {
587600 verifiedPhone : false ,
588601 ssoAppIds : [ 'sso1' , 'sso2' ] ,
589602 scim : true ,
603+ status : 'invited' ,
604+ } ) ;
605+ } ) ;
606+ } ) ;
607+
608+ describe ( 'patchBatch' , ( ) => {
609+ it ( 'should send the correct request and receive correct response' , async ( ) => {
610+ const httpResponse = {
611+ ok : true ,
612+ json : ( ) => mockMgmtPatchBatchResponse ,
613+ clone : ( ) => ( {
614+ json : ( ) => Promise . resolve ( mockMgmtPatchBatchResponse ) ,
615+ } ) ,
616+ status : 200 ,
617+ } ;
618+ mockHttpClient . patch . mockResolvedValue ( httpResponse ) ;
619+ const resp : SdkResponse < PatchUserBatchResponse > = await management . user . patchBatch ( [
620+ {
621+ loginId : 'user1' ,
622+ 623+ displayName : 'User One' ,
624+ roles : [ 'role1' ] ,
625+ } ,
626+ {
627+ loginId : 'user2' ,
628+ phone : '+1234567890' ,
629+ verifiedPhone : true ,
630+ customAttributes : { department : 'engineering' } ,
631+ } ,
632+ {
633+ loginId : 'user3' ,
634+ status : 'disabled' ,
635+ } ,
636+ ] ) ;
637+ expect ( mockHttpClient . patch ) . toHaveBeenCalledWith ( apiPaths . user . patchBatch , {
638+ users : [
639+ {
640+ loginId : 'user1' ,
641+ 642+ displayName : 'User One' ,
643+ roleNames : [ 'role1' ] ,
644+ } ,
645+ {
646+ loginId : 'user2' ,
647+ phone : '+1234567890' ,
648+ verifiedPhone : true ,
649+ customAttributes : { department : 'engineering' } ,
650+ } ,
651+ {
652+ loginId : 'user3' ,
653+ status : 'disabled' ,
654+ } ,
655+ ] ,
656+ } ) ;
657+ expect ( resp ) . toEqual ( {
658+ code : 200 ,
659+ data : mockMgmtPatchBatchResponse ,
660+ ok : true ,
661+ response : httpResponse ,
662+ } ) ;
663+ } ) ;
664+
665+ it ( 'should handle empty user array' , async ( ) => {
666+ const httpResponse = {
667+ ok : true ,
668+ json : ( ) => ( { patchedUsers : [ ] , failedUsers : [ ] , additionalErrors : { } } ) ,
669+ clone : ( ) => ( {
670+ json : ( ) => Promise . resolve ( { patchedUsers : [ ] , failedUsers : [ ] , additionalErrors : { } } ) ,
671+ } ) ,
672+ status : 200 ,
673+ } ;
674+ mockHttpClient . patch . mockResolvedValue ( httpResponse ) ;
675+ const resp : SdkResponse < PatchUserBatchResponse > = await management . user . patchBatch ( [ ] ) ;
676+ expect ( mockHttpClient . patch ) . toHaveBeenCalledWith ( apiPaths . user . patchBatch , {
677+ users : [ ] ,
678+ } ) ;
679+ expect ( resp ) . toEqual ( {
680+ code : 200 ,
681+ data : { patchedUsers : [ ] , failedUsers : [ ] , additionalErrors : { } } ,
682+ ok : true ,
683+ response : httpResponse ,
684+ } ) ;
685+ } ) ;
686+
687+ it ( 'should only include defined fields in patch request' , async ( ) => {
688+ const httpResponse = {
689+ ok : true ,
690+ json : ( ) => mockMgmtPatchBatchResponse ,
691+ clone : ( ) => ( {
692+ json : ( ) => Promise . resolve ( mockMgmtPatchBatchResponse ) ,
693+ } ) ,
694+ status : 200 ,
695+ } ;
696+ mockHttpClient . patch . mockResolvedValue ( httpResponse ) ;
697+ await management . user . patchBatch ( [
698+ {
699+ loginId : 'user1' ,
700+ 701+ phone : undefined ,
702+ displayName : 'Updated Name' ,
703+ roles : undefined ,
704+ verifiedEmail : true ,
705+ verifiedPhone : undefined ,
706+ } ,
707+ ] ) ;
708+ expect ( mockHttpClient . patch ) . toHaveBeenCalledWith ( apiPaths . user . patchBatch , {
709+ users : [
710+ {
711+ loginId : 'user1' ,
712+ 713+ displayName : 'Updated Name' ,
714+ verifiedEmail : true ,
715+ } ,
716+ ] ,
590717 } ) ;
591718 } ) ;
592719 } ) ;
0 commit comments