44 * Licensed under the BSD 3-Clause license.
55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
7- import { Aliases , Config , SfdxError , Messages , Org , SfdxProject } from '@salesforce/core' ;
7+ import { Config , GlobalInfo , SfError , Messages , Org , SfProject } from '@salesforce/core' ;
88import { fromStub , stubInterface , stubMethod } from '@salesforce/ts-sinon' ;
99import * as sinon from 'sinon' ;
10- import { expect , IConfig } from '@salesforce/command/lib/test' ;
10+ import { expect } from '@salesforce/command/lib/test' ;
11+ import { Config as IConfig } from '@oclif/core' ;
1112import { UX } from '@salesforce/command' ;
1213import { assert } from 'sinon' ;
1314import { Create } from '../../../../src/commands/force/org/beta/create' ;
@@ -35,14 +36,17 @@ const CREATE_RESULT = {
3536
3637describe ( 'org:create' , ( ) => {
3738 const sandbox = sinon . createSandbox ( ) ;
38- const oclifConfigStub = fromStub ( stubInterface < IConfig . IConfig > ( sandbox ) ) ;
39+ const oclifConfigStub = fromStub ( stubInterface < IConfig > ( sandbox ) ) ;
3940 const clientSecret = '123456' ;
4041 // stubs
4142 let resolveProjectConfigStub : sinon . SinonStub ;
4243 let scratchOrgCreateStub : sinon . SinonStub ;
4344 let uxLogStub : sinon . SinonStub ;
4445 let uxWarnStub : sinon . SinonStub ;
4546 let promptStub : sinon . SinonStub ;
47+ let aliasGetStub : sinon . SinonStub ;
48+ let aliasSetStub : sinon . SinonSpy ;
49+ let aliasUpdateStub : sinon . SinonSpy ;
4650 let cmd : TestCreate ;
4751
4852 class TestCreate extends Create {
@@ -53,7 +57,7 @@ describe('org:create', () => {
5357 public setOrg ( org : Org ) {
5458 this . org = org ;
5559 }
56- public setProject ( project : SfdxProject ) {
60+ public setProject ( project : SfProject ) {
5761 this . project = project ;
5862 }
5963 }
@@ -62,7 +66,7 @@ describe('org:create', () => {
6266 cmd = new TestCreate ( params , oclifConfigStub ) ;
6367 stubMethod ( sandbox , cmd , 'assignProject' ) . callsFake ( ( ) => {
6468 const sfdxProjectStub = fromStub (
65- stubInterface < SfdxProject > ( sandbox , {
69+ stubInterface < SfProject > ( sandbox , {
6670 resolveProjectConfig : resolveProjectConfigStub ,
6771 } )
6872 ) ;
@@ -198,8 +202,16 @@ describe('org:create', () => {
198202 ...CREATE_RESULT ,
199203 username : 'newScratchUsername' ,
200204 } ) ;
201- const updateValueStub = stubMethod ( sandbox , Aliases . prototype , 'updateValue' ) ;
202- const getKeysByValueStub = stubMethod ( sandbox , Aliases . prototype , 'getKeysByValue' ) . returns ( [ ] ) ;
205+ aliasGetStub = sinon . stub ( ) . returns ( '' ) ;
206+ aliasSetStub = sinon . spy ( ) ;
207+ aliasUpdateStub = sinon . spy ( ) ;
208+ stubMethod ( sandbox , GlobalInfo , 'getInstance' ) . returns ( {
209+ aliases : {
210+ get : aliasGetStub ,
211+ set : aliasSetStub ,
212+ update : aliasUpdateStub ,
213+ } ,
214+ } ) ;
203215 const configStub = stubMethod ( sandbox , Config . prototype , 'set' ) ;
204216 await command . runIt ( ) ;
205217 expect ( prodOrg . firstCall . args [ 0 ] ) . to . deep . equal ( {
@@ -217,8 +229,8 @@ describe('org:create', () => {
217229 retry : 0 ,
218230 orgConfig : { } ,
219231 } ) ;
220- expect ( updateValueStub . firstCall . args ) . to . deep . equal ( [ 'scratchOrgAlias' , 'newScratchUsername' ] ) ;
221- expect ( getKeysByValueStub . firstCall . args ) . to . deep . equal ( [ 'newScratchUsername' ] ) ;
232+ expect ( aliasUpdateStub . firstCall . args ) . to . deep . equal ( [ 'scratchOrgAlias' , 'newScratchUsername' ] ) ;
233+ expect ( aliasGetStub . firstCall . args ) . to . deep . equal ( [ 'newScratchUsername' ] ) ;
222234 expect ( configStub . firstCall . args ) . to . deep . equal ( [ 'defaultusername' , 'newScratchUsername' ] ) ;
223235 } ) ;
224236
@@ -242,8 +254,16 @@ describe('org:create', () => {
242254 ...CREATE_RESULT ,
243255 username : 'newScratchUsername' ,
244256 } ) ;
245- const updateValueStub = stubMethod ( sandbox , Aliases . prototype , 'updateValue' ) ;
246- const getKeysByValueStub = stubMethod ( sandbox , Aliases . prototype , 'getKeysByValue' ) . returns ( [ 'scratchOrgAlias' ] ) ;
257+
258+ aliasGetStub = sinon . stub ( ) . returns ( 'scratchOrgAlias' ) ;
259+ aliasUpdateStub = sinon . spy ( ) ;
260+ stubMethod ( sandbox , GlobalInfo , 'getInstance' ) . returns ( {
261+ aliases : {
262+ get : aliasGetStub ,
263+ update : aliasUpdateStub ,
264+ } ,
265+ } ) ;
266+
247267 const configStub = stubMethod ( sandbox , Config . prototype , 'set' ) ;
248268 await command . runIt ( ) ;
249269 expect ( prodOrg . firstCall . args [ 0 ] ) . to . deep . equal ( {
@@ -261,8 +281,8 @@ describe('org:create', () => {
261281 retry : 0 ,
262282 orgConfig : { } ,
263283 } ) ;
264- expect ( updateValueStub . firstCall . args ) . to . deep . equal ( [ 'scratchOrgAlias' , 'newScratchUsername' ] ) ;
265- expect ( getKeysByValueStub . firstCall . args ) . to . deep . equal ( [ 'newScratchUsername' ] ) ;
284+ expect ( aliasUpdateStub . firstCall . args ) . to . deep . equal ( [ 'scratchOrgAlias' , 'newScratchUsername' ] ) ;
285+ expect ( aliasGetStub . firstCall . args ) . to . deep . equal ( [ 'newScratchUsername' ] ) ;
266286 expect ( configStub . firstCall . args ) . to . deep . equal ( [ 'defaultusername' , 'scratchOrgAlias' ] ) ;
267287 } ) ;
268288
@@ -321,7 +341,7 @@ describe('org:create', () => {
321341
322342 scratchOrgCreateStub . restore ( ) ;
323343 stubMethod ( sandbox , Org , 'create' ) . resolves ( Org . prototype ) ;
324- stubMethod ( sandbox , Org . prototype , 'scratchOrgCreate' ) . rejects ( new SfdxError ( errorMessage ) ) ;
344+ stubMethod ( sandbox , Org . prototype , 'scratchOrgCreate' ) . rejects ( new SfError ( errorMessage ) ) ;
325345 try {
326346 await command . runIt ( ) ;
327347 assert . fail ( 'the above should throw an error' ) ;
0 commit comments