143 lines
3.5 KiB
Lua
143 lines
3.5 KiB
Lua
|
-- Integration tests for query workflow
|
||
|
local busted = require('busted')
|
||
|
|
||
|
describe("Query Workflow Integration", function()
|
||
|
local query_engine
|
||
|
|
||
|
before_each(function()
|
||
|
-- These modules don't exist yet - tests should fail
|
||
|
query_engine = require('notex.query')
|
||
|
end)
|
||
|
|
||
|
it("should execute end-to-end query workflow", function()
|
||
|
-- Setup test data
|
||
|
local test_documents = {
|
||
|
{
|
||
|
id = "doc1",
|
||
|
file_path = "/tmp/doc1.md",
|
||
|
properties = {
|
||
|
title = "Project Plan",
|
||
|
status = "draft",
|
||
|
priority = "high",
|
||
|
created_at = "2024-03-15T10:30:00Z"
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
id = "doc2",
|
||
|
file_path = "/tmp/doc2.md",
|
||
|
properties = {
|
||
|
title = "Meeting Notes",
|
||
|
status = "review",
|
||
|
priority = "medium",
|
||
|
created_at = "2024-03-14T15:20:00Z"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-- Initialize query engine with test data
|
||
|
query_engine.initialize(test_documents)
|
||
|
|
||
|
-- Execute query
|
||
|
local query_string = [[
|
||
|
```notex-query
|
||
|
status: "draft"
|
||
|
priority: "high"
|
||
|
ORDER BY created_at DESC
|
||
|
```
|
||
|
]]
|
||
|
local result = query_engine.execute_query(query_string)
|
||
|
|
||
|
-- Validate results
|
||
|
assert.is_not_nil(result.documents)
|
||
|
assert.are.equal(1, #result.documents)
|
||
|
assert.are.equal("Project Plan", result.documents[1].properties.title)
|
||
|
assert.are.equal("draft", result.documents[1].properties.status)
|
||
|
assert.is_true(result.execution_time_ms < 100) -- Performance requirement
|
||
|
end)
|
||
|
|
||
|
it("should handle complex queries with conditions", function()
|
||
|
local test_documents = {
|
||
|
{
|
||
|
id = "doc1",
|
||
|
properties = {
|
||
|
title = "Important Task",
|
||
|
status = "active",
|
||
|
priority = 5,
|
||
|
created_at = "2024-01-15T10:00:00Z",
|
||
|
tags = {"urgent", "project"}
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
id = "doc2",
|
||
|
properties = {
|
||
|
title = "Regular Task",
|
||
|
status = "active",
|
||
|
priority = 2,
|
||
|
created_at = "2024-02-01T14:30:00Z",
|
||
|
tags = {"routine"}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
query_engine.initialize(test_documents)
|
||
|
|
||
|
local complex_query = [[
|
||
|
```notex-query
|
||
|
FROM status: "active"
|
||
|
WHERE priority > 3 AND tags INCLUDES "urgent"
|
||
|
ORDER BY created_at DESC
|
||
|
```
|
||
|
]]
|
||
|
local result = query_engine.execute_query(complex_query)
|
||
|
|
||
|
assert.are.equal(1, #result.documents)
|
||
|
assert.are.equal("Important Task", result.documents[1].properties.title)
|
||
|
end)
|
||
|
|
||
|
it("should handle queries that return no results", function()
|
||
|
local test_documents = {
|
||
|
{
|
||
|
id = "doc1",
|
||
|
properties = {
|
||
|
title = "Document 1",
|
||
|
status = "archived"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
query_engine.initialize(test_documents)
|
||
|
|
||
|
local query = [[
|
||
|
```notex-query
|
||
|
status: "active"
|
||
|
```
|
||
|
]]
|
||
|
local result = query_engine.execute_query(query)
|
||
|
|
||
|
assert.are.equal(0, #result.documents)
|
||
|
assert.are.equal(0, result.total_count)
|
||
|
end)
|
||
|
|
||
|
it("should save and reuse queries", function()
|
||
|
local query_name = "My Active Tasks"
|
||
|
local query_definition = [[
|
||
|
```notex-query
|
||
|
status: "active"
|
||
|
priority: "high"
|
||
|
```
|
||
|
]]
|
||
|
|
||
|
-- Save query
|
||
|
local save_result = query_engine.save_query(query_name, query_definition)
|
||
|
assert.is_true(save_result.success)
|
||
|
|
||
|
-- List saved queries
|
||
|
local queries = query_engine.list_saved_queries()
|
||
|
assert.is_not_nil(queries[query_name])
|
||
|
|
||
|
-- Execute saved query
|
||
|
local result = query_engine.execute_saved_query(query_name)
|
||
|
assert.is_not_nil(result)
|
||
|
assert.is_number(result.execution_time_ms)
|
||
|
end)
|
||
|
end)
|