@@ -535,9 +535,14 @@ describe('ExportTaxonomies', () => {
535535 } ) ;
536536
537537 it ( 'should disable locale-based export on API error when checkLocaleSupport is true' , async ( ) => {
538+ // Create a structured API error (not a plan limitation error)
539+ const apiError : any = new Error ( 'API Error' ) ;
540+ apiError . status = 500 ;
541+ apiError . errors = { general : [ 'Internal server error' ] } ;
542+
538543 mockStackClient . taxonomy . returns ( {
539544 query : sinon . stub ( ) . returns ( {
540- find : sinon . stub ( ) . rejects ( new Error ( 'API Error' ) )
545+ find : sinon . stub ( ) . rejects ( apiError )
541546 } )
542547 } ) ;
543548
@@ -546,6 +551,27 @@ describe('ExportTaxonomies', () => {
546551 // Should disable locale-based export on error
547552 expect ( exportTaxonomies . isLocaleBasedExportSupported ) . to . be . false ;
548553 } ) ;
554+
555+ it ( 'should handle taxonomy localization plan limitation error gracefully' , async ( ) => {
556+ // Create the exact 403 error from the plan limitation
557+ const planLimitationError : any = new Error ( 'Forbidden' ) ;
558+ planLimitationError . status = 403 ;
559+ planLimitationError . statusText = 'Forbidden' ;
560+ planLimitationError . errors = {
561+ taxonomies : [ 'Taxonomy localization is not included in your plan. Please contact the support@contentstack.com team for assistance.' ]
562+ } ;
563+
564+ mockStackClient . taxonomy . returns ( {
565+ query : sinon . stub ( ) . returns ( {
566+ find : sinon . stub ( ) . rejects ( planLimitationError )
567+ } )
568+ } ) ;
569+
570+ await exportTaxonomies . fetchTaxonomies ( 'en-us' , true ) ;
571+
572+ // Should disable locale-based export and not throw error
573+ expect ( exportTaxonomies . isLocaleBasedExportSupported ) . to . be . false ;
574+ } ) ;
549575 } ) ;
550576
551577 describe ( 'exportTaxonomies() method - locale-based export' , ( ) => {
@@ -586,6 +612,37 @@ describe('ExportTaxonomies', () => {
586612 mockGetLocales . restore ( ) ;
587613 } ) ;
588614
615+ it ( 'should clear taxonomies and re-fetch when falling back to legacy export' , async ( ) => {
616+ let fetchCallCount = 0 ;
617+ const mockFetchTaxonomies = sinon . stub ( exportTaxonomies , 'fetchTaxonomies' ) . callsFake ( async ( locale , checkSupport ) => {
618+ fetchCallCount ++ ;
619+ if ( checkSupport ) {
620+ // First call fails locale check
621+ exportTaxonomies . isLocaleBasedExportSupported = false ;
622+ exportTaxonomies . taxonomies = { 'partial-data' : { uid : 'partial-data' } } ; // Simulate partial data
623+ } else {
624+ // Second call should have cleared data
625+ expect ( exportTaxonomies . taxonomies ) . to . deep . equal ( { } ) ;
626+ }
627+ } ) ;
628+ const mockExportTaxonomies = sinon . stub ( exportTaxonomies , 'exportTaxonomies' ) . resolves ( ) ;
629+ const mockWriteMetadata = sinon . stub ( exportTaxonomies , 'writeTaxonomiesMetadata' ) . resolves ( ) ;
630+ const mockGetLocales = sinon . stub ( exportTaxonomies , 'getLocalesToExport' ) . returns ( [ 'en-us' ] ) ;
631+
632+ await exportTaxonomies . start ( ) ;
633+
634+ // Should call fetchTaxonomies twice: once for check, once for legacy
635+ expect ( fetchCallCount ) . to . equal ( 2 ) ;
636+ // First call with locale, second without
637+ expect ( mockFetchTaxonomies . firstCall . args ) . to . deep . equal ( [ 'en-us' , true ] ) ;
638+ expect ( mockFetchTaxonomies . secondCall . args ) . to . deep . equal ( [ ] ) ;
639+
640+ mockFetchTaxonomies . restore ( ) ;
641+ mockExportTaxonomies . restore ( ) ;
642+ mockWriteMetadata . restore ( ) ;
643+ mockGetLocales . restore ( ) ;
644+ } ) ;
645+
589646 it ( 'should use locale-based export when supported' , async ( ) => {
590647 const mockFetchTaxonomies = sinon . stub ( exportTaxonomies , 'fetchTaxonomies' ) . callsFake ( async ( locale , checkSupport ) => {
591648 if ( checkSupport ) {
0 commit comments