notex.nvim/tests/integration/test_document_indexing.lua

129 lines
2.7 KiB
Lua
Raw Permalink Normal View History

2025-10-05 20:16:33 -04:00
-- Integration tests for document indexing workflow
local busted = require('busted')
describe("Document Indexing Workflow Integration", function()
local indexer
before_each(function()
-- These modules don't exist yet - tests should fail
indexer = require('notex.index')
end)
it("should index markdown files with YAML headers", function()
local test_files = {
"/tmp/test_doc1.md",
"/tmp/test_doc2.md"
}
-- Create test markdown files
local file1 = io.open(test_files[1], "w")
file1:write([[
---
title: "Test Document 1"
status: "draft"
priority: "high"
tags: ["test", "urgent"]
---
# Test Document 1
This is a test document with YAML header.
]])
file1:close()
local file2 = io.open(test_files[2], "w")
file2:write([[
---
title: "Test Document 2"
status: "review"
priority: "medium"
tags: ["test", "review"]
---
# Test Document 2
Another test document.
]])
file2:close()
-- Index the documents
local result = indexer.index_documents("/tmp")
assert.is_true(result.success)
assert.are.equal(2, result.indexed_count)
-- Clean up
os.remove(test_files[1])
os.remove(test_files[2])
end)
it("should handle documents with malformed YAML headers", function()
local malformed_file = "/tmp/malformed.md"
local file = io.open(malformed_file, "w")
file:write([[
---
title: "Malformed Document"
status: "draft"
invalid_yaml: [unclosed array
---
# Malformed Document
This has bad YAML.
]])
file1:close()
local result = indexer.index_documents("/tmp")
assert.is_true(result.success)
assert.are.equal(0, result.indexed_count)
assert.is_not_nil(result.errors)
assert.are.equal(1, #result.errors)
-- Clean up
os.remove(malformed_file)
end)
it("should incrementally update index when files change", function()
local test_file = "/tmp/incremental_test.md"
-- Create initial document
local file = io.open(test_file, "w")
file:write([[
---
title: "Incremental Test"
status: "draft"
---
# Incremental Test
Initial content.
]])
file:close()
-- Initial indexing
local result1 = indexer.index_documents("/tmp")
assert.is_true(result1.success)
assert.are.equal(1, result1.indexed_count)
-- Modify the file
vim.wait(100) -- Ensure different timestamp
local file2 = io.open(test_file, "w")
file2:write([[
---
title: "Incremental Test"
status: "review"
priority: "high"
---
# Incremental Test
Modified content.
]])
file2:close()
-- Incremental update
local result2 = indexer.update_index("/tmp")
assert.is_true(result2.success)
assert.are.equal(1, result2.updated_count)
-- Clean up
os.remove(test_file)
end)
end)