test: add comprehensive unit tests for database, parsers, loaders, and MCP tools

- Database layer tests (32 tests):
  - node-repository.ts: 100% coverage
  - template-repository.ts: 80.31% coverage
  - database-adapter.ts: interface compliance tests

- Parser tests (99 tests):
  - node-parser.ts: 93.10% coverage
  - property-extractor.ts: 95.18% coverage
  - simple-parser.ts: 91.26% coverage
  - Fixed parser bugs for version extraction

- Loader tests (22 tests):
  - node-loader.ts: comprehensive mocking tests

- MCP tools tests (85 tests):
  - tools.ts: 100% coverage
  - tools-documentation.ts: 100% coverage
  - docs-mapper.ts: 100% coverage

Total: 943 tests passing across 32 test files
Significant progress from 2.45% to ~30% overall coverage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-07-28 20:16:38 +02:00
parent 48219fb860
commit d870d0ab71
16 changed files with 5077 additions and 21 deletions

View File

@@ -3,6 +3,7 @@ import { vi } from 'vitest';
export class MockDatabase {
private data = new Map<string, any[]>();
private prepared = new Map<string, any>();
public inTransaction = false;
constructor() {
this.data.set('nodes', []);
@@ -24,7 +25,18 @@ export class MockDatabase {
items.push(params);
this.data.set(key, items);
return { changes: 1, lastInsertRowid: items.length };
})
}),
iterate: vi.fn(function* () {
const items = this.data.get(key) || [];
for (const item of items) {
yield item;
}
}),
pluck: vi.fn(function() { return this; }),
expand: vi.fn(function() { return this; }),
raw: vi.fn(function() { return this; }),
columns: vi.fn(() => []),
bind: vi.fn(function() { return this; })
};
}
@@ -38,6 +50,26 @@ export class MockDatabase {
return true;
}
pragma(key: string, value?: any) {
// Mock pragma
if (key === 'journal_mode' && value === 'WAL') {
return 'wal';
}
return null;
}
transaction<T>(fn: () => T): T {
this.inTransaction = true;
try {
const result = fn();
this.inTransaction = false;
return result;
} catch (error) {
this.inTransaction = false;
throw error;
}
}
// Helper to extract table name from SQL
private extractTableName(sql: string): string {
const match = sql.match(/FROM\s+(\w+)|INTO\s+(\w+)|UPDATE\s+(\w+)/i);