@@ -113,6 +113,52 @@ describe('code deploy', () => {
113113 expect ( result . reloaded ) . to . equal ( false ) ;
114114 } ) ;
115115
116+ it ( 'errors when no code version and no OAuth credentials' , async ( ) => {
117+ const command : any = await createCommand ( { } , { cartridgePath : '.' } ) ;
118+
119+ sinon . stub ( command , 'requireWebDavCredentials' ) . returns ( void 0 ) ;
120+ sinon . stub ( command , 'hasOAuthCredentials' ) . returns ( false ) ;
121+ sinon . stub ( command , 'log' ) . returns ( void 0 ) ;
122+ sinon . stub ( command , 'warn' ) . returns ( void 0 ) ;
123+ sinon . stub ( command , 'resolvedConfig' ) . get ( ( ) => ( { values : { hostname : 'example.com' , codeVersion : undefined } } ) ) ;
124+
125+ const errorStub = sinon . stub ( command , 'error' ) . throws ( new Error ( 'OAuth required' ) ) ;
126+
127+ try {
128+ await command . run ( ) ;
129+ expect . fail ( 'Should have thrown' ) ;
130+ } catch {
131+ // expected
132+ }
133+
134+ expect ( errorStub . calledOnce ) . to . equal ( true ) ;
135+ const errorMessage = errorStub . firstCall . args [ 0 ] ;
136+ expect ( errorMessage ) . to . include ( 'auto-discover' ) ;
137+ } ) ;
138+
139+ it ( 'errors when --reload flag set but no OAuth credentials' , async ( ) => {
140+ const command : any = await createCommand ( { reload : true } , { cartridgePath : '.' } ) ;
141+
142+ sinon . stub ( command , 'requireWebDavCredentials' ) . returns ( void 0 ) ;
143+ sinon . stub ( command , 'hasOAuthCredentials' ) . returns ( false ) ;
144+ sinon . stub ( command , 'log' ) . returns ( void 0 ) ;
145+ sinon . stub ( command , 'warn' ) . returns ( void 0 ) ;
146+ sinon . stub ( command , 'resolvedConfig' ) . get ( ( ) => ( { values : { hostname : 'example.com' , codeVersion : 'v1' } } ) ) ;
147+
148+ const errorStub = sinon . stub ( command , 'error' ) . throws ( new Error ( 'OAuth required' ) ) ;
149+
150+ try {
151+ await command . run ( ) ;
152+ expect . fail ( 'Should have thrown' ) ;
153+ } catch {
154+ // expected
155+ }
156+
157+ expect ( errorStub . calledOnce ) . to . equal ( true ) ;
158+ const errorMessage = errorStub . firstCall . args [ 0 ] ;
159+ expect ( errorMessage ) . to . include ( 'reload' ) ;
160+ } ) ;
161+
116162 it ( 'uses active code version when resolvedConfig is missing codeVersion' , async ( ) => {
117163 const command : any = await createCommand ( { } , { cartridgePath : '.' } ) ;
118164
0 commit comments