Skip to content

Add unit tests for the useDatabase composable#28

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

Add unit tests for the useDatabase composable#28
catherineluse merged 1 commit into
mainfrom
test-usedatabase-pr

Conversation

@catherineluse

Copy link
Copy Markdown
Collaborator

Summary

Tests src/composables/useDatabase.ts (~459 lines, was ~3%), the composable wrapping the SQLite layer and cloud sync. Takes it to ~58% line coverage.

Stacked on #26 (the flaky-test fix). Until #26 merges, this PR's diff also shows those two test-file changes; it reduces to just useDatabase.spec.ts once #26 lands.

Approach

Mocks the db AppDatabase singleton as a Proxy of async vi.fns (so every thin wrapper is exercised without enumerating the whole surface) and mocks CloudSync/GoogleDriveProvider.

Coverage

  • State management: loadBooks/saveBook/loadChapters/saveChapter/deleteChapter — list refresh, loading/error handling, and rethrow-on-failure.
  • Cloud sync: guards that throw when uninitialized; a fresh-module test with a configured client id that wires up CloudSync and drives prepareCloudSync/backupToCloud/restoreFromCloud.
  • Delegation: every remaining wrapper (summaries, reviews, notes, profiles, wiki pages, mentions/links, parts, search/replace, image assets, import) delegates to db and surfaces its result.
  • The getWikiPages swallow-and-return-[] error path.

The remaining uncovered lines are mostly the identical per-wrapper catch branches.

Testing

npm run lint, type-check, and vitest run pass (Node 22).

🤖 Generated with Claude Code

Mocks the AppDatabase singleton (a Proxy of async vi.fns) and CloudSync,
covering: book/chapter state management (load/save/delete with refresh
and error handling), cloud-sync guards (throw when uninitialized) and
the configured-client-id init path enabling backup/restore, delegation
of every thin wrapper to the database layer, and the getWikiPages
swallow-and-return-empty behavior. useDatabase.ts goes from ~3% to ~58%.

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 6:19am

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 9596d4e 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