fix(tests): add wsdcId cleanup to prevent unique constraint violations
Both users.test.js and auth-phase1.5.test.js were failing due to unique constraint violations on wsdc_id field when running after other test suites. Added wsdcId to cleanup queries and proper deletion of related data (messages, matches, eventParticipants).
This commit is contained in:
@@ -27,12 +27,41 @@ beforeAll(async () => {
|
|||||||
'resend@example.com', 'expired@example.com', 'reset@example.com',
|
'resend@example.com', 'expired@example.com', 'reset@example.com',
|
||||||
'newpass@example.com', 'expiredreset@example.com', 'emailfail@example.com',
|
'newpass@example.com', 'expiredreset@example.com', 'emailfail@example.com',
|
||||||
'wsdc@example.com', 'user1@example.com', 'user2@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({
|
await prisma.user.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
OR: [
|
OR: [
|
||||||
{ username: { in: testUsernames } },
|
{ 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',
|
'resend@example.com', 'expired@example.com', 'reset@example.com',
|
||||||
'newpass@example.com', 'expiredreset@example.com', 'emailfail@example.com',
|
'newpass@example.com', 'expiredreset@example.com', 'emailfail@example.com',
|
||||||
'wsdc@example.com', 'user1@example.com', 'user2@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({
|
await prisma.user.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
OR: [
|
OR: [
|
||||||
{ username: { in: testUsernames } },
|
{ username: { in: testUsernames } },
|
||||||
{ email: { in: testEmails } }
|
{ email: { in: testEmails } },
|
||||||
|
{ wsdcId: { in: testWsdcIds } }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,13 +12,15 @@ beforeAll(async () => {
|
|||||||
// Clean up only specific test data (not all tables)
|
// Clean up only specific test data (not all tables)
|
||||||
const testUsernames = ['users_john_dancer', 'users_sarah_swings'];
|
const testUsernames = ['users_john_dancer', 'users_sarah_swings'];
|
||||||
const testEmails = ['users_john@example.com', 'users_sarah@example.com'];
|
const testEmails = ['users_john@example.com', 'users_sarah@example.com'];
|
||||||
|
const testWsdcIds = ['12345'];
|
||||||
|
|
||||||
// Find test users
|
// Find test users
|
||||||
const testUsers = await prisma.user.findMany({
|
const testUsers = await prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
OR: [
|
OR: [
|
||||||
{ username: { in: testUsernames } },
|
{ username: { in: testUsernames } },
|
||||||
{ email: { in: testEmails } }
|
{ email: { in: testEmails } },
|
||||||
|
{ wsdcId: { in: testWsdcIds } }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
select: { id: true }
|
select: { id: true }
|
||||||
@@ -45,7 +47,8 @@ beforeAll(async () => {
|
|||||||
where: {
|
where: {
|
||||||
OR: [
|
OR: [
|
||||||
{ username: { in: testUsernames } },
|
{ username: { in: testUsernames } },
|
||||||
{ email: { in: testEmails } }
|
{ email: { in: testEmails } },
|
||||||
|
{ wsdcId: { in: testWsdcIds } }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -87,12 +90,14 @@ afterAll(async () => {
|
|||||||
// Clean up only specific test data
|
// Clean up only specific test data
|
||||||
const testUsernames = ['users_john_dancer', 'users_sarah_swings'];
|
const testUsernames = ['users_john_dancer', 'users_sarah_swings'];
|
||||||
const testEmails = ['users_john@example.com', 'users_sarah@example.com'];
|
const testEmails = ['users_john@example.com', 'users_sarah@example.com'];
|
||||||
|
const testWsdcIds = ['12345'];
|
||||||
|
|
||||||
const testUsers = await prisma.user.findMany({
|
const testUsers = await prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
OR: [
|
OR: [
|
||||||
{ username: { in: testUsernames } },
|
{ username: { in: testUsernames } },
|
||||||
{ email: { in: testEmails } }
|
{ email: { in: testEmails } },
|
||||||
|
{ wsdcId: { in: testWsdcIds } }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
select: { id: true }
|
select: { id: true }
|
||||||
@@ -117,7 +122,8 @@ afterAll(async () => {
|
|||||||
where: {
|
where: {
|
||||||
OR: [
|
OR: [
|
||||||
{ username: { in: testUsernames } },
|
{ username: { in: testUsernames } },
|
||||||
{ email: { in: testEmails } }
|
{ email: { in: testEmails } },
|
||||||
|
{ wsdcId: { in: testWsdcIds } }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user