refactor(test): migrate remaining 25 test files to createTestDb helper (#3501)#3511
Conversation
#3501) Replace hand-rolled CREATE TABLE DDL in 25 test files with the shared createTestDb() helper, which runs the real migration registry against an in-memory SQLite database. Schema changes now only need a single edit instead of updates scattered across every test file that builds its own schema. Key fixes discovered during migration: - Settings table requires createdAt/updatedAt (NOT NULL from baseline 001) - Traceroutes require fromNodeId/toNodeId TEXT NOT NULL columns - packet_log.encrypted is integer NOT NULL (boolean mode) - ignored_nodes FK to sources(id) requires seeding sources rows first (better-sqlite3 defaults foreign_keys=ON on this system) - Migration 050 seeds a default source on fresh empty DBs; sources.test.ts clears it in beforeEach so tests control exactly which sources exist - push_subscriptions composite unique index (user_id, endpoint, source_id) does not fire with NULL user_id in SQLite — tests use a real user id - user_notification_preferences defaults: enable_apprise=1, enable_web_push=1 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
origin/main removed the test-only upsertChannel fixture (DatabaseService .upsertChannel was deleted in #3503). Accept that deletion, keep getChannelById(id) without the sourceId param that our branch had added. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(test): migrate remaining 25 test files to createTestDb helperTasks:
Overall AssessmentThis is a well-executed refactor with a clear, well-motivated goal. The Positive Highlights
Issues / Observations1. The This is pre-existing and outside the stated scope of the PR (which only targets DDL), but worth flagging so it doesn't get lost. 2. Several tests in the 3. The filtering logic tests (lines 190–278) don't import or call anything from the service; they inline the same logic as plain arithmetic/string operations. As with point 2, these pass vacuously. Not introduced by this PR, but visible now that the schema setup is correct. 4.
it('includes columns added by recent migrations (e.g. telemetry.rxSnr — migration 089)', () => {The CLAUDE.md states the current migration count is 84 ( 5. Line 396: void schema;This was apparently added to suppress a "dead import" lint warning on the 6. Lines 22-31 insert directly via Minor Nits
SummaryThe migration is correct, the helper is well-designed, and the schema drift fixes are a genuine improvement in test reliability. The issues noted (vacuous tests, stale comment, |
…nnels tests PostgreSQL lowercases unquoted identifiers, so `createdAt` becomes `createdat` (column not found). Use dialect-specific quoting: double- quotes for PostgreSQL, unquoted for SQLite/MySQL (which are case- insensitive or backtick-users respectively). Also resolves the merge conflict in database.test.ts that landed in the previous commit (upsertChannel was removed in #3503 on main). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(test): migrate remaining 25 test files to createTestDb helperTasks:
Overall AssessmentThis is a well-executed, high-value refactor. Migrating 25 test files from hand-rolled DDL to the shared
|
Summary
CREATE TABLEDDL to the sharedcreateTestDb()helper, which runs the real migration registry on an in-memory SQLite databaseFiles changed
All 25 files in
src/db/repositories/,src/server/services/, andsrc/services/that had hand-rolled SQLiteCREATE TABLEDDL.Schema drift fixes found during migration
The migration uncovered several places where test schemas had drifted from production:
settingstable requirescreatedAt/updatedAtNOT NULL (from baseline 001)traceroutesrequiresfromNodeId/toNodeId TEXT NOT NULLcolumnspacket_log.encryptedisinteger NOT NULL(boolean mode)ignored_nodeshas an FK tosources(id)— tests must seedsourcesrows first (better-sqlite3 defaultsforeign_keys=ON)sources.test.tsnow clears it inbeforeEachpush_subscriptionscomposite unique index(user_id, endpoint, source_id)doesn't fire with NULLuser_idin SQLite — uniqueness test now uses a real user iduser_notification_preferencesschema defaults:enable_apprise=1,enable_web_push=1(not 0)Test plan
npm run typecheckpasses clean🤖 Generated with Claude Code