@@ -570,87 +570,47 @@ describe("ReconciliationText", () => {
570570 expect ( result . name_nl ) . toBe ( handle ) ;
571571 } ) ;
572572
573- it ( "should find a text part that was moved into a subdirectory " , ( ) => {
574- // Move part_1.liquid into a subfolder
573+ it ( "should read a text part from a subdirectory when config path is set manually " , ( ) => {
574+ // User manually set config to point to a subfolder; file lives there
575575 const subDir = path . join ( templateDir , "text_parts" , "tables" ) ;
576576 fs . mkdirSync ( subDir , { recursive : true } ) ;
577577 fs . renameSync ( part1LiquidPath , path . join ( subDir , "part_1.liquid" ) ) ;
578578
579+ const configWithSubfolderPath = { ...configContent , text_parts : { part_1 : "text_parts/tables/part_1.liquid" } } ;
580+ fs . writeFileSync ( configPath , JSON . stringify ( configWithSubfolderPath ) ) ;
581+
579582 const result = ReconciliationText . read ( handle ) ;
580583
581584 expect ( result . text_parts ) . toEqual ( [ { name : "part_1" , content : "Part 1 content" } ] ) ;
582585 } ) ;
583586
584- it ( "should update config.json when a text part is moved to a subdirectory" , ( ) => {
585- // Move part_1.liquid into a subfolder
586- const subDir = path . join ( templateDir , "text_parts" , "tables" ) ;
587- fs . mkdirSync ( subDir , { recursive : true } ) ;
588- fs . renameSync ( part1LiquidPath , path . join ( subDir , "part_1.liquid" ) ) ;
589-
590- ReconciliationText . read ( handle ) ;
591-
592- const updatedConfig = JSON . parse ( fs . readFileSync ( configPath , "utf-8" ) ) ;
593- expect ( updatedConfig . text_parts . part_1 ) . toBe ( "text_parts/tables/part_1.liquid" ) ;
594- } ) ;
595-
596- it ( "should find a text part nested multiple levels deep" , ( ) => {
597- // Move part_1.liquid into a deeply nested subfolder
598- // First, ensure no leftover from other tests by recreating the file at original location
599- if ( ! fs . existsSync ( part1LiquidPath ) ) {
600- fs . writeFileSync ( part1LiquidPath , "Part 1 content" ) ;
601- }
602- // Remove any subdirectories left from previous tests
603- const textPartsDir = path . join ( templateDir , "text_parts" ) ;
604- for ( const entry of fs . readdirSync ( textPartsDir ) ) {
605- const fullPath = path . join ( textPartsDir , entry ) ;
606- if ( fs . statSync ( fullPath ) . isDirectory ( ) ) {
607- fs . rmSync ( fullPath , { recursive : true , force : true } ) ;
608- }
609- }
587+ it ( "should read a text part nested multiple levels deep when config path is set manually" , ( ) => {
610588 const deepDir = path . join ( templateDir , "text_parts" , "section" , "subsection" ) ;
611589 fs . mkdirSync ( deepDir , { recursive : true } ) ;
612- fs . renameSync ( part1LiquidPath , path . join ( deepDir , "part_1.liquid" ) ) ;
590+ fs . writeFileSync ( path . join ( deepDir , "part_1.liquid" ) , "Part 1 content" ) ;
591+ fs . unlinkSync ( part1LiquidPath ) ;
592+
593+ const configWithDeepPath = { ...configContent , text_parts : { part_1 : "text_parts/section/subsection/part_1.liquid" } } ;
594+ fs . writeFileSync ( configPath , JSON . stringify ( configWithDeepPath ) ) ;
613595
614596 const result = ReconciliationText . read ( handle ) ;
615597
616598 expect ( result . text_parts ) . toEqual ( [ { name : "part_1" , content : "Part 1 content" } ] ) ;
617-
618- const updatedConfig = JSON . parse ( fs . readFileSync ( configPath , "utf-8" ) ) ;
619- expect ( updatedConfig . text_parts . part_1 ) . toBe ( "text_parts/section/subsection/part_1.liquid" ) ;
620599 } ) ;
621600
622- it ( "should not add new files on disk that are not in the config" , ( ) => {
623- // Add a new liquid file that is NOT listed in config
601+ it ( "should only include parts listed in the config" , ( ) => {
602+ // Extra file on disk not in config is ignored
624603 fs . writeFileSync ( path . join ( templateDir , "text_parts" , "extra_part.liquid" ) , "Extra content" ) ;
625604
626605 const result = ReconciliationText . read ( handle ) ;
627606
628- // Should only contain part_1, not extra_part
629607 expect ( result . text_parts ) . toEqual ( [ { name : "part_1" , content : "Part 1 content" } ] ) ;
630-
631- const updatedConfig = JSON . parse ( fs . readFileSync ( configPath , "utf-8" ) ) ;
632- expect ( updatedConfig . text_parts ) . not . toHaveProperty ( "extra_part" ) ;
633608 } ) ;
634609
635- it ( "should keep config entry unchanged when a text part file is missing from disk" , ( ) => {
636- // Delete part_1.liquid from disk but keep it in the config
610+ it ( "should throw when a text part in config is missing from disk" , ( ) => {
637611 fs . unlinkSync ( part1LiquidPath ) ;
638612
639- // The config should still have the original path (not removed by syncTextPartsFromDisk)
640- // We can't call read() fully because it will fail when trying to read the missing file,
641- // so we just verify the config is not modified by writing it and checking it
642- const configBefore = JSON . parse ( fs . readFileSync ( configPath , "utf-8" ) ) ;
643- expect ( configBefore . text_parts . part_1 ) . toBe ( "text_parts/part_1.liquid" ) ;
644-
645- // read() will fail at readPartsLiquid, but the config should not have been altered
646- try {
647- ReconciliationText . read ( handle ) ;
648- } catch ( e ) {
649- // Expected to fail when reading the missing file
650- }
651-
652- const configAfter = JSON . parse ( fs . readFileSync ( configPath , "utf-8" ) ) ;
653- expect ( configAfter . text_parts . part_1 ) . toBe ( "text_parts/part_1.liquid" ) ;
613+ expect ( ( ) => ReconciliationText . read ( handle ) ) . toThrow ( ) ;
654614 } ) ;
655615 } ) ;
656616} ) ;
0 commit comments