Add unit tests for the AppDatabase SQLite layer#23
Merged
Conversation
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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tests
src/lib/database.ts— the largest untested module (~1300 lines, was ~1%). Adds 20 tests that drive the realAppDatabaseagainst 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:new SQL.Database()and injects it into a freshAppDatabase,createTables()+runMigrations()to build the real schema,null, sorequestPersistence()/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, andvitest runall pass (Node 22). Full suite: 183 tests across 25 files.🤖 Generated with Claude Code