diff --git a/backend/src/__tests__/auth-phase1.5.test.js b/backend/src/__tests__/auth-phase1.5.test.js index 146e5d5..c88f5a0 100644 --- a/backend/src/__tests__/auth-phase1.5.test.js +++ b/backend/src/__tests__/auth-phase1.5.test.js @@ -27,12 +27,41 @@ beforeAll(async () => { 'resend@example.com', 'expired@example.com', 'reset@example.com', 'newpass@example.com', 'expiredreset@example.com', 'emailfail@example.com', 'wsdc@example.com', 'user1@example.com', 'user2@example.com']; + const testWsdcIds = ['26997', '12345']; + + // Find test users + const testUsers = await prisma.user.findMany({ + where: { + OR: [ + { username: { in: testUsernames } }, + { email: { in: testEmails } }, + { wsdcId: { in: testWsdcIds } } + ] + }, + select: { id: true } + }); + const testUserIds = testUsers.map(u => u.id); + + // Delete related data for test users only + if (testUserIds.length > 0) { + await prisma.message.deleteMany({ where: { userId: { in: testUserIds } } }); + await prisma.match.deleteMany({ + where: { + OR: [ + { user1Id: { in: testUserIds } }, + { user2Id: { in: testUserIds } } + ] + } + }); + await prisma.eventParticipant.deleteMany({ where: { userId: { in: testUserIds } } }); + } await prisma.user.deleteMany({ where: { OR: [ { username: { in: testUsernames } }, - { email: { in: testEmails } } + { email: { in: testEmails } }, + { wsdcId: { in: testWsdcIds } } ] } }); @@ -47,12 +76,41 @@ afterAll(async () => { 'resend@example.com', 'expired@example.com', 'reset@example.com', 'newpass@example.com', 'expiredreset@example.com', 'emailfail@example.com', 'wsdc@example.com', 'user1@example.com', 'user2@example.com']; + const testWsdcIds = ['26997', '12345']; + + // Find test users + const testUsers = await prisma.user.findMany({ + where: { + OR: [ + { username: { in: testUsernames } }, + { email: { in: testEmails } }, + { wsdcId: { in: testWsdcIds } } + ] + }, + select: { id: true } + }); + const testUserIds = testUsers.map(u => u.id); + + // Delete related data for test users only + if (testUserIds.length > 0) { + await prisma.message.deleteMany({ where: { userId: { in: testUserIds } } }); + await prisma.match.deleteMany({ + where: { + OR: [ + { user1Id: { in: testUserIds } }, + { user2Id: { in: testUserIds } } + ] + } + }); + await prisma.eventParticipant.deleteMany({ where: { userId: { in: testUserIds } } }); + } await prisma.user.deleteMany({ where: { OR: [ { username: { in: testUsernames } }, - { email: { in: testEmails } } + { email: { in: testEmails } }, + { wsdcId: { in: testWsdcIds } } ] } }); diff --git a/backend/src/__tests__/users.test.js b/backend/src/__tests__/users.test.js index a4b7720..58df0f3 100644 --- a/backend/src/__tests__/users.test.js +++ b/backend/src/__tests__/users.test.js @@ -12,13 +12,15 @@ beforeAll(async () => { // Clean up only specific test data (not all tables) const testUsernames = ['users_john_dancer', 'users_sarah_swings']; const testEmails = ['users_john@example.com', 'users_sarah@example.com']; + const testWsdcIds = ['12345']; // Find test users const testUsers = await prisma.user.findMany({ where: { OR: [ { username: { in: testUsernames } }, - { email: { in: testEmails } } + { email: { in: testEmails } }, + { wsdcId: { in: testWsdcIds } } ] }, select: { id: true } @@ -45,7 +47,8 @@ beforeAll(async () => { where: { OR: [ { username: { in: testUsernames } }, - { email: { in: testEmails } } + { email: { in: testEmails } }, + { wsdcId: { in: testWsdcIds } } ] } }); @@ -87,12 +90,14 @@ afterAll(async () => { // Clean up only specific test data const testUsernames = ['users_john_dancer', 'users_sarah_swings']; const testEmails = ['users_john@example.com', 'users_sarah@example.com']; + const testWsdcIds = ['12345']; const testUsers = await prisma.user.findMany({ where: { OR: [ { username: { in: testUsernames } }, - { email: { in: testEmails } } + { email: { in: testEmails } }, + { wsdcId: { in: testWsdcIds } } ] }, select: { id: true } @@ -117,7 +122,8 @@ afterAll(async () => { where: { OR: [ { username: { in: testUsernames } }, - { email: { in: testEmails } } + { email: { in: testEmails } }, + { wsdcId: { in: testWsdcIds } } ] } });