tractatus/tests/unit
TheFlow 9b79c8dea3 test: increase coverage for ClaudeAPI and koha services (9% → 86%)
Major test coverage improvements for Week 1 Task 3 (PHASE-4-PREPARATION-CHECKLIST).

ClaudeAPI.service.js Coverage:
- Before: 9.41% (CRITICAL - lowest coverage in codebase)
- After: 85.88%  (exceeds 80% target)
- Tests: 34 passing
- File: tests/unit/ClaudeAPI.test.js (NEW)

Test Coverage:
- Constructor and configuration
- sendMessage() with various options
- extractTextContent() edge cases
- extractJSON() with markdown code blocks
- classifyInstruction() AI classification
- generateBlogTopics() content generation
- classifyMediaInquiry() triage system
- draftMediaResponse() AI drafting
- analyzeCaseRelevance() case study scoring
- curateResource() resource evaluation
- Error handling (network, parsing, empty responses)
- Private _makeRequest() method validation

Mocking Strategy:
- Mocked _makeRequest() to avoid real API calls
- Tested all public methods with mock responses
- Validated error paths and edge cases

koha.service.js Coverage:
- Before: 13.76% (improved from 5.79% after integration tests)
- After: 86.23%  (exceeds 80% target)
- Tests: 34 passing
- File: tests/unit/koha.service.test.js (NEW)

Test Coverage:
- createCheckoutSession() validation and Stripe calls
- handleWebhook() event routing (7 event types)
- handleCheckoutComplete() donation creation/update
- handlePaymentSuccess/Failure() status updates
- handleInvoicePaid() recurring payments
- verifyWebhookSignature() security
- getTransparencyMetrics() public data
- sendReceiptEmail() receipt generation
- cancelRecurringDonation() subscription management
- getStatistics() admin reporting

Mocking Strategy:
- Mocked Stripe SDK (customers, checkout, subscriptions, webhooks)
- Mocked Donation model (all database operations)
- Mocked currency utilities (exchange rates)
- Suppressed console output in tests

Impact:
- 2 of 4 critical services now have >80% coverage
- Added 68 comprehensive test cases
- Improved codebase reliability and maintainability
- Reduced risk for Phase 4 deployment

Remaining Coverage Targets (Task 3):
- governance.routes.js: 31.81% → 80%+ (pending)
- markdown.util.js: 17.39% → 80%+ (pending)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-09 21:17:32 +13:00
..
BoundaryEnforcer.test.js test: add comprehensive unit test suite for Tractatus governance services 2025-10-07 01:11:21 +13:00
ClaudeAPI.test.js test: increase coverage for ClaudeAPI and koha services (9% → 86%) 2025-10-09 21:17:32 +13:00
ContextPressureMonitor.test.js feat: update tests for weighted pressure scoring - 94.3% coverage achieved! 🎉 2025-10-07 10:33:42 +13:00
CrossReferenceValidator.test.js test: add comprehensive unit test suite for Tractatus governance services 2025-10-07 01:11:21 +13:00
InstructionPersistenceClassifier.test.js test: add comprehensive unit test suite for Tractatus governance services 2025-10-07 01:11:21 +13:00
koha.service.test.js test: increase coverage for ClaudeAPI and koha services (9% → 86%) 2025-10-09 21:17:32 +13:00
MetacognitiveVerifier.test.js feat: achieve 100% test coverage - MetacognitiveVerifier improvements 2025-10-07 11:03:49 +13:00