Skip to content

Commit 2cf51be

Browse files
Y-RyuZUclaude
andcommitted
fix: update filesystem-service tests to use FileService test override
Replace direct Tauri invoke mocks with FileService.setTestInvokeOverride method for more reliable test execution. This ensures the FileService internal tauriInvoke function uses the test mock properly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent bde72da commit 2cf51be

File tree

1 file changed

+54
-16
lines changed

1 file changed

+54
-16
lines changed

src/lib/services/__tests__/filesystem-service.jest.test.ts

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
import { FileService } from '../file-service';
22

33
describe('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(/\.snbt$/);
1963
expect(file).toMatch(/ftb\/quests/);
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(/\.snbt$/);
3781
expect(file).toMatch(/\/different\/path\/ftb\/quests/);
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

Comments
 (0)