Skip to content

Fix: DNF books not appearing in library filter#418

Merged
masonfox merged 1 commit into
developfrom
fix/dnf-filter-bug
Apr 16, 2026
Merged

Fix: DNF books not appearing in library filter#418
masonfox merged 1 commit into
developfrom
fix/dnf-filter-bug

Conversation

@masonfox

Copy link
Copy Markdown
Owner

Summary

Fixes critical bug where books with DNF (Did Not Finish) status were not showing up when filtering by status on the library page.

Root Cause

The book repository was incorrectly treating DNF status like active statuses (reading, to-read, read-next) by requiring is_active = 1. However, DNF is a terminal/completed state like "read", where sessions are archived with is_active = 0.

Before: DNF filter returned 0 books despite 3 DNF books existing in the database
After: DNF filter correctly returns all 3 DNF books

Changes

Repository Logic (lib/repositories/book.repository.ts)

  • Updated findWithFilters() to treat 'dnf' status like 'read' status (lines 377-380)
  • Updated findWithFiltersAndRelations() to treat 'dnf' status like 'read' status (lines 754-757)
  • Terminal states (read, dnf) now include all sessions regardless of is_active
  • Active states (reading, to-read, read-next) still require is_active = 1

Test Coverage (__tests__/integration/repositories/books/book-status-filtering.test.ts)

Added 9 comprehensive tests covering:

  • ✅ DNF status filtering (terminal state)
  • ✅ Read status filtering (terminal state)
  • ✅ Active status filtering (reading, to-read, read-next)
  • ✅ Books with multiple sessions (DNF + active)
  • ✅ Both findWithFilters() and findWithFiltersAndRelations() methods

Testing

  • All 4,022 existing tests pass ✅
  • 9 new tests added for status filtering ✅
  • Verified via API: /api/books?status=dnf returns 3 books ✅
  • Confirmed database has 3 DNF sessions with is_active = 0

Impact

  • Users can now filter for DNF books on the library page
  • Fixes incorrect behavior where terminal states were treated as active states
  • No breaking changes to other status filters

Database Evidence

-- Before fix: 3 DNF sessions exist with is_active = 0
sqlite> SELECT status, is_active, COUNT(*) FROM reading_sessions 
        GROUP BY status, is_active;
dnf|0|3
read|0|66
read|1|2
read-next|1|35
reading|1|3
to-read|1|915

Related Files

  • lib/repositories/book.repository.ts (2 locations updated)
  • __tests__/integration/repositories/books/book-status-filtering.test.ts (new file)

Fixed critical bug where books with DNF status were not showing up when
filtering by status on the library page.

Root Cause:
The book repository was treating DNF status like active statuses (reading,
to-read, read-next) by requiring is_active = 1. However, DNF is a terminal
state like 'read', where sessions are archived with is_active = 0.

Changes:
- Updated findWithFilters() to treat 'dnf' status like 'read' status
- Updated findWithFiltersAndRelations() to treat 'dnf' status like 'read'
- Added comprehensive test coverage for status filtering including DNF

Impact:
- Users can now filter for DNF books on the library page
- All 3 DNF books in database now appear in filter results
- Terminal states (read, dnf) properly include all sessions
- Active states (reading, to-read, read-next) still require active sessions

Tests:
- Created book-status-filtering.test.ts with 9 new tests
- All 4022 existing tests pass
- Verified fix via API: /api/books?status=dnf returns 3 books

Locations:
- lib/repositories/book.repository.ts lines 377-380
- lib/repositories/book.repository.ts lines 754-757
@codecov

codecov Bot commented Apr 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #418      +/-   ##
===========================================
+ Coverage    78.67%   78.70%   +0.02%     
===========================================
  Files          167      167              
  Lines         7559     7559              
  Branches      1850     1850              
===========================================
+ Hits          5947     5949       +2     
  Misses        1127     1127              
+ Partials       485      483       -2     
Flag Coverage Δ
unittests 78.70% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
lib/repositories/book.repository.ts 64.24% <100.00%> (+0.63%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@masonfox

Copy link
Copy Markdown
Owner Author

@copilot review this PR

Copilot AI commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

@copilot review this PR

Reviewed. I ran targeted validation for this fix and automated PR/security review; the DNF status filter tests pass (9/9) and no additional code changes are required for this PR. Current commit: b860fb6.

@masonfox masonfox merged commit d294877 into develop Apr 16, 2026
5 checks passed
@masonfox masonfox deleted the fix/dnf-filter-bug branch April 16, 2026 12:22
This was referenced Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants