@@ -47,7 +47,7 @@ describe('ImportContentTypes', () => {
4747 } ;
4848
4949 mockImportConfig = {
50- apiKey : 'test-api-key ' ,
50+ apiKey : 'test' ,
5151 contentDir : '/test/content' ,
5252 data : '/test/content' ,
5353 contentVersion : 1 ,
@@ -61,7 +61,7 @@ describe('ImportContentTypes', () => {
6161 userId : 'user-123' ,
6262 email : 'test@example.com' ,
6363 sessionId : 'session-123' ,
64- apiKey : 'test-api-key ' ,
64+ apiKey : 'test' ,
6565 orgId : 'org-123' ,
6666 authenticationMethod : 'Basic Auth'
6767 } ,
@@ -807,4 +807,184 @@ describe('ImportContentTypes', () => {
807807 expect ( importContentTypes [ 'isExtensionsUpdate' ] ) . to . be . true ;
808808 } ) ;
809809 } ) ;
810+
811+ describe ( 'Additional Branch Coverage Tests' , ( ) => {
812+ it ( 'should handle different error conditions in seedCTs onReject' , async ( ) => {
813+ const mockCTs = [ { uid : 'ct1' , title : 'Content Type 1' } ] ;
814+
815+ fsUtilStub . readFile . withArgs ( sinon . match ( / s c h e m a \. j s o n / ) ) . returns ( mockCTs ) ;
816+ fsUtilStub . readFile . withArgs ( sinon . match ( / u i d - m a p p i n g \. j s o n / ) ) . returns ( { extension_uid : { } } ) ;
817+ fsUtilStub . readFile . withArgs ( sinon . match ( / t a x o n o m i e s .* s u c c e s s \. j s o n / ) ) . returns ( { } ) ;
818+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ g l o b a l _ f i e l d s \. j s / ) ) . returns ( [ ] ) ;
819+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ e x t e n s i o n s \. j s / ) ) . returns ( [ ] ) ;
820+
821+ await importContentTypes . start ( ) ;
822+
823+ const onReject = makeConcurrentCallStub . firstCall . args [ 0 ] . apiParams . reject ;
824+
825+ // Test error with errorCode 115 but different error structure
826+ onReject ( {
827+ error : { errorCode : 115 , errors : { title : 'Title already exists' } } ,
828+ apiData : { content_type : { uid : 'ct1' } }
829+ } ) ;
830+
831+ // Test error with errorCode 115 but different error structure
832+ onReject ( {
833+ error : { errorCode : 115 , errors : { uid : 'UID already exists' } } ,
834+ apiData : { content_type : { uid : 'ct1' } }
835+ } ) ;
836+
837+ expect ( makeConcurrentCallStub . called ) . to . be . true ;
838+ } ) ;
839+
840+ it ( 'should handle different conditions in updatePendingGFs' , async ( ) => {
841+ const mockCTs = [ { uid : 'ct1' , title : 'Content Type 1' } ] ;
842+ const mockPendingGFs = [ 'gf1' , 'gf2' ] ;
843+ const mockGFs = [ { uid : 'gf1' , title : 'Global Field 1' } ] ;
844+
845+ fsUtilStub . readFile . withArgs ( sinon . match ( / s c h e m a \. j s o n / ) ) . returns ( mockCTs ) ;
846+ fsUtilStub . readFile . withArgs ( sinon . match ( / u i d - m a p p i n g \. j s o n / ) ) . returns ( { extension_uid : { } } ) ;
847+ fsUtilStub . readFile . withArgs ( sinon . match ( / t a x o n o m i e s .* s u c c e s s \. j s o n / ) ) . returns ( { } ) ;
848+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ g l o b a l _ f i e l d s \. j s / ) ) . returns ( mockPendingGFs ) ;
849+ fsUtilStub . readFile . withArgs ( sinon . match ( / g l o b a l _ f i e l d s .* \. j s o n / ) ) . returns ( mockGFs ) ;
850+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ e x t e n s i o n s \. j s / ) ) . returns ( [ ] ) ;
851+
852+ await importContentTypes . start ( ) ;
853+
854+ const onSuccess = makeConcurrentCallStub . getCall ( 2 ) . args [ 0 ] . apiParams . resolve ;
855+ const onReject = makeConcurrentCallStub . getCall ( 2 ) . args [ 0 ] . apiParams . reject ;
856+
857+ // Test onSuccess with undefined uid
858+ onSuccess ( {
859+ response : { uid : 'gf1' } ,
860+ apiData : { uid : undefined }
861+ } ) ;
862+
863+ // Test onReject with undefined uid
864+ onReject ( {
865+ error : { message : 'Update failed' } ,
866+ apiData : { uid : undefined }
867+ } ) ;
868+
869+ expect ( makeConcurrentCallStub . callCount ) . to . be . greaterThan ( 2 ) ;
870+ } ) ;
871+
872+ it ( 'should handle different conditions in updatePendingExtensions' , async ( ) => {
873+ const mockCTs = [ { uid : 'ct1' , title : 'Content Type 1' } ] ;
874+ const mockExtensions = [ { uid : 'ext1' , title : 'Extension 1' } ] ;
875+
876+ fsUtilStub . readFile . withArgs ( sinon . match ( / s c h e m a \. j s o n / ) ) . returns ( mockCTs ) ;
877+ fsUtilStub . readFile . withArgs ( sinon . match ( / u i d - m a p p i n g \. j s o n / ) ) . returns ( { extension_uid : { } } ) ;
878+ fsUtilStub . readFile . withArgs ( sinon . match ( / t a x o n o m i e s .* s u c c e s s \. j s o n / ) ) . returns ( { } ) ;
879+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ g l o b a l _ f i e l d s \. j s / ) ) . returns ( [ ] ) ;
880+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ e x t e n s i o n s \. j s / ) ) . returns ( mockExtensions ) ;
881+
882+ await importContentTypes . start ( ) ;
883+
884+ const onSuccess = makeConcurrentCallStub . lastCall . args [ 0 ] . apiParams . resolve ;
885+ const onReject = makeConcurrentCallStub . lastCall . args [ 0 ] . apiParams . reject ;
886+
887+ // Test onSuccess with undefined uid and title
888+ onSuccess ( {
889+ response : { title : 'Updated Extension' } ,
890+ apiData : { uid : undefined , title : undefined }
891+ } ) ;
892+
893+ // Test onReject with title error and skipExisting true
894+ importContentTypes [ 'importConfig' ] . skipExisting = true ;
895+ onReject ( {
896+ error : { errors : { title : 'Title already exists' } } ,
897+ apiData : { uid : 'ext1' }
898+ } ) ;
899+
900+ // Test onReject with title error and skipExisting false
901+ importContentTypes [ 'importConfig' ] . skipExisting = false ;
902+ onReject ( {
903+ error : { errors : { title : 'Title already exists' } } ,
904+ apiData : { uid : 'ext1' }
905+ } ) ;
906+
907+ expect ( makeConcurrentCallStub . called ) . to . be . true ;
908+ } ) ;
909+
910+ it ( 'should handle null apiContent in updatePendingExtensions' , async ( ) => {
911+ const mockCTs = [ { uid : 'ct1' , title : 'Content Type 1' } ] ;
912+
913+ fsUtilStub . readFile . withArgs ( sinon . match ( / s c h e m a \. j s o n / ) ) . returns ( mockCTs ) ;
914+ fsUtilStub . readFile . withArgs ( sinon . match ( / u i d - m a p p i n g \. j s o n / ) ) . returns ( { extension_uid : { } } ) ;
915+ fsUtilStub . readFile . withArgs ( sinon . match ( / t a x o n o m i e s .* s u c c e s s \. j s o n / ) ) . returns ( { } ) ;
916+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ g l o b a l _ f i e l d s \. j s / ) ) . returns ( [ ] ) ;
917+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ e x t e n s i o n s \. j s / ) ) . returns ( null ) ;
918+
919+ await importContentTypes . start ( ) ;
920+
921+ expect ( importContentTypes [ 'isExtensionsUpdate' ] ) . to . be . false ;
922+ } ) ;
923+
924+ it ( 'should handle empty array apiContent in updatePendingExtensions' , async ( ) => {
925+ const mockCTs = [ { uid : 'ct1' , title : 'Content Type 1' } ] ;
926+
927+ fsUtilStub . readFile . withArgs ( sinon . match ( / s c h e m a \. j s o n / ) ) . returns ( mockCTs ) ;
928+ fsUtilStub . readFile . withArgs ( sinon . match ( / u i d - m a p p i n g \. j s o n / ) ) . returns ( { extension_uid : { } } ) ;
929+ fsUtilStub . readFile . withArgs ( sinon . match ( / t a x o n o m i e s .* s u c c e s s \. j s o n / ) ) . returns ( { } ) ;
930+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ g l o b a l _ f i e l d s \. j s / ) ) . returns ( [ ] ) ;
931+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ e x t e n s i o n s \. j s / ) ) . returns ( [ ] ) ;
932+
933+ await importContentTypes . start ( ) ;
934+
935+ expect ( importContentTypes [ 'isExtensionsUpdate' ] ) . to . be . false ;
936+ } ) ;
937+
938+ it ( 'should handle onSuccess with different response structure in updatePendingExtensions' , async ( ) => {
939+ const mockCTs = [ { uid : 'ct1' , title : 'Content Type 1' } ] ;
940+ const mockExtensions = [ { uid : 'ext1' , title : 'Extension 1' } ] ;
941+
942+ fsUtilStub . readFile . withArgs ( sinon . match ( / s c h e m a \. j s o n / ) ) . returns ( mockCTs ) ;
943+ fsUtilStub . readFile . withArgs ( sinon . match ( / u i d - m a p p i n g \. j s o n / ) ) . returns ( { extension_uid : { } } ) ;
944+ fsUtilStub . readFile . withArgs ( sinon . match ( / t a x o n o m i e s .* s u c c e s s \. j s o n / ) ) . returns ( { } ) ;
945+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ g l o b a l _ f i e l d s \. j s / ) ) . returns ( [ ] ) ;
946+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ e x t e n s i o n s \. j s / ) ) . returns ( mockExtensions ) ;
947+
948+ await importContentTypes . start ( ) ;
949+
950+ const onSuccess = makeConcurrentCallStub . lastCall . args [ 0 ] . apiParams . resolve ;
951+
952+ // Test onSuccess with response that has no title property
953+ onSuccess ( {
954+ response : { uid : 'ext1' } ,
955+ apiData : { uid : 'ext1' , title : 'Extension 1' }
956+ } ) ;
957+
958+ expect ( makeConcurrentCallStub . called ) . to . be . true ;
959+ } ) ;
960+
961+ it ( 'should handle onReject with different error structures in updatePendingExtensions' , async ( ) => {
962+ const mockCTs = [ { uid : 'ct1' , title : 'Content Type 1' } ] ;
963+ const mockExtensions = [ { uid : 'ext1' , title : 'Extension 1' } ] ;
964+
965+ fsUtilStub . readFile . withArgs ( sinon . match ( / s c h e m a \. j s o n / ) ) . returns ( mockCTs ) ;
966+ fsUtilStub . readFile . withArgs ( sinon . match ( / u i d - m a p p i n g \. j s o n / ) ) . returns ( { extension_uid : { } } ) ;
967+ fsUtilStub . readFile . withArgs ( sinon . match ( / t a x o n o m i e s .* s u c c e s s \. j s o n / ) ) . returns ( { } ) ;
968+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ g l o b a l _ f i e l d s \. j s / ) ) . returns ( [ ] ) ;
969+ fsUtilStub . readFile . withArgs ( sinon . match ( / p e n d i n g _ e x t e n s i o n s \. j s / ) ) . returns ( mockExtensions ) ;
970+
971+ await importContentTypes . start ( ) ;
972+
973+ const onReject = makeConcurrentCallStub . lastCall . args [ 0 ] . apiParams . reject ;
974+
975+ // Test onReject with error that has no errors property
976+ onReject ( {
977+ error : { message : 'Server error' } ,
978+ apiData : { uid : 'ext1' }
979+ } ) ;
980+
981+ // Test onReject with error that has errors but no title
982+ onReject ( {
983+ error : { errors : { uid : 'UID already exists' } } ,
984+ apiData : { uid : 'ext1' }
985+ } ) ;
986+
987+ expect ( makeConcurrentCallStub . called ) . to . be . true ;
988+ } ) ;
989+ } ) ;
810990} ) ;
0 commit comments