Major improvements based on comprehensive test suite review: Test Fixes: - Fix all 78 failing tests across logger, MSW, and validator tests - Fix console spy management in logger tests with proper DEBUG env handling - Fix MSW test environment restoration in session-management.test.ts - Fix workflow validator tests by adding proper node connections - Fix mock setup issues in edge case tests Test Organization: - Split large config-validator.test.ts (1,075 lines) into 4 focused files - Rename 63+ tests to follow "should X when Y" naming convention - Add comprehensive edge case test files for all major validators - Create tests/README.md with testing guidelines and best practices New Features: - Add ConfigValidator.validateBatch() method for bulk validation - Add edge case coverage for null/undefined, boundaries, invalid data - Add CI-aware performance test timeouts - Add JSDoc comments to test utilities and factories - Add workflow duplicate node name validation tests Results: - All tests passing: 1,356 passed, 19 skipped - Test coverage: 85.34% statements, 85.3% branches - From 78 failures to 0 failures 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Database Layer Unit Tests
This directory contains comprehensive unit tests for the database layer components of n8n-mcp.
Test Coverage
node-repository.ts - 100% Coverage ✅
saveNodemethod with JSON serializationgetNodemethod with JSON deserializationgetAIToolsmethodsafeJsonParseprivate method- Edge cases: large JSON, boolean conversion, invalid JSON handling
template-repository.ts - 80.31% Coverage ✅
- FTS5 initialization and fallback
saveTemplatewith sanitizationgetTemplateandgetTemplatesByNodessearchTemplateswith FTS5 and LIKE fallbackgetTemplatesForTaskwith task mapping- Template statistics and maintenance operations
- Uncovered: Some error paths in FTS5 operations
database-adapter.ts - Tested via Mocks
- Interface compliance tests
- PreparedStatement implementation
- Transaction support
- FTS5 detection logic
- Error handling patterns
Test Strategy
The tests use a mock-based approach to:
- Isolate database operations from actual database dependencies
- Test business logic without requiring real SQLite/sql.js
- Ensure consistent test execution across environments
- Focus on behavior rather than implementation details
Key Test Files
node-repository-core.test.ts- Core NodeRepository functionalitytemplate-repository-core.test.ts- Core TemplateRepository functionalitydatabase-adapter-unit.test.ts- DatabaseAdapter interface and patterns
Running Tests
# Run all database tests
npm test -- tests/unit/database/
# Run with coverage
npm run test:coverage -- tests/unit/database/
# Run specific test file
npm test -- tests/unit/database/node-repository-core.test.ts
Mock Infrastructure
The tests use custom mock implementations:
MockDatabaseAdapter- Simulates database operationsMockPreparedStatement- Simulates SQL statement execution- Mock logger and template sanitizer for external dependencies
This approach ensures tests are fast, reliable, and maintainable.