File tree Expand file tree Collapse file tree 2 files changed +9
-16
lines changed
src/commands/force/org/beta Expand file tree Collapse file tree 2 files changed +9
-16
lines changed Original file line number Diff line number Diff line change @@ -269,14 +269,15 @@ export class Create extends SfdxCommand {
269269 this . logger . debug ( 'Set Alias: %s result: %s' , this . flags . setalias , result ) ;
270270 }
271271 if ( this . flags . setdefaultusername ) {
272+ let config : Config ;
272273 try {
273- const config = await Config . create ( { isGlobal : false } ) ;
274- const result = config . set ( Config . DEFAULT_USERNAME , username ) ;
275- await config . write ( ) ;
276- this . logger . debug ( 'Set defaultUsername: %s result: %s' , this . flags . setdefaultusername , result ) ;
277- } catch ( error ) {
278- this . logger . debug ( 'Set defaultUsername failed with error: %s' , error ) ;
274+ config = await Config . create ( { isGlobal : false } ) ;
275+ } catch {
276+ config = await Config . create ( { isGlobal : true } ) ;
279277 }
278+ const result = config . set ( Config . DEFAULT_USERNAME , username ) ;
279+ await config . write ( ) ;
280+ this . logger . debug ( 'Set defaultUsername: %s result: %s' , this . flags . setdefaultusername , result ) ;
280281 }
281282 }
282283 private async createScratchOrg ( ) : Promise < ScratchOrgProcessObject > {
Original file line number Diff line number Diff line change @@ -199,12 +199,7 @@ describe('org:create', () => {
199199 username : 'newScratchUsername' ,
200200 } ) ;
201201 const aliasStub = stubMethod ( sandbox , Aliases . prototype , 'set' ) ;
202- const setStub = sandbox . spy ( ) ;
203- const writeStub = sandbox . spy ( ) ;
204- const configCreateStub = stubMethod ( sandbox , Config , 'create' ) . withArgs ( { isGlobal : false } ) . resolves ( {
205- set : setStub ,
206- write : writeStub ,
207- } ) ;
202+ const configStub = stubMethod ( sandbox , Config . prototype , 'set' ) ;
208203 await command . runIt ( ) ;
209204 expect ( prodOrg . firstCall . args [ 0 ] ) . to . deep . equal ( {
210205 apiversion : undefined ,
@@ -222,10 +217,7 @@ describe('org:create', () => {
222217 orgConfig : { } ,
223218 } ) ;
224219 expect ( aliasStub . firstCall . args ) . to . deep . equal ( [ 'sandboxAlias' , 'newScratchUsername' ] ) ;
225- expect ( configCreateStub . calledOnce ) . to . be . true ;
226- expect ( writeStub . calledOnce ) . to . be . true ;
227- expect ( configCreateStub . firstCall . firstArg ) . to . deep . equal ( { isGlobal : false } ) ;
228- expect ( setStub . firstCall . args ) . to . deep . equal ( [ 'defaultusername' , 'newScratchUsername' ] ) ;
220+ expect ( configStub . firstCall . args ) . to . deep . equal ( [ 'defaultusername' , 'newScratchUsername' ] ) ;
229221 } ) ;
230222
231223 it ( 'will test json output' , async ( ) => {
You can’t perform that action at this time.
0 commit comments