55 */
66
77import { expect } from 'chai' ;
8+ import sinon from 'sinon' ;
89
910import OdsStart from '../../../src/commands/ods/start.js' ;
1011
@@ -66,6 +67,15 @@ describe('ods operations', () => {
6667 expect ( OdsStart . enableJsonFlag ) . to . be . true ;
6768 } ) ;
6869
70+ it ( 'should expose wait/polling flags' , ( ) => {
71+ expect ( OdsStart . flags ) . to . have . property ( 'wait' ) ;
72+ expect ( OdsStart . flags . wait . char ) . to . equal ( 'w' ) ;
73+ expect ( OdsStart . flags ) . to . have . property ( 'poll-interval' ) ;
74+ expect ( OdsStart . flags [ 'poll-interval' ] . dependsOn ) . to . deep . equal ( [ 'wait' ] ) ;
75+ expect ( OdsStart . flags ) . to . have . property ( 'timeout' ) ;
76+ expect ( OdsStart . flags . timeout . dependsOn ) . to . deep . equal ( [ 'wait' ] ) ;
77+ } ) ;
78+
6979 it ( 'should return operation data in JSON mode' , async ( ) => {
7080 const command = new OdsStart ( [ ] , { } as any ) ;
7181
@@ -178,6 +188,40 @@ describe('ods operations', () => {
178188 expect ( error . message ) . to . include ( 'Bad request' ) ;
179189 }
180190 } ) ;
191+
192+ it ( 'should poll sandbox state when --wait is true' , async ( ) => {
193+ const command = new OdsStart ( [ ] , { } as any ) ;
194+
195+ Object . defineProperty ( command , 'args' , {
196+ value : { sandboxId : 'sandbox-123' } ,
197+ configurable : true ,
198+ } ) ;
199+
200+ Object . defineProperty ( command , 'flags' , {
201+ value : { wait : true , 'poll-interval' : 0 , timeout : 1 } ,
202+ configurable : true ,
203+ } ) ;
204+
205+ stubCommandConfigAndLogger ( command ) ;
206+ stubJsonEnabled ( command , true ) ;
207+
208+ const getSpy = sinon . spy ( async ( ) => ( {
209+ data : { data : { state : 'started' } } ,
210+ response : new Response ( ) ,
211+ } ) ) ;
212+
213+ stubOdsClient ( command , {
214+ POST : async ( ) => ( {
215+ data : { data : { operation : 'start' , operationState : 'running' } } ,
216+ response : new Response ( ) ,
217+ } ) ,
218+ GET : getSpy ,
219+ } ) ;
220+
221+ await command . run ( ) ;
222+
223+ expect ( getSpy . called , 'Expected GET to be called when --wait is true' ) . to . equal ( true ) ;
224+ } ) ;
181225 } ) ;
182226
183227 describe ( 'ods stop' , ( ) => {
@@ -195,6 +239,15 @@ describe('ods operations', () => {
195239 expect ( OdsStop . enableJsonFlag ) . to . be . true ;
196240 } ) ;
197241
242+ it ( 'should expose wait/polling flags' , ( ) => {
243+ expect ( OdsStop . flags ) . to . have . property ( 'wait' ) ;
244+ expect ( OdsStop . flags . wait . char ) . to . equal ( 'w' ) ;
245+ expect ( OdsStop . flags ) . to . have . property ( 'poll-interval' ) ;
246+ expect ( OdsStop . flags [ 'poll-interval' ] . dependsOn ) . to . deep . equal ( [ 'wait' ] ) ;
247+ expect ( OdsStop . flags ) . to . have . property ( 'timeout' ) ;
248+ expect ( OdsStop . flags . timeout . dependsOn ) . to . deep . equal ( [ 'wait' ] ) ;
249+ } ) ;
250+
198251 it ( 'should return operation data in JSON mode' , async ( ) => {
199252 const command = new OdsStop ( [ ] , { } as any ) ;
200253
@@ -307,6 +360,40 @@ describe('ods operations', () => {
307360 expect ( error . message ) . to . include ( 'Bad request' ) ;
308361 }
309362 } ) ;
363+
364+ it ( 'should poll sandbox state when --wait is true' , async ( ) => {
365+ const command = new OdsStop ( [ ] , { } as any ) ;
366+
367+ Object . defineProperty ( command , 'args' , {
368+ value : { sandboxId : 'sandbox-123' } ,
369+ configurable : true ,
370+ } ) ;
371+
372+ Object . defineProperty ( command , 'flags' , {
373+ value : { wait : true , 'poll-interval' : 0 , timeout : 1 } ,
374+ configurable : true ,
375+ } ) ;
376+
377+ stubCommandConfigAndLogger ( command ) ;
378+ stubJsonEnabled ( command , true ) ;
379+
380+ const getSpy = sinon . spy ( async ( ) => ( {
381+ data : { data : { state : 'stopped' } } ,
382+ response : new Response ( ) ,
383+ } ) ) ;
384+
385+ stubOdsClient ( command , {
386+ POST : async ( ) => ( {
387+ data : { data : { operation : 'stop' , operationState : 'running' } } ,
388+ response : new Response ( ) ,
389+ } ) ,
390+ GET : getSpy ,
391+ } ) ;
392+
393+ await command . run ( ) ;
394+
395+ expect ( getSpy . called , 'Expected GET to be called when --wait is true' ) . to . equal ( true ) ;
396+ } ) ;
310397 } ) ;
311398
312399 describe ( 'ods restart' , ( ) => {
@@ -324,6 +411,15 @@ describe('ods operations', () => {
324411 expect ( OdsRestart . enableJsonFlag ) . to . be . true ;
325412 } ) ;
326413
414+ it ( 'should expose wait/polling flags' , ( ) => {
415+ expect ( OdsRestart . flags ) . to . have . property ( 'wait' ) ;
416+ expect ( OdsRestart . flags . wait . char ) . to . equal ( 'w' ) ;
417+ expect ( OdsRestart . flags ) . to . have . property ( 'poll-interval' ) ;
418+ expect ( OdsRestart . flags [ 'poll-interval' ] . dependsOn ) . to . deep . equal ( [ 'wait' ] ) ;
419+ expect ( OdsRestart . flags ) . to . have . property ( 'timeout' ) ;
420+ expect ( OdsRestart . flags . timeout . dependsOn ) . to . deep . equal ( [ 'wait' ] ) ;
421+ } ) ;
422+
327423 it ( 'should return operation data in JSON mode' , async ( ) => {
328424 const command = new OdsRestart ( [ ] , { } as any ) ;
329425
@@ -436,5 +532,39 @@ describe('ods operations', () => {
436532 expect ( error . message ) . to . include ( 'Bad request' ) ;
437533 }
438534 } ) ;
535+
536+ it ( 'should poll sandbox state when --wait is true' , async ( ) => {
537+ const command = new OdsRestart ( [ ] , { } as any ) ;
538+
539+ Object . defineProperty ( command , 'args' , {
540+ value : { sandboxId : 'sandbox-123' } ,
541+ configurable : true ,
542+ } ) ;
543+
544+ Object . defineProperty ( command , 'flags' , {
545+ value : { wait : true , 'poll-interval' : 0 , timeout : 1 } ,
546+ configurable : true ,
547+ } ) ;
548+
549+ stubCommandConfigAndLogger ( command ) ;
550+ stubJsonEnabled ( command , true ) ;
551+
552+ const getSpy = sinon . spy ( async ( ) => ( {
553+ data : { data : { state : 'started' } } ,
554+ response : new Response ( ) ,
555+ } ) ) ;
556+
557+ stubOdsClient ( command , {
558+ POST : async ( ) => ( {
559+ data : { data : { operation : 'restart' , operationState : 'running' } } ,
560+ response : new Response ( ) ,
561+ } ) ,
562+ GET : getSpy ,
563+ } ) ;
564+
565+ await command . run ( ) ;
566+
567+ expect ( getSpy . called , 'Expected GET to be called when --wait is true' ) . to . equal ( true ) ;
568+ } ) ;
439569 } ) ;
440570} ) ;
0 commit comments