@@ -87,6 +87,15 @@ describe('Common Helper', () => {
8787
8888 describe ( 'initialization()' , ( ) => {
8989 it ( 'should initialize config successfully when validation passes' , ( ) => {
90+ // Stub configHandler.get to make isAuthenticated() return true
91+ const configHandler = require ( '@contentstack/cli-utilities' ) . configHandler ;
92+ sandbox . stub ( configHandler , 'get' ) . callsFake ( ( key ) => {
93+ if ( key === 'authorisationType' ) {
94+ return 'OAUTH' ; // This will make isAuthenticated() return true
95+ }
96+ return undefined ;
97+ } ) ;
98+
9099 const configData : ImportConfig = {
91100 apiKey : 'test-api-key' ,
92101 target_stack : 'test-api-key' ,
@@ -108,11 +117,9 @@ describe('Common Helper', () => {
108117 } ) ;
109118
110119 it ( 'should return undefined when validation fails - covers line 30' , ( ) => {
111- const configData : ImportConfig = {
120+ const configData : any = {
112121 email : 'test@example.com' ,
113122 password : 'password' ,
114- // Don't set target_stack - this should trigger validation error (line 42-45)
115- // buildAppConfig will merge with defaultConfig, but undefined won't override anything
116123 data : '/test/data' ,
117124 contentVersion : 1 ,
118125 masterLocale : { code : 'en-us' } ,
@@ -122,12 +129,22 @@ describe('Common Helper', () => {
122129 host : 'https://api.contentstack.io' ,
123130 'exclude-global-modules' : false ,
124131 context : { command : 'cm:stacks:import' } ,
125- } as any as ImportConfig ;
132+ } ;
126133
127- const result = initialization ( configData ) ;
134+ // Stub buildAppConfig on the module so initialization uses the stubbed version
135+ const commonHelperModule = require ( '../../../src/utils/common-helper' ) ;
136+ const originalBuildAppConfig = commonHelperModule . buildAppConfig ;
137+ sandbox . stub ( commonHelperModule , 'buildAppConfig' ) . callsFake ( ( config : ImportConfig ) => {
138+ const merged = originalBuildAppConfig ( config ) ;
139+ // Delete target_stack to ensure validation fails (email/password without target_stack)
140+ delete merged . target_stack ;
141+ return merged ;
142+ } ) ;
143+
144+ const result = initialization ( configData as ImportConfig ) ;
128145
129- // When validation fails (returns 'error'), the condition on line 26 is false,
130- // so it falls through to line 30 which implicitly returns undefined
146+ // When validation fails (returns 'error'), the condition on line 23 is false,
147+ // so it falls through and implicitly returns undefined
131148 expect ( result ) . to . be . undefined ;
132149 } ) ;
133150 } ) ;
0 commit comments