Skip to content

test(db,utils): add unit tests for db/client.ts and utils/logging.ts#973

Merged
aaight merged 1 commit intodevfrom
feature/unit-tests-db-client-utils-logging
Mar 21, 2026
Merged

test(db,utils): add unit tests for db/client.ts and utils/logging.ts#973
aaight merged 1 commit intodevfrom
feature/unit-tests-db-client-utils-logging

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 21, 2026

Summary

  • Extended tests/unit/db/client.test.ts with tests for getDatabaseUrl, getDb (SSL config, singleton), and closeDb — bringing db/client.ts coverage from ~62% to ~95%
  • Created tests/unit/utils/logging.test.ts for setLogLevel and getLogLevel — bringing utils/logging.ts coverage 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: returns DATABASE_URL when set; falls back to CASCADE_POSTGRES_* with defaults (port=6543, user=postgres, db=cascade); respects custom values; throws when neither set
  • getDb: creates pg.Pool with SSL disabled when DATABASE_SSL=false; uses {rejectUnauthorized:false} by default; returns singleton on repeated calls
  • closeDb: calls pool.end() and resets pool/db to null; no-op when pool is already null
  • Uses vi.hoisted() + vi.mock('pg') + vi.mock('drizzle-orm/node-postgres') to mock dependencies; vi.stubEnv() for env vars

tests/unit/utils/logging.test.ts (new)

  • setLogLevel: sets correct numeric level for each valid string; case-insensitive; ignores invalid/empty strings
  • getLogLevel: returns string name for each known numeric level; defaults to 'debug' for unknown levels; round-trips correctly after setLogLevel
  • Uses the real llmist Logger instance, saving/restoring settings.minLevel between tests

Test plan

  • All 19 new tests pass
  • Full unit suite passes: 330 files, 6220 tests, no regressions
  • Lint passes (biome check, no fixes needed)
  • Type check passes (tsc --noEmit)

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@aaight aaight merged commit e85edc1 into dev Mar 21, 2026
9 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