Skip to content

Add unit tests for the AppDatabase SQLite layer#23

Merged
catherineluse merged 1 commit into
mainfrom
test-database
Jul 16, 2026
Merged

Add unit tests for the AppDatabase SQLite layer#23
catherineluse merged 1 commit into
mainfrom
test-database

Conversation

@catherineluse

Copy link
Copy Markdown
Collaborator

Summary

Tests src/lib/database.ts — the largest untested module (~1300 lines, was ~1%). Adds 20 tests that drive the real AppDatabase against an in-memory sql.js database, taking it from ~1% → ~39% line coverage.

Approach

AppDatabase.init() is browser-only (loads the wasm from a URL and reads IndexedDB), so it can't run in node. Instead the harness:

  • creates an in-memory new SQL.Database() and injects it into a fresh AppDatabase,
  • calls the private createTables() + runMigrations() to build the real schema,
  • leaves the persistence coordinator null, so requestPersistence()/flushPersistence() are safe no-ops.

This exercises the actual SQL and row-mapping code, not a mock.

Coverage

CRUD round-trips for: books, chapters, parts, chapter & part summaries, reviews, chapter notes, custom reviewer profiles, wiki pages (incl. duplicate-name rejection), image assets (save/list/cover/tags/notes/delete), chapter ordering + part assignment, chapter-wiki mentions/links, and book/part/wiki cover images.

The remaining uncovered lines are largely the if (this.isNative) Capacitor SQLite branches (unreachable under sql.js) plus some import/export and search paths — candidates for a follow-up.

Testing

npm run lint, npm run type-check, and vitest run all pass (Node 22). Full suite: 183 tests across 25 files.

🤖 Generated with Claude Code

Exercises the real AppDatabase against an in-memory sql.js database
(bypassing the browser-only init: IndexedDB + wasm URL loading), with a
null persistence coordinator so mutations are safe no-ops. Covers CRUD
round-trips for books, chapters, parts, chapter/part summaries, reviews,
notes, custom reviewer profiles, wiki pages (incl. duplicate-name
rejection), image assets (save/list/cover/tags/notes/delete), chapter
ordering + part assignment, chapter-wiki mentions/links, and book/part/
wiki cover images.

database.ts goes from ~1% to ~39% line coverage (the remaining lines are
largely native-platform branches unreachable under sql.js).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-beta-reader-frontend Ready Ready Preview, Comment Jul 16, 2026 5:41am

Request Review

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@catherineluse
catherineluse merged commit 568e687 into main Jul 16, 2026
4 checks passed
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