@@ -83,11 +83,14 @@ describe('org:clone', () => {
8383 }
8484 }
8585
86- const runCloneCommand = async ( params : string [ ] ) => {
86+ const runCloneCommand = async ( params : string [ ] , fails ?: boolean ) => {
8787 cmd = new TestOrgCloneCommand ( params , oclifConfigStub ) ;
8888 stubMethod ( sandbox , cmd , 'assignOrg' ) . callsFake ( ( ) => {
8989 cloneSandboxStub = sandbox . stub ( ) . callsFake ( async ( ) => {
90- return sandboxProcessObj ;
90+ if ( ! fails ) {
91+ return sandboxProcessObj ;
92+ }
93+ throw new Error ( 'MyError' ) ;
9194 } ) ;
9295 const orgStubOptions = {
9396 cloneSandbox : cloneSandboxStub ,
@@ -105,11 +108,15 @@ describe('org:clone', () => {
105108 configAggregatorStub = fromStub ( stubInterface < ConfigAggregator > ( sandbox , configAggregatorStubOptions ) ) ;
106109 cmd . setConfigAggregator ( configAggregatorStub ) ;
107110 } ) ;
108- onStub = sandbox
109- . stub ( )
110- . callsArgWith ( 1 , sandboxProcessObj )
111- . callsArgWith ( 1 , statusEvent )
112- . callsArgWith ( 1 , resultObject ) ;
111+ if ( ! fails ) {
112+ onStub = sandbox
113+ . stub ( )
114+ . callsArgWith ( 1 , sandboxProcessObj )
115+ . callsArgWith ( 1 , statusEvent )
116+ . callsArgWith ( 1 , resultObject ) ;
117+ } else {
118+ onStub = sandbox . stub ( ) . resolves ( true ) ;
119+ }
113120 stubMethod ( sandbox , Lifecycle , 'getInstance' ) . returns ( {
114121 on : onStub ,
115122 } ) ;
@@ -203,6 +210,32 @@ describe('org:clone', () => {
203210 expect ( res ) . to . deep . equal ( sandboxProcessObj ) ;
204211 } ) ;
205212
213+ it ( 'cloneSandbox fails and wont set alias or default username' , async ( ) => {
214+ try {
215+ await runCloneCommand (
216+ [ '-t' , 'sandbox' , '-u' , 'DevHub' , '-f' , 'sandbox-def.json' , '-a' , sandboxalias , '-s' ] ,
217+ true
218+ ) ;
219+ sinon . assert . fail ( 'the above should throw an error' ) ;
220+ } catch ( e ) {
221+ expect ( uxStyledHeaderStub . calledOnce ) . to . be . false ;
222+ expect ( uxTableStub . calledOnce ) . to . be . false ;
223+ expect ( readFileSyncStub . calledOnce ) . to . be . true ;
224+ expect ( uxLogStub . callCount ) . to . be . equal ( 0 ) ;
225+ expect ( aliasSetStub . callCount ) . to . be . equal ( 0 ) ;
226+ expect ( configSetStub . callCount ) . to . be . equal ( 0 ) ;
227+ expect ( onStub . firstCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_ASYNC_RESULT ) ;
228+ expect ( onStub . secondCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_STATUS ) ;
229+ expect ( onStub . thirdCall . firstArg ) . to . be . equal ( SandboxEvents . EVENT_RESULT ) ;
230+ expect ( onStub . callCount ) . to . be . equal ( 3 ) ;
231+ expect ( cloneSandboxStub . firstCall . firstArg ) . to . deep . equal ( {
232+ LicenseType : 'Developer' ,
233+ SandboxName : 'newSandbox' ,
234+ } ) ;
235+ expect ( configWriteStub . calledOnce ) . to . be . false ;
236+ }
237+ } ) ;
238+
206239 afterEach ( ( ) => {
207240 sandbox . restore ( ) ;
208241 } ) ;
0 commit comments