test(db,utils): add unit tests for db/client.ts and utils/logging.ts#973
Merged
test(db,utils): add unit tests for db/client.ts and utils/logging.ts#973
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
nhopeatall
approved these changes
Mar 21, 2026
Collaborator
nhopeatall
left a comment
There was a problem hiding this comment.
LGTM — Well-structured unit tests that correctly exercise the source code paths. Mock setup with vi.hoisted() + vi.mock() is idiomatic Vitest. The resetDbState() helper properly handles the isolate: false environment by resetting module-level singletons between tests. The unstubEnvs: true config ensures env var stubs are automatically cleaned up. Assertions accurately reflect the actual implementation in db/client.ts and utils/logging.ts.
🕵️ claude-code · claude-opus-4-6 · run details
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/unit/db/client.test.tswith tests forgetDatabaseUrl,getDb(SSL config, singleton), andcloseDb— bringingdb/client.tscoverage from ~62% to ~95%tests/unit/utils/logging.test.tsforsetLogLevelandgetLogLevel— bringingutils/logging.tscoverage from 66% to 100%Trello card: https://trello.com/c/lxVqlGXo/494-as-a-developer-i-want-unit-tests-for-db-clientts-and-utils-loggingts-so-that-database-url-construction-connection-lifecycle-and
What was implemented
tests/unit/db/client.test.ts(extended)getDatabaseUrl: returnsDATABASE_URLwhen set; falls back toCASCADE_POSTGRES_*with defaults (port=6543, user=postgres, db=cascade); respects custom values; throws when neither setgetDb: createspg.Poolwith SSL disabled whenDATABASE_SSL=false; uses{rejectUnauthorized:false}by default; returns singleton on repeated callscloseDb: callspool.end()and resets pool/db to null; no-op when pool is already nullvi.hoisted()+vi.mock('pg')+vi.mock('drizzle-orm/node-postgres')to mock dependencies;vi.stubEnv()for env varstests/unit/utils/logging.test.ts(new)setLogLevel: sets correct numeric level for each valid string; case-insensitive; ignores invalid/empty stringsgetLogLevel: returns string name for each known numeric level; defaults to'debug'for unknown levels; round-trips correctly aftersetLogLevelllmistLogger instance, saving/restoringsettings.minLevelbetween testsTest plan
🤖 Generated with Claude Code
🕵️ claude-code · claude-sonnet-4-6 · run details