@@ -5,6 +5,7 @@ import * as utilities from '@contentstack/cli-utilities';
55import ExportMarketplaceApps from '../../../../src/export/modules/marketplace-apps' ;
66import ExportConfig from '../../../../src/types/export-config' ;
77import * as marketplaceAppHelper from '../../../../src/utils/marketplace-app-helper' ;
8+ import * as utils from '../../../../src/utils' ;
89
910describe ( 'ExportMarketplaceApps' , ( ) => {
1011 let exportMarketplaceApps : any ;
@@ -105,6 +106,10 @@ describe('ExportMarketplaceApps', () => {
105106 sinon . stub ( marketplaceAppHelper , 'getDeveloperHubUrl' ) . resolves ( 'https://developer-api.contentstack.io' ) ;
106107 sinon . stub ( marketplaceAppHelper , 'createNodeCryptoInstance' ) . resolves ( mockNodeCrypto ) ;
107108 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' ) ;
108113 } ) ;
109114
110115 afterEach ( ( ) => {
@@ -295,7 +300,14 @@ describe('ExportMarketplaceApps', () => {
295300
296301 await exportMarketplaceApps . start ( ) ;
297302
298- expect ( ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . calledOnce ) . to . be . true ;
303+ // Source imports from utils barrel; resolution may use utils or marketplaceAppHelper depending on env (CI vs local)
304+ const helperCalled = ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . calledOnce ;
305+ const utilsCalled = ( utils . createNodeCryptoInstance as sinon . SinonStub ) . calledOnce ;
306+ expect ( helperCalled || utilsCalled , 'createNodeCryptoInstance should be called exactly once' ) . to . be . true ;
307+ expect (
308+ ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . callCount +
309+ ( utils . createNodeCryptoInstance as sinon . SinonStub ) . callCount ,
310+ ) . to . equal ( 1 ) ;
299311
300312 getAppsCountStub . restore ( ) ;
301313 exportAppsStub . restore ( ) ;
@@ -397,12 +409,12 @@ describe('ExportMarketplaceApps', () => {
397409 const getAppManifestAndAppConfigStub = sinon . stub ( exportMarketplaceApps , 'getAppManifestAndAppConfig' ) . resolves ( ) ;
398410
399411 // Reset the stub call count since it might have been called in previous tests
400- ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . resetHistory ( ) ;
412+ ( utils . createNodeCryptoInstance as sinon . SinonStub ) . resetHistory ( ) ;
401413
402414 await exportMarketplaceApps . exportApps ( ) ;
403415
404416 // NodeCrypto should not be initialized if no configurations
405- expect ( ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . false ;
417+ expect ( ( utils . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . false ;
406418
407419 getStackSpecificAppsStub . restore ( ) ;
408420 getAppManifestAndAppConfigStub . restore ( ) ;
@@ -773,11 +785,11 @@ describe('ExportMarketplaceApps', () => {
773785 } ) ;
774786
775787 // Reset the stub call count since it was called in beforeEach
776- ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . resetHistory ( ) ;
788+ ( utils . createNodeCryptoInstance as sinon . SinonStub ) . resetHistory ( ) ;
777789
778790 await exportMarketplaceApps . getAppConfigurations ( 0 , exportMarketplaceApps . installedApps [ 0 ] ) ;
779791
780- expect ( ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . true ;
792+ expect ( ( utils . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . true ;
781793 expect ( exportMarketplaceApps . nodeCrypto ) . to . exist ;
782794 expect ( ( marketplaceAppHelper . createNodeCryptoInstance as sinon . SinonStub ) . called ) . to . be . true ;
783795 } ) ;
0 commit comments