@@ -16,9 +16,13 @@ const orgs = [
1616 { id : '1' , code : 'CODE01' , name : 'ORG01' , type : 'entp' } ,
1717 { id : '2' , code : 'CODE02' , name : 'ORG02' , type : 'entp' } ,
1818 { id : '3' , code : 'CODE03' , name : 'ORG03' , type : 'entp' } ,
19- { id : '33' , code : 'CODE03' , name : 'ORG03' , type : 'not_entp' }
19+ { id : '4' , code : 'CODE04' , name : 'ORG04' , type : 'developer' } ,
20+ { id : '6' , code : 'CODE06' , name : 'ORG06' , type : 'developer' } ,
21+ { id : '33' , code : 'CODE33' , name : 'ORG33' , type : 'not_entp' }
2022]
23+ const selectableOrgs = orgs . slice ( 0 , 4 )
2124const selectedOrg = { id : '1' , code : 'CODE01' , name : 'ORG01' , type : 'entp' }
25+ const selectedDeveloperOrg = { id : '4' , code : 'CODE04' , name : 'ORG04' , type : 'developer' }
2226/** @private */
2327function setDefaultMockConsoleCLI ( ) {
2428 mockConsoleCLIInstance . getOrganizations = jest . fn ( ) . mockResolvedValue ( orgs )
@@ -36,6 +40,10 @@ let command
3640beforeEach ( ( ) => {
3741 command = new SelectCommand ( [ ] )
3842 setDefaultMockConsoleCLI ( )
43+ global . fetch = jest . fn ( url => Promise . resolve ( {
44+ ok : true ,
45+ json : ( ) => Promise . resolve ( url . endsWith ( '/4/features' ) ? [ { name : 'RUNTIME' } ] : [ ] )
46+ } ) )
3947 config . set . mockReset ( )
4048 config . delete . mockReset ( )
4149} )
@@ -73,7 +81,7 @@ describe('console:org:select', () => {
7381 test ( 'should select the provided org code' , async ( ) => {
7482 command . argv = [ selectedOrg . code ]
7583 await expect ( command . run ( ) ) . resolves . not . toThrow ( )
76- expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . toHaveBeenCalledWith ( orgs , { orgCode : selectedOrg . code , orgId : selectedOrg . code } )
84+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . toHaveBeenCalledWith ( selectableOrgs , { orgCode : selectedOrg . code , orgId : selectedOrg . code } )
7785 // stores the org configuration
7886 expect ( config . set ) . toHaveBeenCalledWith ( 'console.org' , { code : selectedOrg . code , id : selectedOrg . id , name : selectedOrg . name } )
7987 expect ( config . delete ) . toHaveBeenCalledWith ( 'console.project' )
@@ -82,7 +90,7 @@ describe('console:org:select', () => {
8290 test ( 'should select the provided org id' , async ( ) => {
8391 command . argv = [ selectedOrg . id ]
8492 await expect ( command . run ( ) ) . resolves . not . toThrow ( )
85- expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . toHaveBeenCalledWith ( orgs , { orgCode : selectedOrg . id , orgId : selectedOrg . id } )
93+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . toHaveBeenCalledWith ( selectableOrgs , { orgCode : selectedOrg . id , orgId : selectedOrg . id } )
8694 // stores the org configuration
8795 expect ( config . set ) . toHaveBeenCalledWith ( 'console.org' , { code : selectedOrg . code , id : selectedOrg . id , name : selectedOrg . name } )
8896 expect ( config . delete ) . toHaveBeenCalledWith ( 'console.project' )
@@ -91,13 +99,23 @@ describe('console:org:select', () => {
9199 test ( 'should prompt for selection if no org is provided' , async ( ) => {
92100 command . argv = [ ]
93101 await expect ( command . run ( ) ) . resolves . not . toThrow ( )
94- expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . toHaveBeenCalledWith ( orgs , { orgCode : undefined , orgId : undefined } )
102+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . toHaveBeenCalledWith ( selectableOrgs , { orgCode : undefined , orgId : undefined } )
95103 // stores the org configuration
96104 expect ( config . set ) . toHaveBeenCalledWith ( 'console.org' , { code : selectedOrg . code , id : selectedOrg . id , name : selectedOrg . name } )
97105 expect ( config . delete ) . toHaveBeenCalledWith ( 'console.project' )
98106 expect ( config . delete ) . toHaveBeenCalledWith ( 'console.workspace' )
99107 } )
100108
109+ test ( 'should select the provided developer org id' , async ( ) => {
110+ mockConsoleCLIInstance . promptForSelectOrganization . mockResolvedValue ( selectedDeveloperOrg )
111+ command . argv = [ selectedDeveloperOrg . id ]
112+ await expect ( command . run ( ) ) . resolves . not . toThrow ( )
113+ expect ( mockConsoleCLIInstance . promptForSelectOrganization ) . toHaveBeenCalledWith ( selectableOrgs , { orgCode : selectedDeveloperOrg . id , orgId : selectedDeveloperOrg . id } )
114+ expect ( config . set ) . toHaveBeenCalledWith ( 'console.org' , { code : selectedDeveloperOrg . code , id : selectedDeveloperOrg . id , name : selectedDeveloperOrg . name } )
115+ expect ( config . delete ) . toHaveBeenCalledWith ( 'console.project' )
116+ expect ( config . delete ) . toHaveBeenCalledWith ( 'console.workspace' )
117+ } )
118+
101119 test ( 'throw Error retrieving Orgs' , async ( ) => {
102120 mockConsoleCLIInstance . getOrganizations . mockRejectedValue ( new Error ( 'error org' ) )
103121 await expect ( command . run ( ) ) . rejects . toThrow ( new Error ( 'error org' ) )
0 commit comments