@@ -158,9 +158,11 @@ beforeEach(() => {
158158
159159 resetMockConsoleCLI ( )
160160 mockConsoleCLIInstance . promptForSelectOrganization . mockResolvedValue ( { id : 'my-org' } )
161+ mockConsoleCLIInstance . getOrganizations . mockResolvedValue ( [ { id : 'my-org' } , { id : 'other-org' } ] )
161162 mockConsoleCLIInstance . getDevTermsForOrg . mockResolvedValue ( { text : 'These are the Dev Terms.' } )
162163 mockConsoleCLIInstance . checkDevTermsForOrg . mockResolvedValue ( true )
163164 mockConsoleCLIInstance . createProject . mockResolvedValue ( { } )
165+ mockConsoleCLIInstance . getProjects . mockResolvedValue ( [ ] )
164166 mockConsoleCLIInstance . getWorkspaces . mockResolvedValue ( [ { name : 'Stage' } , { name : 'Production' } ] )
165167 mockConsoleCLIInstance . getWorkspaceConfig . mockResolvedValue ( {
166168 project : {
@@ -421,19 +423,17 @@ describe('--no-login', () => {
421423 expect ( importHelperLib . importConfigJson ) . not . toHaveBeenCalled ( )
422424 } )
423425
424- test ( '--yes --no-install, select excshell' , async ( ) => {
425- const installOptions = {
426- useDefaultValues : true ,
427- installNpm : false ,
428- installConfig : false ,
429- templates : [ '@adobe/my-extension' ]
430- }
431- command . selectTemplates . mockResolvedValue ( [ '@adobe/my-extension' ] )
432-
426+ test ( '--yes --no-install without --template creates standalone app' , async ( ) => {
433427 command . argv = [ '--no-login' , '--yes' , '--no-install' ]
434428 await command . run ( )
435429
436- expect ( command . installTemplates ) . toHaveBeenCalledWith ( installOptions )
430+ expect ( command . installTemplates ) . toHaveBeenCalledWith ( {
431+ useDefaultValues : true ,
432+ installNpm : false ,
433+ installConfig : false ,
434+ templates : [ ]
435+ } )
436+ expect ( command . selectTemplates ) . not . toHaveBeenCalled ( )
437437 expect ( LibConsoleCLI . init ) . not . toHaveBeenCalled ( )
438438 expect ( importHelperLib . importConfigJson ) . not . toHaveBeenCalled ( )
439439 } )
@@ -544,6 +544,103 @@ describe('--login', () => {
544544 expect ( importHelperLib . importConfigJson ) . toHaveBeenCalled ( )
545545 } )
546546
547+ test ( '--yes --project name45 selects existing project without creating' , async ( ) => {
548+ mockConsoleCLIInstance . getProjects . mockResolvedValue ( [ { id : 'proj45id' , name : 'name45' } ] )
549+
550+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' , '--project' , 'name45' ]
551+ await command . run ( )
552+
553+ expect ( mockConsoleCLIInstance . createProject ) . not . toHaveBeenCalled ( )
554+ expect ( importHelperLib . importConfigJson ) . toHaveBeenCalled ( )
555+ } )
556+
557+ test ( '--yes --project name45 creates project when it does not exist' , async ( ) => {
558+ mockConsoleCLIInstance . getProjects . mockResolvedValue ( [ { id : 'other' , name : 'otherProject' } ] )
559+ mockConsoleCLIInstance . createProject . mockResolvedValue ( { id : 'newid' , name : 'name45' } )
560+
561+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' , '--project' , 'name45' ]
562+ await command . run ( )
563+
564+ expect ( mockConsoleCLIInstance . createProject ) . toHaveBeenCalledWith (
565+ expect . anything ( ) ,
566+ { name : 'name45' , title : 'name45' , description : 'App Builder Project name45 - generated by an agent' }
567+ )
568+ expect ( importHelperLib . importConfigJson ) . toHaveBeenCalled ( )
569+ } )
570+
571+ test ( '--yes with no existing projects uses App1' , async ( ) => {
572+ mockConsoleCLIInstance . getProjects . mockResolvedValue ( [ ] )
573+ mockConsoleCLIInstance . createProject . mockResolvedValue ( { id : 'newprojid' , name : 'App1' } )
574+
575+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' ]
576+ await command . run ( )
577+
578+ expect ( mockConsoleCLIInstance . createProject ) . toHaveBeenCalledWith (
579+ expect . anything ( ) ,
580+ { name : 'App1' , title : 'App Builder Project 1' , description : 'App Builder Project 1 - generated' }
581+ )
582+ expect ( importHelperLib . importConfigJson ) . toHaveBeenCalled ( )
583+ } )
584+
585+ test ( '--yes skips existing names and picks next available suffix' , async ( ) => {
586+ mockConsoleCLIInstance . getProjects . mockResolvedValue ( [
587+ { name : 'App1' } ,
588+ { name : 'App2' } ,
589+ { name : 'App3' }
590+ ] )
591+ mockConsoleCLIInstance . createProject . mockResolvedValue ( { id : 'newprojid' , name : 'App4' } )
592+
593+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' ]
594+ await command . run ( )
595+
596+ expect ( mockConsoleCLIInstance . createProject ) . toHaveBeenCalledWith (
597+ expect . anything ( ) ,
598+ { name : 'App4' , title : 'App Builder Project 4' , description : 'App Builder Project 4 - generated' }
599+ )
600+ } )
601+
602+ test ( '--yes skips non-sequential gaps and picks first available' , async ( ) => {
603+ mockConsoleCLIInstance . getProjects . mockResolvedValue ( [
604+ { name : 'App1' } ,
605+ { name : 'App3' }
606+ ] )
607+ mockConsoleCLIInstance . createProject . mockResolvedValue ( { id : 'newprojid' , name : 'App2' } )
608+
609+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' ]
610+ await command . run ( )
611+
612+ expect ( mockConsoleCLIInstance . createProject ) . toHaveBeenCalledWith (
613+ expect . anything ( ) ,
614+ { name : 'App2' , title : 'App Builder Project 2' , description : 'App Builder Project 2 - generated' }
615+ )
616+ } )
617+
618+ test ( '--yes errors when all App{N} names up to MAX_SUFFIX are taken' , async ( ) => {
619+ const MAX_SUFFIX = 10000
620+ const allTaken = Array . from ( { length : MAX_SUFFIX } , ( _ , i ) => ( { name : `App${ i + 1 } ` } ) )
621+ mockConsoleCLIInstance . getProjects . mockResolvedValue ( allTaken )
622+
623+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' ]
624+ await expect ( command . run ( ) ) . rejects . toThrow ( `Could not find an available generated App name after ${ MAX_SUFFIX } attempts` )
625+ expect ( mockConsoleCLIInstance . createProject ) . not . toHaveBeenCalled ( )
626+ } )
627+
628+ test ( '--yes with missing workspace auto-creates without confirm prompt' , async ( ) => {
629+ mockConsoleCLIInstance . createProject . mockResolvedValue ( { id : 'newprojid' , name : 'App1' } )
630+ mockConsoleCLIInstance . getWorkspaces . mockResolvedValue ( [ { name : 'Stage' } , { name : 'Production' } ] )
631+ mockConsoleCLIInstance . createWorkspace . mockResolvedValue ( { id : 'newwsid' , name : 'CustomWs' } )
632+
633+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' , '-w' , 'CustomWs' ]
634+ await command . run ( )
635+
636+ expect ( mockConsoleCLIInstance . prompt . promptConfirm ) . not . toHaveBeenCalled ( )
637+ expect ( mockConsoleCLIInstance . createWorkspace ) . toHaveBeenCalledWith (
638+ expect . anything ( ) ,
639+ expect . anything ( ) ,
640+ expect . objectContaining ( { name : 'CustomWs' } )
641+ )
642+ } )
643+
547644 test ( '--import fakeconfig.json' , async ( ) => {
548645 importHelperLib . loadAndValidateConfigFile . mockReturnValue ( { values : fakeConfig } )
549646 importHelperLib . getServiceApiKey . mockReturnValue ( 'fakeclientid' )
@@ -787,6 +884,65 @@ describe('no args', () => {
787884 } )
788885} )
789886
887+ describe ( 'selectConsoleOrg' , ( ) => {
888+ test ( 'no organizations returned' , async ( ) => {
889+ mockConsoleCLIInstance . getOrganizations . mockResolvedValue ( null )
890+ await expect ( command . run ( ) ) . rejects . toThrow ( 'No organizations found for the logged-in user' )
891+ } )
892+
893+ test ( 'empty organizations list' , async ( ) => {
894+ mockConsoleCLIInstance . getOrganizations . mockResolvedValue ( [ ] )
895+ await expect ( command . run ( ) ) . rejects . toThrow ( 'No organizations found for the logged-in user' )
896+ } )
897+
898+ test ( 'single org is auto-selected without prompt' , async ( ) => {
899+ mockConsoleCLIInstance . getOrganizations . mockResolvedValue ( [ { id : 'my-org' , name : 'My Org' } ] )
900+ command . argv = [ '--standalone-app' ]
901+ await command . run ( )
902+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . not . toHaveBeenCalled ( )
903+ expect ( LibConsoleCLI . init ) . toHaveBeenCalled ( )
904+ } )
905+
906+ test ( '--yes with multiple orgs auto-selects first org without prompt' , async ( ) => {
907+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' ]
908+ await command . run ( )
909+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . not . toHaveBeenCalled ( )
910+ expect ( importHelperLib . importConfigJson ) . toHaveBeenCalled ( )
911+ } )
912+
913+ test ( '--yes --org selects matching org by id without prompt' , async ( ) => {
914+ mockConsoleCLIInstance . getOrganizations . mockResolvedValue ( [ { id : 'org-a' } , { id : 'org-b' } ] )
915+ command . argv = [ '--yes' , '--org' , 'org-b' , '--no-install' , '--template' , '@adobe/my-extension' ]
916+ await command . run ( )
917+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . not . toHaveBeenCalled ( )
918+ expect ( mockConsoleCLIInstance . getEnabledServicesForOrg ) . toHaveBeenCalledWith ( 'org-b' )
919+ } )
920+
921+ test ( '--yes --org throws when org not found' , async ( ) => {
922+ mockConsoleCLIInstance . getOrganizations . mockResolvedValue ( [ { id : 'org-a' } , { id : 'org-b' } ] )
923+ command . argv = [ '--yes' , '--org' , 'non-existent-org' , '--no-install' , '--template' , '@adobe/my-extension' ]
924+ await expect ( command . run ( ) ) . rejects . toThrow ( '--org non-existent-org not found' )
925+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . not . toHaveBeenCalled ( )
926+ } )
927+
928+ test ( '--org throws when mismatched against the only org (single org)' , async ( ) => {
929+ mockConsoleCLIInstance . getOrganizations . mockResolvedValue ( [ { id : 'only-org' } ] )
930+ command . argv = [ '--yes' , '--org' , 'wrong-org' , '--no-install' , '--template' , '@adobe/my-extension' ]
931+ await expect ( command . run ( ) ) . rejects . toThrow ( '--org wrong-org not found' )
932+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . not . toHaveBeenCalled ( )
933+ } )
934+ } )
935+
936+ describe ( 'ensureDevTermAccepted' , ( ) => {
937+ test ( 'uses skipPrompts=false by default (terms already accepted)' , async ( ) => {
938+ mockConsoleCLIInstance . checkDevTermsForOrg . mockResolvedValue ( true )
939+ // Call directly without the third argument to exercise the default parameter
940+ await command . ensureDevTermAccepted ( mockConsoleCLIInstance , 'org-id' )
941+ expect ( mockConsoleCLIInstance . checkDevTermsForOrg ) . toHaveBeenCalledWith ( 'org-id' )
942+ expect ( mockConsoleCLIInstance . prompt . promptConfirm ) . not . toHaveBeenCalled ( )
943+ } )
944+ } )
945+
790946describe ( 'dev terms' , ( ) => {
791947 test ( 'not accepted' , async ( ) => {
792948 mockConsoleCLIInstance . checkDevTermsForOrg . mockResolvedValue ( false )
@@ -814,6 +970,13 @@ describe('dev terms', () => {
814970
815971 await expect ( command . run ( ) ) . rejects . toThrow ( 'The Developer Terms of Service could not be accepted' )
816972 } )
973+
974+ test ( '--yes errors without prompting when terms not accepted' , async ( ) => {
975+ mockConsoleCLIInstance . checkDevTermsForOrg . mockResolvedValue ( false )
976+ command . argv = [ '--yes' , '--no-install' , '--template' , '@adobe/my-extension' ]
977+ await expect ( command . run ( ) ) . rejects . toThrow ( 'Developer Terms of Service have not been accepted' )
978+ expect ( mockConsoleCLIInstance . prompt . promptConfirm ) . not . toHaveBeenCalled ( )
979+ } )
817980} )
818981
819982describe ( 'template-options' , ( ) => {
0 commit comments