@@ -149,4 +149,110 @@ describe("app:deploy", () => {
149149 ) ;
150150 } ) ;
151151 } ) ;
152+
153+ describe ( "Deploy app error handling" , ( ) => {
154+ it ( "should fail with invalid hosting type" , async ( ) => {
155+ sandbox . restore ( ) ;
156+ sandbox = sinon . createSandbox ( ) ;
157+ stubAuthentication ( sandbox ) ;
158+
159+ sandbox . stub ( cliux , "loader" ) . callsFake ( ( ) => { } ) ;
160+ sandbox . stub ( cliux , "inquire" ) . callsFake ( ( prompt : any ) => {
161+ const cases : Record < string , any > = {
162+ App : mock . apps [ 1 ] . name ,
163+ Organization : mock . organizations [ 0 ] . name ,
164+ "hosting types" : "invalid-hosting" ,
165+ } ;
166+ return Promise . resolve ( cases [ prompt . name ] ) ;
167+ } ) ;
168+
169+ sandbox
170+ . stub ( require ( "../../../../src/util/common-utils" ) , "getProjects" )
171+ . resolves ( [ ] ) ;
172+ sandbox
173+ . stub ( require ( "../../../../src/util/common-utils" ) , "updateApp" )
174+ . resolves ( ) ;
175+
176+ nock ( region . cma )
177+ . get (
178+ "/v3/organizations?limit=100&asc=name&asc=name&include_count=true&skip=0"
179+ )
180+ . reply ( 200 , { organizations : mock . organizations } ) ;
181+
182+ nock ( `https://${ developerHubBaseUrl } ` )
183+ . get ( "/manifests?limit=50&asc=name&include_count=true&skip=0" )
184+ . reply ( 200 , { data : mock . apps2 } ) ;
185+
186+ const { stdout } = await runCommand ( [ "app:deploy" ] , {
187+ root : process . cwd ( ) ,
188+ } ) ;
189+ expect ( stdout ) . to . contain ( "Please provide a valid Hosting Type." ) ;
190+ } ) ;
191+
192+ it ( "should handle new project creation with hosting-with-launch" , async ( ) => {
193+ sandbox . restore ( ) ;
194+ sandbox = sinon . createSandbox ( ) ;
195+ stubAuthentication ( sandbox ) ;
196+
197+ sandbox . stub ( cliux , "loader" ) . callsFake ( ( ) => { } ) ;
198+ sandbox . stub ( cliux , "inquire" ) . callsFake ( ( prompt : any ) => {
199+ const cases : Record < string , any > = {
200+ App : mock . apps [ 1 ] . name ,
201+ Organization : mock . organizations [ 0 ] . name ,
202+ "hosting types" : "hosting-with-launch" ,
203+ "launch project" : "new" ,
204+ } ;
205+ return Promise . resolve ( cases [ prompt . name ] ) ;
206+ } ) ;
207+
208+ sandbox
209+ . stub ( require ( "../../../../src/util/common-utils" ) , "getProjects" )
210+ . resolves ( [
211+ {
212+ name : "new-project" ,
213+ uid : "project-2" ,
214+ url : "https://new-project.com" ,
215+ environmentUid : "env-2" ,
216+ } ,
217+ ] ) ;
218+ sandbox
219+ . stub ( require ( "../../../../src/util/common-utils" ) , "setupConfig" )
220+ . returns ( {
221+ name : "new-project" ,
222+ type : "react" ,
223+ environment : "production" ,
224+ framework : "nextjs" ,
225+ } ) ;
226+ sandbox
227+ . stub (
228+ require ( "../../../../src/util/common-utils" ) ,
229+ "handleProjectNameConflict"
230+ )
231+ . resolves ( "new-project" ) ;
232+ sandbox
233+ . stub ( require ( "@contentstack/cli-launch" ) . Launch , "run" )
234+ . resolves ( ) ;
235+
236+ nock ( region . cma )
237+ . get (
238+ "/v3/organizations?limit=100&asc=name&asc=name&include_count=true&skip=0"
239+ )
240+ . reply ( 200 , { organizations : mock . organizations } ) ;
241+
242+ nock ( `https://${ developerHubBaseUrl } ` )
243+ . get ( "/manifests?limit=50&asc=name&include_count=true&skip=0" )
244+ . reply ( 200 , { data : mock . apps2 } ) ;
245+
246+ nock ( `https://${ developerHubBaseUrl } ` )
247+ . put ( `/manifests/${ mock . apps2 [ 1 ] . uid } ` )
248+ . reply ( 200 , mock . deploy_launch_host ) ;
249+
250+ const { stdout } = await runCommand ( [ "app:deploy" ] , {
251+ root : process . cwd ( ) ,
252+ } ) ;
253+ expect ( stdout ) . to . contain (
254+ $t ( messages . APP_DEPLOYED , { app : mock . apps [ 1 ] . name } )
255+ ) ;
256+ } ) ;
257+ } ) ;
152258} ) ;
0 commit comments