55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
77import * as fs from 'fs' ;
8- import {
9- Org ,
10- Lifecycle ,
11- StateAggregator ,
12- SandboxEvents ,
13- // SfdxConfigAggregator,
14- // OrgConfigProperties,
15- // ConfigAggregator,
16- SandboxProcessObject ,
17- Logger ,
18- } from '@salesforce/core' ;
8+ import { Org , Lifecycle , SandboxEvents , SandboxProcessObject , Logger , SfError } from '@salesforce/core' ;
199import { stubMethod } from '@salesforce/ts-sinon' ;
20- import { TestContext } from '@salesforce/core/lib/testSetup' ;
10+ import { shouldThrow , TestContext } from '@salesforce/core/lib/testSetup' ;
2111import { stubSfCommandUx , stubUx } from '@salesforce/sf-plugins-core' ;
2212import { assert , expect , config } from 'chai' ;
2313import * as sinon from 'sinon' ;
@@ -84,30 +74,17 @@ describe('org:clone', () => {
8474
8575 // stubs
8676 let requestStub : sinon . SinonStub ;
87- // let aliasSetStub: sinon.SinonSpy;
88- // let configSetStub: sinon.SinonStub;
89- // let configWriteStub: sinon.SinonStub;
9077 let onStub : sinon . SinonStub ;
91- // let readJsonDefFileStub: sinon.SinonStub;
9278 let cloneSandboxStub : sinon . SinonStub ;
93- // let configAggregatorStub;
9479 let sfCommandUxStubs : ReturnType < typeof stubSfCommandUx > ;
80+ let setAliasStub : sinon . SinonStub ;
81+ let setDefaultUsernameStub : sinon . SinonStub ;
9582
9683 const runCloneCommand = async ( params : string [ ] , fails ?: boolean ) : Promise < SandboxProcessObject > => {
9784 cloneSandboxStub = fails
9885 ? $$ . SANDBOX . stub ( Org . prototype , 'cloneSandbox' ) . rejects ( new Error ( 'MyError' ) )
9986 : $$ . SANDBOX . stub ( Org . prototype , 'cloneSandbox' ) . resolves ( sandboxProcessObj ) ;
10087
101- // configSetStub = $$.SANDBOX.stub().returns(true);
102- // configWriteStub = $$.SANDBOX.stub().resolves(true);
103- // const configAggregatorStubOptions = {
104- // getGlobalConfig: () => ({
105- // set: configSetStub,
106- // write: configWriteStub,
107- // }),
108- // };
109- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
110- // cmd.setConfigAggregator(configAggregatorStub);
11188 if ( ! fails ) {
11289 onStub = $$ . SANDBOX . stub ( )
11390 . callsArgWith ( 1 , sandboxProcessObj )
@@ -124,6 +101,9 @@ describe('org:clone', () => {
124101 onWarning : $$ . SANDBOX . stub ( ) ,
125102 } ) ;
126103
104+ setAliasStub = $$ . SANDBOX . stub ( OrgCloneCommand . prototype , 'setAlias' ) . resolves ( ) ;
105+ setDefaultUsernameStub = $$ . SANDBOX . stub ( OrgCloneCommand . prototype , 'setDefaultUsername' ) . resolves ( ) ;
106+
127107 return OrgCloneCommand . run ( params ) ;
128108 } ;
129109
@@ -159,10 +139,11 @@ describe('org:clone', () => {
159139
160140 expect ( sfCommandUxStubs . table . firstCall . args [ 0 ] . length ) . to . be . equal ( 12 ) ;
161141 expect ( sfCommandUxStubs . log . callCount ) . to . be . equal ( 3 ) ;
162- const stateAggregator = await StateAggregator . getInstance ( ) ;
163- expect ( stateAggregator . aliases . getAll ( ) ) . to . deep . equal ( { } ) ;
164- // expect(configSetStub.callCount).to.be.equal(0);
165- // expect(configWriteStub.callCount).to.be.equal(0);
142+
143+ // Alias and default username should not be set.
144+ expect ( setAliasStub . callCount ) . to . equal ( 0 ) ;
145+ expect ( setDefaultUsernameStub . callCount ) . to . equal ( 0 ) ;
146+
166147 expect ( onStub . firstCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_ASYNC_RESULT ) ;
167148 expect ( onStub . secondCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_STATUS ) ;
168149 expect ( onStub . thirdCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_RESULT ) ;
@@ -185,19 +166,15 @@ describe('org:clone', () => {
185166 expect ( sfCommandUxStubs . table . firstCall . args [ 0 ] . length ) . to . be . equal ( 12 ) ;
186167 expect ( sfCommandUxStubs . log . callCount ) . to . be . equal ( 3 ) ;
187168
188- const stateAggregator = await StateAggregator . getInstance ( ) ;
189- expect ( stateAggregator . aliases . getAll ( ) ) . to . deep . equal ( { [ sandboxAlias ] : authUserName } ) ;
169+ expect ( setAliasStub . firstCall . args ) . to . deep . equal ( [ sandboxAlias , authUserName ] ) ;
190170
191- expect ( $$ . stubs . configWrite . callCount ) . to . equal ( 2 ) ;
192171 expect ( sfCommandUxStubs . styledHeader . callCount ) . to . equal ( 1 ) ;
193172 expect ( sfCommandUxStubs . table . firstCall . args [ 0 ] . length ) . to . be . equal ( 12 ) ;
194173 expect ( sfCommandUxStubs . log . callCount ) . to . be . equal ( 3 ) ;
195174
196- // expect($$.configAggregator?.getGlobalConfig()?.get(OrgConfigProperties.TARGET_ORG)). to.equal(authUserName) ;
197- // expect(configSetStub.callCount ).to.be.equal(1 );
175+ expect ( setDefaultUsernameStub . calledOnce ) . to . be . true ;
176+ expect ( setDefaultUsernameStub . firstCall . args [ 0 ] ) . to . be . equal ( authUserName ) ;
198177
199- // expect(configSetStub.firstCall.args[0]).to.be.equal(OrgConfigProperties.TARGET_ORG);
200- // expect(configSetStub.firstCall.args[1]).to.be.equal(authUserName);
201178 expect ( onStub . firstCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_ASYNC_RESULT ) ;
202179 expect ( onStub . secondCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_STATUS ) ;
203180 expect ( onStub . thirdCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_RESULT ) ;
@@ -206,7 +183,6 @@ describe('org:clone', () => {
206183 authUserName,
207184 SandboxName : sandboxName ,
208185 } ) ;
209- // expect(configWriteStub.calledOnce).to.be.true;
210186 expect ( res ) . to . deep . equal ( sandboxProcessObj ) ;
211187 } ) ;
212188
@@ -216,21 +192,15 @@ describe('org:clone', () => {
216192 srcSandboxName : 'TheOriginal' ,
217193 } ) ;
218194 try {
219- // await shouldThrow(
220- // runCloneCommand(['-t', 'sandbox', '-u', 'DevHub', '-f', 'sandbox-def.json', '-a', sandboxAlias, '-s'], true)
221- // );
222- await runCloneCommand (
223- [ '-t' , 'sandbox' , '-u' , 'DevHub' , '-f' , 'sandbox-def.json' , '-a' , sandboxAlias , '-s' ] ,
224- true
195+ await shouldThrow (
196+ runCloneCommand ( [ '-t' , 'sandbox' , '-u' , 'DevHub' , '-f' , 'sandbox-def.json' , '-a' , sandboxAlias , '-s' ] , true )
225197 ) ;
226198 } catch ( error ) {
227- const e = error as Error ;
228- expect ( e . name === 'MyError' ) ;
199+ assert ( error instanceof SfError , 'should be an SfError' ) ;
200+ expect ( error . name === 'MyError' ) ;
229201 expect ( sfCommandUxStubs . styledHeader . calledOnce ) . to . be . false ;
230202 expect ( sfCommandUxStubs . table . calledOnce ) . to . be . false ;
231- // expect(configSetStub.callCount).to.be.equal(0);
232- const stateAggregator = await StateAggregator . getInstance ( ) ;
233- expect ( stateAggregator . aliases . getAll ( ) ) . to . deep . equal ( { } ) ;
203+ expect ( setAliasStub . callCount ) . to . equal ( 0 ) ;
234204
235205 expect ( onStub . firstCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_ASYNC_RESULT ) ;
236206 expect ( onStub . secondCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_STATUS ) ;
@@ -240,7 +210,6 @@ describe('org:clone', () => {
240210 // license type is not set in sandbox cloning
241211 SandboxName : sandboxName ,
242212 } ) ;
243- // expect(configWriteStub.calledOnce).to.be.false;
244213 }
245214 } ) ;
246215} ) ;
0 commit comments