From abd712f694a05bd55e5c192df9b77194175c6427 Mon Sep 17 00:00:00 2001 From: Bill Ballou Date: Sat, 31 Jan 2026 17:08:29 -0500 Subject: [PATCH] test: add failing tests for updateSections force parameter Add three tests for the upcoming force parameter feature: 1. Test that ifMatch is required when force is not set 2. Test that force=true bypasses ifMatch requirement 3. Test that valid ifMatch works without force These tests are expected to fail until the force parameter is implemented in updateSections. --- tests/note-tools.test.ts | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/note-tools.test.ts b/tests/note-tools.test.ts index c58480b..60981fe 100644 --- a/tests/note-tools.test.ts +++ b/tests/note-tools.test.ts @@ -1022,6 +1022,77 @@ Some text expect(result.isError).toBe(true); expect(result.content[0].text).toContain('not a file'); }); + + it('should return error when ifMatch not provided and force not set', async () => { + const mockFile = createMockTFile('test.md', { + ctime: 1000, + mtime: 2000, + size: 100 + }); + const content = 'Line 1\nLine 2'; + + (PathUtils.resolveFile as jest.Mock).mockReturnValue(mockFile); + mockVault.read = jest.fn().mockResolvedValue(content); + mockVault.modify = jest.fn().mockResolvedValue(undefined); + + const result = await noteTools.updateSections('test.md', [ + { startLine: 1, endLine: 1, content: 'New' } + ]); + + expect(result.isError).toBe(true); + const parsed = JSON.parse(result.content[0].text); + expect(parsed.error).toBe('Version check required'); + expect(parsed.message).toContain('ifMatch parameter is required'); + expect(mockVault.modify).not.toHaveBeenCalled(); + }); + + it('should proceed without ifMatch when force is true', async () => { + const mockFile = createMockTFile('test.md', { + ctime: 1000, + mtime: 2000, + size: 100 + }); + const content = 'Line 1\nLine 2'; + + (PathUtils.resolveFile as jest.Mock).mockReturnValue(mockFile); + mockVault.read = jest.fn().mockResolvedValue(content); + mockVault.modify = jest.fn().mockResolvedValue(undefined); + + const result = await noteTools.updateSections( + 'test.md', + [{ startLine: 1, endLine: 1, content: 'New Line 1' }], + undefined, // no ifMatch + true, // validateLinks + true // force + ); + + expect(result.isError).toBeUndefined(); + expect(mockVault.modify).toHaveBeenCalled(); + const parsed = JSON.parse(result.content[0].text); + expect(parsed.success).toBe(true); + }); + + it('should proceed with valid ifMatch without force', async () => { + const mockFile = createMockTFile('test.md', { + ctime: 1000, + mtime: 2000, + size: 100 + }); + const content = 'Line 1\nLine 2'; + + (PathUtils.resolveFile as jest.Mock).mockReturnValue(mockFile); + mockVault.read = jest.fn().mockResolvedValue(content); + mockVault.modify = jest.fn().mockResolvedValue(undefined); + + const result = await noteTools.updateSections( + 'test.md', + [{ startLine: 1, endLine: 1, content: 'New Line 1' }], + 'AXrGSV5GxqntccmzWCNwe7' // valid ifMatch (SHA-256 hash of "2000-100") + ); + + expect(result.isError).toBeUndefined(); + expect(mockVault.modify).toHaveBeenCalled(); + }); }); describe('path validation', () => {