@@ -184,7 +184,7 @@ describe('org:create', () => {
184184 '--type' ,
185185 'scratch' ,
186186 '--setalias' ,
187- 'sandboxAlias ' ,
187+ 'scratchOrgAlias ' ,
188188 '--setdefaultusername' ,
189189 '--definitionfile' ,
190190 definitionfile ,
@@ -198,7 +198,8 @@ describe('org:create', () => {
198198 ...CREATE_RESULT ,
199199 username : 'newScratchUsername' ,
200200 } ) ;
201- const aliasStub = stubMethod ( sandbox , Aliases . prototype , 'set' ) ;
201+ const updateValueStub = stubMethod ( sandbox , Aliases . prototype , 'updateValue' ) ;
202+ const getKeysByValueStub = stubMethod ( sandbox , Aliases . prototype , 'getKeysByValue' ) . returns ( [ ] ) ;
202203 const configStub = stubMethod ( sandbox , Config . prototype , 'set' ) ;
203204 await command . runIt ( ) ;
204205 expect ( prodOrg . firstCall . args [ 0 ] ) . to . deep . equal ( {
@@ -216,10 +217,55 @@ describe('org:create', () => {
216217 retry : 0 ,
217218 orgConfig : { } ,
218219 } ) ;
219- expect ( aliasStub . firstCall . args ) . to . deep . equal ( [ 'sandboxAlias' , 'newScratchUsername' ] ) ;
220+ expect ( updateValueStub . firstCall . args ) . to . deep . equal ( [ 'scratchOrgAlias' , 'newScratchUsername' ] ) ;
221+ expect ( getKeysByValueStub . firstCall . args ) . to . deep . equal ( [ 'newScratchUsername' ] ) ;
220222 expect ( configStub . firstCall . args ) . to . deep . equal ( [ 'defaultusername' , 'newScratchUsername' ] ) ;
221223 } ) ;
222224
225+ it ( 'will set alias as default' , async ( ) => {
226+ const definitionfile = 'myScratchDef.json' ;
227+ const command = createCommand ( [
228+ '--type' ,
229+ 'scratch' ,
230+ '--setalias' ,
231+ 'scratchOrgAlias' ,
232+ '--setdefaultusername' ,
233+ '--definitionfile' ,
234+ definitionfile ,
235+ '-u' ,
236+ 'testProdOrg' ,
237+ ] ) ;
238+
239+ scratchOrgCreateStub . restore ( ) ;
240+ stubMethod ( sandbox , Org , 'create' ) . resolves ( Org . prototype ) ;
241+ const prodOrg = stubMethod ( sandbox , Org . prototype , 'scratchOrgCreate' ) . resolves ( {
242+ ...CREATE_RESULT ,
243+ username : 'newScratchUsername' ,
244+ } ) ;
245+ const updateValueStub = stubMethod ( sandbox , Aliases . prototype , 'updateValue' ) ;
246+ const getKeysByValueStub = stubMethod ( sandbox , Aliases . prototype , 'getKeysByValue' ) . returns ( [ 'scratchOrgAlias' ] ) ;
247+ const configStub = stubMethod ( sandbox , Config . prototype , 'set' ) ;
248+ await command . runIt ( ) ;
249+ expect ( prodOrg . firstCall . args [ 0 ] ) . to . deep . equal ( {
250+ apiversion : undefined ,
251+ clientSecret : undefined ,
252+ connectedAppConsumerKey : undefined ,
253+ definitionfile,
254+ durationDays : undefined ,
255+ noancestors : undefined ,
256+ nonamespace : undefined ,
257+ wait : {
258+ quantity : 6 ,
259+ unit : 0 ,
260+ } ,
261+ retry : 0 ,
262+ orgConfig : { } ,
263+ } ) ;
264+ expect ( updateValueStub . firstCall . args ) . to . deep . equal ( [ 'scratchOrgAlias' , 'newScratchUsername' ] ) ;
265+ expect ( getKeysByValueStub . firstCall . args ) . to . deep . equal ( [ 'newScratchUsername' ] ) ;
266+ expect ( configStub . firstCall . args ) . to . deep . equal ( [ 'defaultusername' , 'scratchOrgAlias' ] ) ;
267+ } ) ;
268+
223269 it ( 'will test json output' , async ( ) => {
224270 const definitionfile = 'myScratchDef.json' ;
225271 const command = createCommand ( [ '--type' , 'scratch' , '--definitionfile' , definitionfile , '-u' , 'testProdOrg' ] ) ;
0 commit comments