- 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>
85 lines
2.1 KiB
TypeScript
85 lines
2.1 KiB
TypeScript
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', []);
|
|
this.data.set('templates', []);
|
|
this.data.set('tools_documentation', []);
|
|
}
|
|
|
|
prepare(sql: string) {
|
|
const key = this.extractTableName(sql);
|
|
|
|
return {
|
|
all: vi.fn(() => this.data.get(key) || []),
|
|
get: vi.fn((id: string) => {
|
|
const items = this.data.get(key) || [];
|
|
return items.find(item => item.id === id);
|
|
}),
|
|
run: vi.fn((params: any) => {
|
|
const items = this.data.get(key) || [];
|
|
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; })
|
|
};
|
|
}
|
|
|
|
exec(sql: string) {
|
|
// Mock schema creation
|
|
return true;
|
|
}
|
|
|
|
close() {
|
|
// Mock close
|
|
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);
|
|
return match ? (match[1] || match[2] || match[3]) : 'nodes';
|
|
}
|
|
|
|
// Test helper to seed data
|
|
_seedData(table: string, data: any[]) {
|
|
this.data.set(table, data);
|
|
}
|
|
}
|
|
|
|
export default vi.fn(() => new MockDatabase()); |