JamesReviewsMusic
JRM-6Stop the test suite from truncating whatever DB it's pointed at
Description
The backend tests call resetTables (backend/src/tests/testUtils.ts), which runs TRUNCATE ... CASCADE on every table using whatever DATABASE_URL is set in the environment. There's no check at all, and DATABASE_URL_PROD lives in the same .env file. One wrong value and running pnpm test empties the production database.
- Introduce a dedicated
TEST_DATABASE_URLthat the test setup uses, and refuse to runresetTablesagainst anything else - As a second layer, bail out unless
NODE_ENVis "test" - Update the jest setup and docs/scripts so tests still run with one command
Sub-tickets
0No sub-tickets yet.
Links
No links.
Summary
backend/src/config/database.tswith aresolveDatabaseURL()helper which returnsDATABASE_URL_TESTunderNODE_ENV=testor elseDATABASE_URL.dbinindex.ts(every controller), thepgpool indb.ts(the test query runner), anddrizzle.config.ts.jest.setup.tsand switchedjest.config.tssetupFilesto it, forcingNODE_ENV=testso the resolver and guard always see a test environment.resetTablesintestUtils.ts: refuses to run unlessNODE_ENV=testandDATABASE_URL_TESTis set.resetTables.test.ts.db:push:testto backend's package.json.album-reviews-test-dbinstead of the live dev DB, so a normalpnpm testno longer wipes real data.