1+ import { test , expect } from "@oclif/test" ;
2+ import { cliux , configHandler , ux } from "@contentstack/cli-utilities" ;
3+ import * as mock from "../../mock/common.mock.json"
4+
5+ import config from "../../../../src/config" ;
6+ import messages , { $t } from "../../../../src/messages" ;
7+
8+ const region : { cma : string ; name : string ; cda : string } =
9+ configHandler . get ( "region" ) ;
10+ const developerHubBaseUrl = ( config . developerHubUrls as Record < string , any > ) [
11+ region . cma
12+ ] ;
13+
14+ describe ( "app:delete" , ( ) => {
15+ describe ( "app:delete with --org and --app-uid flags" , ( ) => {
16+ test
17+ . stdout ( { print : process . env . PRINT === "true" || false } )
18+ . stub ( ux . action , "stop" , ( ) => { } )
19+ . stub ( ux . action , "start" , ( ) => { } )
20+ . nock ( region . cma , ( api ) =>
21+ api
22+ . get ( "/v3/organizations?limit=100&asc=name&include_count=true&skip=0" )
23+ . reply ( 200 , { organizations : mock . organizations } )
24+ )
25+ . nock ( `https://${ developerHubBaseUrl } ` , ( api ) =>
26+ api
27+ . get ( "/manifests/app-uid-1/installations" )
28+ . reply ( 200 , {
29+ data : mock . installations ,
30+ } )
31+ )
32+ . command ( [
33+ "app:delete" , "--org" , mock . organizations [ 0 ] . uid , "--app-uid" , mock . apps [ 0 ] . uid
34+ ] )
35+ . do ( ( { stdout } ) => {
36+ expect ( stdout ) . to . contain ( messages . APP_IS_INSTALLED )
37+ } )
38+ . it ( "should print an error saying that app is already installed" )
39+ } ) ;
40+ describe ( "app:delete using inquirer prompts" , ( ) => {
41+ test
42+ . stdout ( { print : process . env . PRINT === "true" || false } )
43+ . stub ( ux . action , "stop" , ( ) => { } )
44+ . stub ( ux . action , "start" , ( ) => { } )
45+ . stub ( cliux , "inquire" , async ( ...args : any ) => {
46+ const [ prompt ] : any = args ;
47+ const cases = {
48+ Organization : 'test org 1' ,
49+ App : 'App 1'
50+ }
51+ return ( cases as Record < string , any > ) [ prompt . name ] ;
52+ } )
53+ . nock ( region . cma , ( api ) =>
54+ api
55+ . get ( "/v3/organizations?limit=100&asc=name&include_count=true&skip=0" )
56+ . reply ( 200 , { organizations : mock . organizations } )
57+ )
58+ . nock ( `https://${ developerHubBaseUrl } ` , ( api ) =>
59+ api
60+ . get ( "/manifests?limit=50&asc=name&include_count=true&skip=0" )
61+ . reply ( 200 , {
62+ data : mock . apps ,
63+ } )
64+ )
65+ . nock ( `https://${ developerHubBaseUrl } ` , ( api ) =>
66+ api
67+ . get ( "/manifests/app-uid-1/installations" )
68+ . reply ( 200 , {
69+ data : [ ] ,
70+ } )
71+ )
72+ . nock ( `https://${ developerHubBaseUrl } ` , ( api ) =>
73+ api
74+ . delete ( "/manifests/app-uid-1" )
75+ . reply ( 200 , {
76+ data : { } ,
77+ } )
78+ )
79+ . command ( [
80+ "app:delete"
81+ ] )
82+ . do ( ( { stdout } ) => {
83+ expect ( stdout ) . to . contain ( $t ( messages . APP_DELETED_SUCCESSFULLY , { app : mock . apps [ 0 ] . name } ) )
84+ } )
85+ . it ( "should delete the app" )
86+ } ) ;
87+ describe ( "app:delete error handling" , ( ) => {
88+ test
89+ . stdout ( { print : process . env . PRINT === "true" || false } )
90+ . stub ( ux . action , "stop" , ( ) => { } )
91+ . stub ( ux . action , "start" , ( ) => { } )
92+ . stub ( cliux , "inquire" , async ( ...args : any ) => {
93+ const [ prompt ] : any = args ;
94+ const cases = {
95+ Organization : 'test org 1' ,
96+ App : 'App 1'
97+ }
98+ return ( cases as Record < string , any > ) [ prompt . name ] ;
99+ } )
100+ . nock ( region . cma , ( api ) =>
101+ api
102+ . get ( "/v3/organizations?limit=100&asc=name&include_count=true&skip=0" )
103+ . reply ( 200 , { organizations : mock . organizations } )
104+ )
105+ . nock ( `https://${ developerHubBaseUrl } ` , ( api ) =>
106+ api
107+ . get ( "/manifests?limit=50&asc=name&include_count=true&skip=0" )
108+ . reply ( 200 , {
109+ data : mock . apps ,
110+ } )
111+ )
112+ . nock ( `https://${ developerHubBaseUrl } ` , ( api ) =>
113+ api
114+ . get ( "/manifests/app-uid-1/installations" )
115+ . replyWithError ( {
116+ "status" : 409 ,
117+ "message" : [
118+ "(1) installations found for this app"
119+ ] ,
120+ "error" : "Bad Request" ,
121+ "statusText" : "Conflict"
122+ } )
123+ )
124+ . command ( [
125+ "app:delete"
126+ ] )
127+ . do ( ( { stdout } ) => {
128+ expect ( stdout ) . to . contain ( messages . CONTACT_SUPPORT )
129+ } )
130+ . it ( "should throw an error while deleting the app" )
131+ } ) ;
132+ } )
0 commit comments