@@ -42,7 +42,7 @@ describe('code deploy', () => {
4242
4343 const result = await command . run ( ) ;
4444
45- expect ( result ) . to . deep . equal ( { cartridges : [ ] , codeVersion : 'v1' , reloaded : false } ) ;
45+ expect ( result ) . to . deep . equal ( { cartridges : [ ] , codeVersion : 'v1' , activated : false , reloaded : false } ) ;
4646 } ) ;
4747
4848 it ( 'errors when no cartridges are found' , async ( ) => {
@@ -90,11 +90,60 @@ describe('code deploy', () => {
9090 expect ( uploadStub . calledOnceWithExactly ( instance , cartridges ) ) . to . equal ( true ) ;
9191 expect ( reloadStub . calledOnceWithExactly ( instance , 'v1' ) ) . to . equal ( true ) ;
9292
93- expect ( result ) . to . deep . include ( { codeVersion : 'v1' , reloaded : true } ) ;
93+ expect ( result ) . to . deep . include ( { codeVersion : 'v1' , activated : true , reloaded : true } ) ;
9494 expect ( afterHooksStub . calledOnce ) . to . equal ( true ) ;
9595 } ) ;
9696
97- it ( 'swallows reload errors and still succeeds' , async ( ) => {
97+ it ( 'calls activate after deploy when --activate is set' , async ( ) => {
98+ const command : any = await createCommand ( { activate : true } , { cartridgePath : '.' } ) ;
99+ const instance = stubCommon ( command ) ;
100+
101+ sinon . stub ( command , 'runBeforeHooks' ) . resolves ( { skip : false } ) ;
102+ sinon . stub ( command , 'runAfterHooks' ) . resolves ( void 0 ) ;
103+
104+ const cartridges = [ { name : 'c1' , src : '/tmp/c1' , dest : 'c1' } ] ;
105+ sinon . stub ( command , 'findCartridgesWithProviders' ) . resolves ( cartridges ) ;
106+
107+ const uploadStub = sinon . stub ( ) . resolves ( void 0 ) ;
108+ const activateStub = sinon . stub ( ) . resolves ( void 0 ) ;
109+ command . operations = { ...command . operations , uploadCartridges : uploadStub , activateCodeVersion : activateStub } ;
110+
111+ const result = await command . run ( ) ;
112+
113+ expect ( activateStub . calledOnceWithExactly ( instance , 'v1' ) ) . to . equal ( true ) ;
114+ expect ( result ) . to . deep . include ( { codeVersion : 'v1' , activated : true , reloaded : false } ) ;
115+ } ) ;
116+
117+ it ( 'errors when activate fails' , async ( ) => {
118+ const command : any = await createCommand ( { activate : true } , { cartridgePath : '.' } ) ;
119+ stubCommon ( command ) ;
120+
121+ sinon . stub ( command , 'runBeforeHooks' ) . resolves ( { skip : false } ) ;
122+ sinon . stub ( command , 'runAfterHooks' ) . resolves ( void 0 ) ;
123+
124+ const cartridges = [ { name : 'c1' , src : '/tmp/c1' , dest : 'c1' } ] ;
125+ sinon . stub ( command , 'findCartridgesWithProviders' ) . resolves ( cartridges ) ;
126+
127+ const uploadStub = sinon . stub ( ) . resolves ( void 0 ) ;
128+ const activateStub = sinon . stub ( ) . rejects ( new Error ( 'activate failed' ) ) ;
129+ command . operations = { ...command . operations , uploadCartridges : uploadStub , activateCodeVersion : activateStub } ;
130+
131+ const errorStub = sinon . stub ( command , 'error' ) . throws ( new Error ( 'Expected error' ) ) ;
132+
133+ try {
134+ await command . run ( ) ;
135+ expect . fail ( 'Should have thrown' ) ;
136+ } catch {
137+ // expected
138+ }
139+
140+ expect ( errorStub . called ) . to . equal ( true ) ;
141+ const errorMessage = errorStub . firstCall . args [ 0 ] ;
142+ expect ( errorMessage ) . to . include ( 'activate failed' ) ;
143+ expect ( errorMessage ) . to . include ( 'OCAPI' ) ;
144+ } ) ;
145+
146+ it ( 'errors when reload fails' , async ( ) => {
98147 const command : any = await createCommand ( { reload : true } , { cartridgePath : '.' } ) ;
99148 stubCommon ( command ) ;
100149
@@ -108,9 +157,19 @@ describe('code deploy', () => {
108157 const reloadStub = sinon . stub ( ) . rejects ( new Error ( 'reload failed' ) ) ;
109158 command . operations = { ...command . operations , uploadCartridges : uploadStub , reloadCodeVersion : reloadStub } ;
110159
111- const result = await command . run ( ) ;
160+ const errorStub = sinon . stub ( command , 'error' ) . throws ( new Error ( 'Expected error' ) ) ;
112161
113- expect ( result . reloaded ) . to . equal ( false ) ;
162+ try {
163+ await command . run ( ) ;
164+ expect . fail ( 'Should have thrown' ) ;
165+ } catch {
166+ // expected
167+ }
168+
169+ expect ( errorStub . called ) . to . equal ( true ) ;
170+ const errorMessage = errorStub . firstCall . args [ 0 ] ;
171+ expect ( errorMessage ) . to . include ( 'reload failed' ) ;
172+ expect ( errorMessage ) . to . include ( 'OCAPI' ) ;
114173 } ) ;
115174
116175 it ( 'errors when no code version and no OAuth credentials' , async ( ) => {
@@ -156,7 +215,30 @@ describe('code deploy', () => {
156215
157216 expect ( errorStub . calledOnce ) . to . equal ( true ) ;
158217 const errorMessage = errorStub . firstCall . args [ 0 ] ;
159- expect ( errorMessage ) . to . include ( 'reload' ) ;
218+ expect ( errorMessage ) . to . include ( 'activate' ) ;
219+ } ) ;
220+
221+ it ( 'errors when --activate flag set but no OAuth credentials' , async ( ) => {
222+ const command : any = await createCommand ( { activate : true } , { cartridgePath : '.' } ) ;
223+
224+ sinon . stub ( command , 'requireWebDavCredentials' ) . returns ( void 0 ) ;
225+ sinon . stub ( command , 'hasOAuthCredentials' ) . returns ( false ) ;
226+ sinon . stub ( command , 'log' ) . returns ( void 0 ) ;
227+ sinon . stub ( command , 'warn' ) . returns ( void 0 ) ;
228+ sinon . stub ( command , 'resolvedConfig' ) . get ( ( ) => ( { values : { hostname : 'example.com' , codeVersion : 'v1' } } ) ) ;
229+
230+ const errorStub = sinon . stub ( command , 'error' ) . throws ( new Error ( 'OAuth required' ) ) ;
231+
232+ try {
233+ await command . run ( ) ;
234+ expect . fail ( 'Should have thrown' ) ;
235+ } catch {
236+ // expected
237+ }
238+
239+ expect ( errorStub . calledOnce ) . to . equal ( true ) ;
240+ const errorMessage = errorStub . firstCall . args [ 0 ] ;
241+ expect ( errorMessage ) . to . include ( 'activate' ) ;
160242 } ) ;
161243
162244 it ( 'uses active code version when resolvedConfig is missing codeVersion' , async ( ) => {
0 commit comments