test: Phase 2 - Create test infrastructure
- Create comprehensive test directory structure - Implement better-sqlite3 mock for Vitest - Add node factory using fishery for test data generation - Create workflow builder with fluent API - Add infrastructure validation tests - Update testing checklist to reflect progress All Phase 2 tasks completed successfully with 7 tests passing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
53
tests/unit/database/__mocks__/better-sqlite3.ts
Normal file
53
tests/unit/database/__mocks__/better-sqlite3.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { vi } from 'vitest';
|
||||
|
||||
export class MockDatabase {
|
||||
private data = new Map<string, any[]>();
|
||||
private prepared = new Map<string, any>();
|
||||
|
||||
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 };
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
exec(sql: string) {
|
||||
// Mock schema creation
|
||||
return true;
|
||||
}
|
||||
|
||||
close() {
|
||||
// Mock close
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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());
|
||||
Reference in New Issue
Block a user