11import { FileService } from '../file-service' ;
22
33describe ( 'FileService - FTB Quest File Discovery' , ( ) => {
4+ beforeEach ( ( ) => {
5+ jest . clearAllMocks ( ) ;
6+ // Set up the test invoke override for FileService
7+ FileService . setTestInvokeOverride ( ( command : string , args : any ) => {
8+ if ( command === 'get_ftb_quest_files' ) {
9+ const dir = args ?. dir || '' ;
10+ return Promise . resolve ( [
11+ `${ dir } /ftb/quests/chapter1.snbt` ,
12+ `${ dir } /ftb/quests/chapter2.snbt` ,
13+ `${ dir } /ftb/quests/chapter3.snbt` ,
14+ ] ) ;
15+ }
16+ if ( command === 'get_better_quest_files' ) {
17+ return Promise . resolve ( [
18+ `${ args ?. dir } /betterquests/DefaultQuests.json` ,
19+ `${ args ?. dir } /betterquests/QuestLines.json` ,
20+ ] ) ;
21+ }
22+ if ( command === 'get_files_with_extension' ) {
23+ if ( args ?. extension === '.json' ) {
24+ return Promise . resolve ( [
25+ `${ args ?. dir } /example1.json` ,
26+ `${ args ?. dir } /example2.json` ,
27+ `${ args ?. dir } /subfolder/example3.json` ,
28+ ] ) ;
29+ } else if ( args ?. extension === '.snbt' ) {
30+ return Promise . resolve ( [
31+ `${ args ?. dir } /example1.snbt` ,
32+ `${ args ?. dir } /example2.snbt` ,
33+ ] ) ;
34+ }
35+ }
36+ if ( command === 'read_text_file' ) {
37+ return Promise . resolve ( `Mock content for ${ args ?. path } ` ) ;
38+ }
39+ return Promise . resolve ( null ) ;
40+ } ) ;
41+ } ) ;
42+
43+ afterEach ( ( ) => {
44+ // Reset the test invoke override
45+ FileService . setTestInvokeOverride ( null ) ;
46+ } ) ;
47+
448 describe ( 'get_ftb_quest_files functionality' , ( ) => {
549 it ( 'should return SNBT files using built-in mock' , async ( ) => {
6- // FileService has a built-in mock that returns SNBT files for get_ftb_quest_files
7- const result = await FileService . invoke ( 'get_ftb_quest_files' , { dir : ' /test/modpack' } ) ;
50+ // Use the FileService method
51+ const result = await FileService . getFTBQuestFiles ( ' /test/modpack') ;
852
953 // The built-in mock returns SNBT files with the pattern: dir/ftb/quests/chapterX.snbt
1054 expect ( result ) . toEqual ( [
@@ -14,15 +58,15 @@ describe('FileService - FTB Quest File Discovery', () => {
1458 ] ) ;
1559
1660 // Verify SNBT files are returned
17- ( result as string [ ] ) . forEach ( file => {
61+ result . forEach ( file => {
1862 expect ( file ) . toMatch ( / \. s n b t $ / ) ;
1963 expect ( file ) . toMatch ( / f t b \/ q u e s t s / ) ;
2064 } ) ;
2165 } ) ;
2266
2367 it ( 'should handle different directory paths correctly' , async ( ) => {
2468 // Test with different directory path
25- const result = await FileService . invoke ( 'get_ftb_quest_files' , { dir : ' /different/path' } ) ;
69+ const result = await FileService . getFTBQuestFiles ( ' /different/path') ;
2670
2771 // The built-in mock adapts to the directory provided
2872 expect ( result ) . toEqual ( [
@@ -32,14 +76,14 @@ describe('FileService - FTB Quest File Discovery', () => {
3276 ] ) ;
3377
3478 // Verify SNBT files are returned
35- ( result as string [ ] ) . forEach ( file => {
79+ result . forEach ( file => {
3680 expect ( file ) . toMatch ( / \. s n b t $ / ) ;
3781 expect ( file ) . toMatch ( / \/ d i f f e r e n t \/ p a t h \/ f t b \/ q u e s t s / ) ;
3882 } ) ;
3983 } ) ;
4084
4185 it ( 'should work with empty directory path' , async ( ) => {
42- const result = await FileService . invoke ( 'get_ftb_quest_files' , { dir : '' } ) ;
86+ const result = await FileService . getFTBQuestFiles ( '' ) ;
4387
4488 expect ( result ) . toEqual ( [
4589 '/ftb/quests/chapter1.snbt' ,
@@ -74,7 +118,7 @@ describe('FileService - FTB Quest File Discovery', () => {
74118
75119 describe ( 'other file operations' , ( ) => {
76120 it ( 'should handle get_better_quest_files' , async ( ) => {
77- const result = await FileService . invoke ( 'get_better_quest_files' , { dir : ' /test/modpack' } ) ;
121+ const result = await FileService . getBetterQuestFiles ( ' /test/modpack') ;
78122
79123 expect ( result ) . toEqual ( [
80124 '/test/modpack/betterquests/DefaultQuests.json' ,
@@ -83,10 +127,7 @@ describe('FileService - FTB Quest File Discovery', () => {
83127 } ) ;
84128
85129 it ( 'should handle get_files_with_extension for JSON' , async ( ) => {
86- const result = await FileService . invoke ( 'get_files_with_extension' , {
87- dir : '/test/modpack' ,
88- extension : '.json'
89- } ) ;
130+ const result = await FileService . getFilesWithExtension ( '/test/modpack' , '.json' ) ;
90131
91132 expect ( result ) . toEqual ( [
92133 '/test/modpack/example1.json' ,
@@ -96,10 +137,7 @@ describe('FileService - FTB Quest File Discovery', () => {
96137 } ) ;
97138
98139 it ( 'should handle get_files_with_extension for SNBT' , async ( ) => {
99- const result = await FileService . invoke ( 'get_files_with_extension' , {
100- dir : '/test/modpack' ,
101- extension : '.snbt'
102- } ) ;
140+ const result = await FileService . getFilesWithExtension ( '/test/modpack' , '.snbt' ) ;
103141
104142 expect ( result ) . toEqual ( [
105143 '/test/modpack/example1.snbt' ,
@@ -108,7 +146,7 @@ describe('FileService - FTB Quest File Discovery', () => {
108146 } ) ;
109147
110148 it ( 'should handle read_text_file' , async ( ) => {
111- const result = await FileService . invoke ( 'read_text_file' , { path : ' /test/file.txt' } ) ;
149+ const result = await FileService . readTextFile ( ' /test/file.txt') ;
112150
113151 expect ( result ) . toBe ( 'Mock content for /test/file.txt' ) ;
114152 } ) ;
0 commit comments