test: fix backend test cleanup to preserve production data
Replace deleteMany({}) with selective cleanup targeting only test data:
- events.test.js: Delete only test users (john_dancer, sarah_swings, mike_blues)
and test events (test-dance-festival-2025) before creating new ones
- matches.test.js: Clean up john_dancer, sarah_swings, mike_moves and
test-dance-festival slug specifically
- users.test.js: Remove only john_dancer and sarah_swings test users
in both beforeAll and afterAll hooks
- auth.test.js: Target specific test usernames/emails (testuser, newuser,
lockouttest, etc.) instead of all users
- auth-phase1.5.test.js: Clean up 12 specific test users by username/email
- socket.test.js: Add beforeAll cleanup for sockettest user to prevent
conflicts from previous test runs
- socket-webrtc.test.js: Clean up webrtc_user1 and webrtc_user2 before
creating them
Fix CORS configuration for tests:
- security.js: Add http://localhost:3000 to allowed origins in development
mode to fix app.test.js CORS test (was failing with 500 error)
Results: Improved from 125/223 passing to 137/223 passing (12 more tests fixed)
All test data cleanup now uses WHERE clauses with specific usernames/emails/slugs
instead of wiping entire tables with deleteMany({})
This commit is contained in:
@@ -15,6 +15,16 @@ describe('Socket.IO Server', () => {
|
||||
const port = 3001;
|
||||
|
||||
beforeAll(async () => {
|
||||
// Clean up existing test user if any
|
||||
await prisma.user.deleteMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ username: 'sockettest' },
|
||||
{ email: 'sockettest@example.com' }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
// Create test user
|
||||
testUser = await prisma.user.create({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user