@@ -101,11 +101,15 @@ describe('ExportMarketplaceApps', () => {
101101 // Stub utility functions
102102 sinon . stub ( FsUtility . prototype , 'writeFile' ) . resolves ( ) ;
103103 sinon . stub ( FsUtility . prototype , 'makeDirectory' ) . resolves ( ) ;
104- // Note: isAuthenticated is non-configurable, so we'll stub it per test when needed using sinon.replace
105104 sinon . stub ( utilities , 'marketplaceSDKClient' ) . resolves ( mockAppSdk ) ;
106105 sinon . stub ( marketplaceAppHelper , 'getOrgUid' ) . resolves ( 'test-org-uid' ) ;
107106 sinon . stub ( marketplaceAppHelper , 'getDeveloperHubUrl' ) . resolves ( 'https://developer-api.contentstack.io' ) ;
108107 sinon . stub ( marketplaceAppHelper , 'createNodeCryptoInstance' ) . resolves ( mockNodeCrypto ) ;
108+ sinon . stub ( marketplaceAppHelper , 'askEncryptionKey' ) . resolves ( 'test-encryption-key' ) ;
109+ sinon . stub ( utils , 'getOrgUid' ) . resolves ( 'test-org-uid' ) ;
110+ sinon . stub ( utils , 'getDeveloperHubUrl' ) . resolves ( 'https://developer-api.contentstack.io' ) ;
111+ sinon . stub ( utils , 'createNodeCryptoInstance' ) . resolves ( mockNodeCrypto ) ;
112+ sinon . stub ( utils , 'askEncryptionKey' ) . resolves ( 'test-encryption-key' ) ;
109113 } ) ;
110114
111115 afterEach ( ( ) => {
@@ -177,11 +181,6 @@ describe('ExportMarketplaceApps', () => {
177181 } ) ,
178182 } ) ;
179183
180- // marketplaceSDKClient is already stubbed in beforeEach, no need to stub again
181- // getOrgUid and getDeveloperHubUrl are already stubbed in beforeEach, just ensure they resolve correctly
182- ( marketplaceAppHelper . getOrgUid as sinon . SinonStub ) . resolves ( 'test-org-uid' ) ;
183- ( marketplaceAppHelper . getDeveloperHubUrl as sinon . SinonStub ) . resolves ( 'https://developer-api.contentstack.io' ) ;
184-
185184 // Mock exportApps and getAppManifestAndAppConfig to avoid complex setup
186185 const exportAppsStub = sinon . stub ( exportMarketplaceApps , 'exportApps' ) . resolves ( ) ;
187186 const getAppManifestAndAppConfigStub = sinon . stub ( exportMarketplaceApps , 'getAppManifestAndAppConfig' ) . resolves ( ) ;
@@ -200,9 +199,6 @@ describe('ExportMarketplaceApps', () => {
200199 getAppManifestAndAppConfigStub . restore ( ) ;
201200 getAppsCountStub . restore ( ) ;
202201 configHandlerGetStub . restore ( ) ;
203- // marketplaceSDKClient is restored in afterEach, no need to restore here
204- ( marketplaceAppHelper . getOrgUid as sinon . SinonStub ) . restore ( ) ;
205- ( marketplaceAppHelper . getDeveloperHubUrl as sinon . SinonStub ) . restore ( ) ;
206202 } ) ;
207203
208204 it ( 'should set marketplaceAppPath correctly' , async ( ) => {
@@ -332,15 +328,15 @@ describe('ExportMarketplaceApps', () => {
332328 } ) ;
333329
334330 it ( 'should encrypt app configurations when present' , async ( ) => {
335- exportMarketplaceApps . installedApps = [
336- {
337- uid : 'inst-1' ,
338- manifest : { uid : 'app -1' , name : 'Test App' } ,
339- configuration : { key : 'value ' } ,
340- } ,
341- ] ;
342-
343- const getStackSpecificAppsStub = sinon . stub ( exportMarketplaceApps , 'getStackSpecificApps' ) . resolves ( ) ;
331+ const getStackSpecificAppsStub = sinon . stub ( exportMarketplaceApps , 'getStackSpecificApps' ) . callsFake ( async ( ) => {
332+ exportMarketplaceApps . installedApps = [
333+ {
334+ uid : 'inst -1' ,
335+ manifest : { uid : 'app-1' , name : 'Test App ' } ,
336+ configuration : { key : 'value' } ,
337+ } ,
338+ ] ;
339+ } ) ;
344340 const getAppManifestAndAppConfigStub = sinon . stub ( exportMarketplaceApps , 'getAppManifestAndAppConfig' ) . resolves ( ) ;
345341
346342 await exportMarketplaceApps . exportApps ( ) ;
@@ -365,10 +361,13 @@ describe('ExportMarketplaceApps', () => {
365361 const getStackSpecificAppsStub = sinon . stub ( exportMarketplaceApps , 'getStackSpecificApps' ) . resolves ( ) ;
366362 const getAppManifestAndAppConfigStub = sinon . stub ( exportMarketplaceApps , 'getAppManifestAndAppConfig' ) . resolves ( ) ;
367363
364+ // Reset the stub call count since it might have been called in previous tests
365+ ( utils . createNodeCryptoInstance as sinon . SinonStub ) . resetHistory ( ) ;
366+
368367 await exportMarketplaceApps . exportApps ( ) ;
369368
370369 // NodeCrypto should not be initialized if no configurations
371- expect ( ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . false ;
370+ expect ( ( utils . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . false ;
372371
373372 getStackSpecificAppsStub . restore ( ) ;
374373 getAppManifestAndAppConfigStub . restore ( ) ;
@@ -736,9 +735,12 @@ describe('ExportMarketplaceApps', () => {
736735 } ) ,
737736 } ) ;
738737
738+ // Reset the stub call count since it was called in beforeEach
739+ ( utils . createNodeCryptoInstance as sinon . SinonStub ) . resetHistory ( ) ;
740+
739741 await exportMarketplaceApps . getAppConfigurations ( 0 , exportMarketplaceApps . installedApps [ 0 ] ) ;
740742
741- expect ( ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . true ;
743+ expect ( ( utils . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . true ;
742744 expect ( exportMarketplaceApps . nodeCrypto ) . to . exist ;
743745 } ) ;
744746
0 commit comments