@@ -4,40 +4,15 @@ import { runCommand } from "@oclif/test";
44import { cliux , configHandler } from "@contentstack/cli-utilities" ;
55import messages , { $t } from "../../../../src/messages" ;
66const mock = ( global as any ) . commonMock ;
7- import { getDeveloperHubUrl } from "../../../../src/util/inquirer" ;
87import sinon from "sinon" ;
98import { stubAuthentication } from "../../helpers/auth-stub-helper" ;
109import Deploy from "../../../../src/commands/app/deploy" ;
1110import { BaseCommand } from "../../../../src/base-command" ;
12- import { join } from "path" ;
13-
14- const region = configHandler . get ( "region" ) ;
15- // Commands run from lib/ (oclif.commands); stub the same classes/modules the running command uses
16- let BaseCommandToStub : typeof BaseCommand ;
17- let LibDeploy : typeof Deploy ;
18- let libCommonUtils : any ;
19- let libInquirer : any ;
20- try {
21- BaseCommandToStub = require ( join ( process . cwd ( ) , "lib" , "base-command" ) ) . BaseCommand ;
22- } catch {
23- BaseCommandToStub = BaseCommand ;
24- }
25- try {
26- LibDeploy = require ( join ( process . cwd ( ) , "lib" , "commands" , "app" , "deploy" ) ) . default ;
27- } catch {
28- LibDeploy = Deploy ;
29- }
30- try {
31- libCommonUtils = require ( join ( process . cwd ( ) , "lib" , "util" , "common-utils" ) ) ;
32- } catch {
33- libCommonUtils = require ( "../../../../src/util/common-utils" ) ;
34- }
35- try {
36- libInquirer = require ( join ( process . cwd ( ) , "lib" , "util" , "inquirer" ) ) ;
37- } catch {
38- libInquirer = require ( "../../../../src/util/inquirer" ) ;
39- }
40- const developerHubBaseUrl = getDeveloperHubUrl ( ) ;
11+ import * as libCommonUtils from "../../../../src/util/common-utils" ;
12+ import * as libInquirer from "../../../../src/util/inquirer" ;
13+
14+ let region ! : { cma : string ; name : string ; cda : string } ;
15+ let developerHubBaseUrl ! : string ;
4116
4217describe ( "app:deploy" , ( ) => {
4318 let sandbox : sinon . SinonSandbox ;
@@ -52,6 +27,8 @@ describe("app:deploy", () => {
5227
5328 // Stub authentication using shared helper
5429 stubAuthentication ( sandbox ) ;
30+ region = configHandler . get ( "region" ) ;
31+ developerHubBaseUrl = libInquirer . getDeveloperHubUrl ( ) ;
5532
5633 sandbox . stub ( cliux , "loader" ) . callsFake ( ( ) => { } ) ;
5734 sandbox . stub ( cliux , "inquire" ) . callsFake ( ( prompt : any ) => {
@@ -64,7 +41,7 @@ describe("app:deploy", () => {
6441 return Promise . resolve ( cases [ prompt . name ] ) ;
6542 } ) ;
6643
67- // Stub utilities used by the running command (lib /util); stub same module it requires
44+ // Stub utilities used by the running command (src /util); same module instances oclif loads via tsPath
6845 sandbox . stub ( libCommonUtils , "getProjects" ) . resolves ( [ ] ) ;
6946 sandbox . stub ( libCommonUtils , "updateApp" ) . resolves ( ) ;
7047 sandbox . stub ( libCommonUtils , "disconnectApp" ) . resolves ( ) ;
@@ -76,14 +53,14 @@ describe("app:deploy", () => {
7653 sandbox . stub ( libInquirer , "getAppUrl" ) . resolves ( "https://example.com" ) ;
7754 sandbox . stub ( libInquirer , "askProjectType" ) . resolves ( "existing" ) ;
7855 sandbox . stub ( libInquirer , "askConfirmation" ) . resolves ( false ) ;
79- sandbox . stub ( libInquirer , "selectProject" ) . resolves ( null ) ;
56+ sandbox . stub ( libInquirer , "selectProject" ) . resolves ( undefined ) ;
8057 sandbox . stub ( libInquirer , "askProjectName" ) . resolves ( "test-project" ) ;
8158
8259 // Stub Launch.run
8360 sandbox . stub ( require ( "@contentstack/cli-launch" ) . Launch , "run" ) . resolves ( ) ;
8461
85- // Stub getApolloClient on the class that actually runs (lib Deploy) so no real GraphQL runs
86- sandbox . stub ( LibDeploy . prototype , "getApolloClient" ) . resolves ( {
62+ // Stub getApolloClient so no real GraphQL runs
63+ sandbox . stub ( Deploy . prototype , "getApolloClient" ) . resolves ( {
8764 query : ( ) =>
8865 Promise . resolve ( {
8966 data : {
@@ -94,7 +71,7 @@ describe("app:deploy", () => {
9471 } ) ,
9572 } as any ) ;
9673
97- // Stub SDK init so no real HTTP is made (cli-utilities exports use getters so we can't stub those).
74+ // Stub SDK init so no real HTTP is made
9875 const mockManagementSdk = {
9976 organization : ( ) => ( {
10077 fetchAll : ( ) =>
@@ -116,15 +93,15 @@ describe("app:deploy", () => {
11693 } ) ,
11794 } ) ,
11895 } ;
119- sandbox . stub ( BaseCommandToStub . prototype , "initCmaSDK" ) . callsFake ( async function ( this : any ) {
96+ sandbox . stub ( BaseCommand . prototype , "initCmaSDK" ) . callsFake ( async function ( this : any ) {
12097 this . managementSdk = mockManagementSdk ;
12198 this . managementAppSdk = mockManagementSdk ;
12299 } ) ;
123- sandbox . stub ( BaseCommandToStub . prototype , "initMarketplaceSDK" ) . callsFake ( async function ( this : any ) {
100+ sandbox . stub ( BaseCommand . prototype , "initMarketplaceSDK" ) . callsFake ( async function ( this : any ) {
124101 this . marketplaceAppSdk = mockMarketplaceSdk ;
125102 } ) ;
126103
127- // Nock CMA and developer hub (SDK may use :443 or different param order)
104+ // Nock CMA and developer hub
128105 const cmaOrigin = region . cma . replace ( / \/ $ / , "" ) ;
129106 const orgReply = {
130107 organizations : mock . organizations ,
@@ -213,7 +190,7 @@ describe("app:deploy", () => {
213190 sandbox . stub ( process , "exit" ) . callsFake ( ( ( code ?: number ) => {
214191 throw new Error ( `process.exit(${ code } )` ) ;
215192 } ) as any ) ;
216- sandbox . stub ( LibDeploy . prototype , "getApolloClient" ) . resolves ( {
193+ sandbox . stub ( Deploy . prototype , "getApolloClient" ) . resolves ( {
217194 query : ( ) =>
218195 Promise . resolve ( {
219196 data : { projects : { edges : [ ] } } ,
@@ -240,11 +217,11 @@ describe("app:deploy", () => {
240217 } ) ,
241218 } ) ,
242219 } ;
243- sandbox . stub ( BaseCommandToStub . prototype , "initCmaSDK" ) . callsFake ( async function ( this : any ) {
220+ sandbox . stub ( BaseCommand . prototype , "initCmaSDK" ) . callsFake ( async function ( this : any ) {
244221 this . managementSdk = mockMgmt ;
245222 this . managementAppSdk = mockMgmt ;
246223 } ) ;
247- sandbox . stub ( BaseCommandToStub . prototype , "initMarketplaceSDK" ) . callsFake ( async function ( this : any ) {
224+ sandbox . stub ( BaseCommand . prototype , "initMarketplaceSDK" ) . callsFake ( async function ( this : any ) {
248225 this . marketplaceAppSdk = mockMkt ;
249226 } ) ;
250227 stubAuthentication ( sandbox ) ;
@@ -287,7 +264,7 @@ describe("app:deploy", () => {
287264 sandbox . stub ( process , "exit" ) . callsFake ( ( ( code ?: number ) => {
288265 throw new Error ( `process.exit(${ code } )` ) ;
289266 } ) as any ) ;
290- sandbox . stub ( LibDeploy . prototype , "getApolloClient" ) . resolves ( {
267+ sandbox . stub ( Deploy . prototype , "getApolloClient" ) . resolves ( {
291268 query : ( ) =>
292269 Promise . resolve ( {
293270 data : {
@@ -330,11 +307,11 @@ describe("app:deploy", () => {
330307 } ) ,
331308 } ) ,
332309 } ;
333- sandbox . stub ( BaseCommandToStub . prototype , "initCmaSDK" ) . callsFake ( async function ( this : any ) {
310+ sandbox . stub ( BaseCommand . prototype , "initCmaSDK" ) . callsFake ( async function ( this : any ) {
334311 this . managementSdk = mockMgmt ;
335312 this . managementAppSdk = mockMgmt ;
336313 } ) ;
337- sandbox . stub ( BaseCommandToStub . prototype , "initMarketplaceSDK" ) . callsFake ( async function ( this : any ) {
314+ sandbox . stub ( BaseCommand . prototype , "initMarketplaceSDK" ) . callsFake ( async function ( this : any ) {
338315 this . marketplaceAppSdk = mockMkt ;
339316 } ) ;
340317 stubAuthentication ( sandbox ) ;
@@ -355,14 +332,15 @@ describe("app:deploy", () => {
355332 sandbox . stub ( libInquirer , "askProjectType" ) . resolves ( "new" ) ;
356333 sandbox . stub ( libInquirer , "askProjectName" ) . resolves ( "new-project" ) ;
357334 sandbox . stub ( libInquirer , "askConfirmation" ) . resolves ( false ) ;
358- sandbox . stub ( libInquirer , "selectProject" ) . resolves ( null ) ;
335+ sandbox . stub ( libInquirer , "selectProject" ) . resolves ( undefined ) ;
359336
360337 sandbox . stub ( libCommonUtils , "getProjects" ) . resolves ( [
361338 {
362339 name : "new-project" ,
363340 uid : "project-2" ,
364341 url : "https://new-project.com" ,
365342 environmentUid : "env-2" ,
343+ developerHubAppUid : null ,
366344 } ,
367345 ] ) ;
368346 sandbox . stub ( libCommonUtils , "setupConfig" ) . returns ( {
0 commit comments