From 5f36c22e482e494741280708ea7ac1ff282cb74c Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 20 Oct 2025 09:46:13 -0400 Subject: [PATCH] test: add note-tools folder-not-file error tests Add 5 tests for folder-not-file error cases: - read_note when path is a folder (line 61-66 in source) - rename_file when source path is a folder (line 377) - rename_file when destination path is a folder (line 408) - read_excalidraw when path is a folder (line 590) - update_frontmatter when path is a folder (line 710) - update_sections when path is a folder (line 836) All tests verify error message uses ErrorMessages.notAFile() Coverage for note-tools.ts increased to 98% --- tests/note-tools.test.ts | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/note-tools.test.ts b/tests/note-tools.test.ts index 3bcae04..d49d279 100644 --- a/tests/note-tools.test.ts +++ b/tests/note-tools.test.ts @@ -453,6 +453,16 @@ describe('NoteTools', () => { expect(result.content[0].text).toContain('not found'); }); + it('should return error if source path is a folder', async () => { + (PathUtils.resolveFile as jest.Mock).mockReturnValue(null); + (PathUtils.folderExists as jest.Mock).mockReturnValue(true); + + const result = await noteTools.renameFile('folder', 'new.md'); + + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('not a file'); + }); + it('should return error if destination exists', async () => { const mockFile = createMockTFile('old.md'); @@ -465,6 +475,19 @@ describe('NoteTools', () => { expect(result.content[0].text).toContain('already exists'); }); + it('should return error if destination path is a folder', async () => { + const mockFile = createMockTFile('old.md'); + + (PathUtils.resolveFile as jest.Mock).mockReturnValue(mockFile); + (PathUtils.fileExists as jest.Mock).mockReturnValue(false); + (PathUtils.folderExists as jest.Mock).mockReturnValue(true); + + const result = await noteTools.renameFile('old.md', 'existing-folder'); + + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('not a file'); + }); + it('should handle rename errors', async () => { const mockFile = createMockTFile('old.md'); @@ -571,6 +594,16 @@ Some text expect(result.content[0].text).toContain('not found'); }); + it('should return error if path is a folder', async () => { + (PathUtils.resolveFile as jest.Mock).mockReturnValue(null); + (PathUtils.folderExists as jest.Mock).mockReturnValue(true); + + const result = await noteTools.readExcalidraw('folder'); + + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('not a file'); + }); + it('should handle read errors', async () => { const mockFile = createMockTFile('drawing.md'); @@ -643,6 +676,16 @@ Some text expect(result.content[0].text).toContain('not found'); }); + it('should return error if path is a folder', async () => { + (PathUtils.resolveFile as jest.Mock).mockReturnValue(null); + (PathUtils.folderExists as jest.Mock).mockReturnValue(true); + + const result = await noteTools.updateFrontmatter('folder', { title: 'Test' }); + + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('not a file'); + }); + it('should check version if ifMatch provided', async () => { const mockFile = createMockTFile('test.md', { ctime: 1000, @@ -767,6 +810,18 @@ Some text expect(result.isError).toBe(true); expect(result.content[0].text).toContain('not found'); }); + + it('should return error if path is a folder', async () => { + (PathUtils.resolveFile as jest.Mock).mockReturnValue(null); + (PathUtils.folderExists as jest.Mock).mockReturnValue(true); + + const result = await noteTools.updateSections('folder', [ + { startLine: 1, endLine: 1, content: 'New' } + ]); + + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('not a file'); + }); }); describe('path validation', () => {