Skip to content

test: mock UserRepository in webuiQR unit test#1695

Merged
kaizhou-lab merged 1 commit intomainfrom
zynx/fix/webuiQR-test-mock-database
Mar 25, 2026
Merged

test: mock UserRepository in webuiQR unit test#1695
kaizhou-lab merged 1 commit intomainfrom
zynx/fix/webuiQR-test-mock-database

Conversation

@piorpua
Copy link
Copy Markdown
Contributor

@piorpua piorpua commented Mar 25, 2026

Summary

  • The verifyQRTokenDirect unit test was failing because better-sqlite3 native module was compiled for a different Node.js version, causing database initialization to throw ERR_DLOPEN_FAILED
  • Added vi.mock for UserRepository to stub getSystemUser, updateLastLogin, and updateJwtSecret, so the test runs without a real database
  • All 5 tests in webuiQR.test.ts now pass

Test plan

  • Run bun run test — 0 failures
  • Verify tests/unit/webuiQR.test.ts passes all 5 cases including "accepts a freshly generated token"

better-sqlite3 native module version mismatch causes database
initialization to fail in the test environment, making
verifyQRTokenDirect always return success=false.

Mock UserRepository.getSystemUser, updateLastLogin, and
updateJwtSecret so the test runs without a real database,
isolating the QR token logic under test.
@kaizhou-lab kaizhou-lab merged commit dcfe9f2 into main Mar 25, 2026
13 of 17 checks passed
@piorpua piorpua deleted the zynx/fix/webuiQR-test-mock-database branch March 25, 2026 03:18
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