Add extensive unit tests for collection rule matching logic:
Test Coverage (30+ tests):
1. Rule Evaluation Tests:
- Equals operator (match and no match)
- Not equals operator (match and no match)
- Contains operator (case-insensitive)
- Not contains operator
- Starts with operator
- Ends with operator
- Greater than operator (numeric)
- Less than operator (numeric)
- NULL field handling
2. Comparison Function Tests:
- Case-insensitive string matching
- Empty string edge cases
- Numeric edge cases (0, negative, large numbers)
- Type conversion validation
3. Multi-Rule Tests:
- Matches first rule
- Matches second rule (first fails)
- No matches across all rules
- Empty rules array
4. Complex Rule Scenarios:
- Multiple conditions on same book
- Different field types (genre, author, year, series)
- Various operators tested
- Table-driven test for 8 scenarios
5. Edge Cases and Error Handling:
- Invalid operator returns false
- Non-existent field returns false
- Invalid numeric strings handled
- Type conversion failures
Test Structure:
- Clear test names explaining what's being tested
- Assertion messages explain expected vs actual
- Uses testify/assert for better error messages
- Table-driven tests for multiple scenarios
- Comprehensive edge case coverage
Code Coverage:
- evaluateRule() function
- compareValues() function
- checkRulesAgainstBook() function
- All operators: equals, not_equals, contains, not_contains,
starts_with, ends_with, greater_than, less_than
- All field types: genre, author, series, copyright_year
Test Results:
- All 30+ tests passing
- Coverage of critical collection rule logic
- Prevents regressions in rule matching
- Validates edge case handling
This test suite ensures the collection auto-assignment
feature works correctly for all supported rule types and operators.