Add unit tests for the useDatabase composable#28
Merged
Conversation
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]>
|
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/composables/useDatabase.ts(~459 lines, was ~3%), the composable wrapping the SQLite layer and cloud sync. Takes it to ~58% line coverage.Approach
Mocks the
dbAppDatabase singleton as aProxyof asyncvi.fns (so every thin wrapper is exercised without enumerating the whole surface) and mocksCloudSync/GoogleDriveProvider.Coverage
loadBooks/saveBook/loadChapters/saveChapter/deleteChapter— list refresh,loading/errorhandling, and rethrow-on-failure.CloudSyncand drivesprepareCloudSync/backupToCloud/restoreFromCloud.dband surfaces its result.getWikiPagesswallow-and-return-[]error path.The remaining uncovered lines are mostly the identical per-wrapper
catchbranches.Testing
npm run lint,type-check, andvitest runpass (Node 22).🤖 Generated with Claude Code