Skip to content

Refactor: extract findUserOrThrow in AuthService, drop dead test vars - #101

Merged
buzz-code merged 1 commit into
mainfrom
claude/refactor-debt-2026-11-14
Nov 14, 2026
Merged

buzz-code merged 1 commit into
mainfrom
claude/refactor-debt-2026-11-14

Conversation

@buzz-code

Copy link
Copy Markdown
Owner

Part of buzz-code/ops#60

Scope

Weekly behavior-preserving tech-debt pass. Focus: code changed since 2026-11-07 (auth, jobs, mcp, report/PDF, s3, logging). No API, DTO, entity or schema change; no consumer action needed (no CONSUMER_CHANGES.md row).

Changes

  • auth/auth.service.ts: getProfile, updateSettings and updateProfile each repeated the same findOneBy({ id }) + throw new Error('User not found') block. Moved into a private findUserOrThrow(userId). Same query, same error.
  • utils/report/markup-to-pdf.generator.ts: typed the standalone browser variable (let browser: Browser | undefined), was implicit any.
  • base-entity/__tests__/base-entity.service.spec.ts: removed an unused options object.
  • utils/report/__tests__/pdf-render.scope.spec.ts: removed an unused result variable (call still awaited).

Helper added

  • AuthService.findUserOrThrow(userId: number): Promise<User> (private, auth/auth.service.ts): load a user by id or throw User not found.

Not changed

  • Narrowing AuthService.validateUser / registerUser return types from Promise<any> to IAuthenticatedUser: tried, but it breaks existing test mocks (and likely consumer mocks), so left as is.
  • app/__tests__/base-app.module.spec.ts: DefaultUserInitModule is required but never asserted. Fixing it would mean changing what the test checks, so left out of this pass.

Tests

Run in consumer layout (server/shared), same as CI:

  • Before: yarn test 95 suites / 904 tests passed; tsc --noEmit clean.
  • After: yarn test 95 suites / 904 tests passed; tsc --noEmit clean; --noUnusedLocals shows only the test var noted above.

Generated by Claude Code

- AuthService: getProfile, updateSettings and updateProfile each repeated
  the same find-by-id + "User not found" check; move it into a private
  findUserOrThrow helper. Same query, same error.
- MarkupToPdfReportGenerator: type the standalone browser variable.
- Tests: remove an unused options object and an unused result variable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012GTictqecCYiBSiCMj1RKN
@buzz-code
buzz-code merged commit 573f3ee into main Nov 14, 2026
1 check 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