@@ -198,6 +198,9 @@ beforeEach(() => {
198198 env : 'stage'
199199 }
200200 } )
201+ authHelper . getTokenData . mockImplementation ( ( ) => {
202+ return null // default to null, tests can override
203+ } )
201204 LogForwarding . init . mockResolvedValue ( mockLogForwarding )
202205
203206 command = new TheCommand ( [ ] )
@@ -670,6 +673,136 @@ describe('run', () => {
670673 expect ( open ) . toHaveBeenCalledWith ( 'http://prefix?fake=https://example.com' )
671674 } )
672675
676+ test ( 'deploy should pass auditUserId to deployWeb config when user_id is present in token' , async ( ) => {
677+ const mockUserId = 'test-user-123'
678+ const mockToken = 'mock.token.value'
679+
680+ authHelper . getAccessToken . mockResolvedValueOnce ( {
681+ accessToken : mockToken ,
682+ env : 'stage'
683+ } )
684+ authHelper . getTokenData . mockReturnValueOnce ( {
685+ user_id : mockUserId
686+ } )
687+
688+ command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
689+ mockWebLib . deployWeb . mockResolvedValue ( 'https://example.com' )
690+
691+ command . argv = [ ]
692+ await command . run ( )
693+
694+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
695+ expect ( authHelper . getTokenData ) . toHaveBeenCalledWith ( mockToken )
696+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledWith (
697+ expect . objectContaining ( {
698+ auditUserId : mockUserId
699+ } ) ,
700+ expect . any ( Function )
701+ )
702+ } )
703+
704+ test ( 'deploy should NOT include auditUserId in config when user_id is undefined' , async ( ) => {
705+ const mockToken = 'mock.token.value'
706+
707+ authHelper . getAccessToken . mockResolvedValueOnce ( {
708+ accessToken : mockToken ,
709+ env : 'stage'
710+ } )
711+ authHelper . getTokenData . mockReturnValueOnce ( {
712+ // user_id is undefined
713+ } )
714+
715+ command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
716+ mockWebLib . deployWeb . mockResolvedValue ( 'https://example.com' )
717+
718+ command . argv = [ ]
719+ await command . run ( )
720+
721+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
722+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledWith (
723+ expect . not . objectContaining ( {
724+ auditUserId : expect . anything ( )
725+ } ) ,
726+ expect . any ( Function )
727+ )
728+ } )
729+
730+ test ( 'deploy should NOT include auditUserId in config when user_id is null' , async ( ) => {
731+ const mockToken = 'mock.token.value'
732+
733+ authHelper . getAccessToken . mockResolvedValueOnce ( {
734+ accessToken : mockToken ,
735+ env : 'stage'
736+ } )
737+ authHelper . getTokenData . mockReturnValueOnce ( {
738+ user_id : null
739+ } )
740+
741+ command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
742+ mockWebLib . deployWeb . mockResolvedValue ( 'https://example.com' )
743+
744+ command . argv = [ ]
745+ await command . run ( )
746+
747+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
748+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledWith (
749+ expect . not . objectContaining ( {
750+ auditUserId : expect . anything ( )
751+ } ) ,
752+ expect . any ( Function )
753+ )
754+ } )
755+
756+ test ( 'deploy should NOT include auditUserId in config when user_id is empty string' , async ( ) => {
757+ const mockToken = 'mock.token.value'
758+
759+ authHelper . getAccessToken . mockResolvedValueOnce ( {
760+ accessToken : mockToken ,
761+ env : 'stage'
762+ } )
763+ authHelper . getTokenData . mockReturnValueOnce ( {
764+ user_id : ''
765+ } )
766+
767+ command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
768+ mockWebLib . deployWeb . mockResolvedValue ( 'https://example.com' )
769+
770+ command . argv = [ ]
771+ await command . run ( )
772+
773+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
774+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledWith (
775+ expect . not . objectContaining ( {
776+ auditUserId : expect . anything ( )
777+ } ) ,
778+ expect . any ( Function )
779+ )
780+ } )
781+
782+ test ( 'deploy should NOT include auditUserId when getTokenData returns null' , async ( ) => {
783+ const mockToken = 'mock.token.value'
784+
785+ authHelper . getAccessToken . mockResolvedValueOnce ( {
786+ accessToken : mockToken ,
787+ env : 'stage'
788+ } )
789+ authHelper . getTokenData . mockReturnValueOnce ( null )
790+
791+ command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
792+ mockWebLib . deployWeb . mockResolvedValue ( 'https://example.com' )
793+
794+ command . argv = [ ]
795+ await command . run ( )
796+
797+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
798+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledWith (
799+ expect . not . objectContaining ( {
800+ auditUserId : expect . anything ( )
801+ } ) ,
802+ expect . any ( Function )
803+ )
804+ } )
805+
673806 test ( 'deploy should show action urls (web-export: true)' , async ( ) => {
674807 command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
675808 mockRuntimeLib . deployActions . mockResolvedValue ( {
0 commit comments