test: fix test isolation by using unique test data per suite
- Add unique prefixes to test usernames (users_, matches_, events_) - Add unique prefixes to test emails to prevent conflicts - Add unique prefixes to event slugs and worldsdc_id values - This prevents race conditions when Jest runs tests in parallel Results: - All 223 tests now passing (was 145/223) - 14/14 test suites passing (was 11/14) - Code coverage improved to 71.31% (from ~45%) Fixes: - users.test.js: Changed john_dancer → users_john_dancer - matches.test.js: Changed to matches_ prefix - events.test.js: Changed to events_ prefix + unique worldsdc_id
This commit is contained in:
@@ -13,9 +13,9 @@ let checkinToken;
|
|||||||
// Setup test data
|
// Setup test data
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Clean up only specific test data (not all tables)
|
// Clean up only specific test data (not all tables)
|
||||||
const testUsernames = ['john_dancer', 'sarah_swings', 'mike_blues'];
|
const testUsernames = ['events_john_dancer', 'events_sarah_swings', 'events_mike_blues'];
|
||||||
const testEmails = ['john@example.com', 'sarah@example.com', 'mike@example.com'];
|
const testEmails = ['events_john@example.com', 'events_sarah@example.com', 'events_mike@example.com'];
|
||||||
const testEventSlugs = ['test-dance-festival-2025', 'test-another-event-2025'];
|
const testEventSlugs = ['events-test-dance-festival-2025', 'events-test-another-event-2025'];
|
||||||
|
|
||||||
// Find test users
|
// Find test users
|
||||||
const testUsers = await prisma.user.findMany({
|
const testUsers = await prisma.user.findMany({
|
||||||
@@ -71,8 +71,8 @@ beforeAll(async () => {
|
|||||||
// Create test users
|
// Create test users
|
||||||
testUser1 = await prisma.user.create({
|
testUser1 = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
username: 'john_dancer',
|
username: 'events_john_dancer',
|
||||||
email: 'john@example.com',
|
email: 'events_john@example.com',
|
||||||
passwordHash: await hashPassword('password123'),
|
passwordHash: await hashPassword('password123'),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
firstName: 'John',
|
firstName: 'John',
|
||||||
@@ -82,8 +82,8 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
testUser2 = await prisma.user.create({
|
testUser2 = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
username: 'sarah_swings',
|
username: 'events_sarah_swings',
|
||||||
email: 'sarah@example.com',
|
email: 'events_sarah@example.com',
|
||||||
passwordHash: await hashPassword('password123'),
|
passwordHash: await hashPassword('password123'),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
firstName: 'Sarah',
|
firstName: 'Sarah',
|
||||||
@@ -93,8 +93,8 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
testUser3 = await prisma.user.create({
|
testUser3 = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
username: 'mike_blues',
|
username: 'events_mike_blues',
|
||||||
email: 'mike@example.com',
|
email: 'events_mike@example.com',
|
||||||
passwordHash: await hashPassword('password123'),
|
passwordHash: await hashPassword('password123'),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
firstName: 'Mike',
|
firstName: 'Mike',
|
||||||
@@ -135,24 +135,24 @@ beforeAll(async () => {
|
|||||||
testEvent = await prisma.event.create({
|
testEvent = await prisma.event.create({
|
||||||
data: {
|
data: {
|
||||||
name: 'Test Dance Festival 2025',
|
name: 'Test Dance Festival 2025',
|
||||||
slug: 'test-dance-festival-2025',
|
slug: 'events-test-dance-festival-2025',
|
||||||
location: 'Test City',
|
location: 'Test City',
|
||||||
startDate: new Date('2025-06-01'),
|
startDate: new Date('2025-06-01'),
|
||||||
endDate: new Date('2025-06-03'),
|
endDate: new Date('2025-06-03'),
|
||||||
description: 'Test event description',
|
description: 'Test event description',
|
||||||
worldsdcId: 'test-2025',
|
worldsdcId: 'events-test-2025',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
testEvent2 = await prisma.event.create({
|
testEvent2 = await prisma.event.create({
|
||||||
data: {
|
data: {
|
||||||
name: 'Another Dance Event',
|
name: 'Another Dance Event',
|
||||||
slug: 'another-dance-event',
|
slug: 'events-test-another-event-2025',
|
||||||
location: 'Another City',
|
location: 'Another City',
|
||||||
startDate: new Date('2025-07-15'),
|
startDate: new Date('2025-07-15'),
|
||||||
endDate: new Date('2025-07-17'),
|
endDate: new Date('2025-07-17'),
|
||||||
description: 'Another test event',
|
description: 'Another test event',
|
||||||
worldsdcId: 'another-2025',
|
worldsdcId: 'events-another-2025',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -183,9 +183,9 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
// Clean up - only delete test data, not all data
|
// Clean up - only delete test data, not all data
|
||||||
const testUsernames = ['john_dancer', 'sarah_swings', 'mike_blues'];
|
const testUsernames = ['events_john_dancer', 'events_sarah_swings', 'events_mike_blues'];
|
||||||
const testEmails = ['john@example.com', 'sarah@example.com', 'mike@example.com'];
|
const testEmails = ['events_john@example.com', 'events_sarah@example.com', 'events_mike@example.com'];
|
||||||
const testEventSlugs = ['test-dance-festival-2025', 'test-another-event-2025'];
|
const testEventSlugs = ['events-test-dance-festival-2025', 'events-test-another-event-2025'];
|
||||||
|
|
||||||
// Find test events
|
// Find test events
|
||||||
const testEvents = await prisma.event.findMany({
|
const testEvents = await prisma.event.findMany({
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ let testMatch;
|
|||||||
// Setup test data
|
// Setup test data
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Clean up only specific test data (not all tables)
|
// Clean up only specific test data (not all tables)
|
||||||
const testUsernames = ['john_dancer', 'sarah_swings', 'mike_moves'];
|
const testUsernames = ['matches_john_dancer', 'matches_sarah_swings', 'matches_mike_moves'];
|
||||||
const testEmails = ['john@example.com', 'sarah@example.com', 'mike@example.com'];
|
const testEmails = ['matches_john@example.com', 'matches_sarah@example.com', 'matches_mike@example.com'];
|
||||||
const testEventSlugs = ['test-dance-festival'];
|
const testEventSlugs = ['matches-test-dance-festival'];
|
||||||
|
|
||||||
// Find test users
|
// Find test users
|
||||||
const testUsers = await prisma.user.findMany({
|
const testUsers = await prisma.user.findMany({
|
||||||
@@ -66,8 +66,8 @@ beforeAll(async () => {
|
|||||||
// Create test users
|
// Create test users
|
||||||
testUser1 = await prisma.user.create({
|
testUser1 = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
username: 'john_dancer',
|
username: 'matches_john_dancer',
|
||||||
email: 'john@example.com',
|
email: 'matches_john@example.com',
|
||||||
passwordHash: await hashPassword('password123'),
|
passwordHash: await hashPassword('password123'),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
firstName: 'John',
|
firstName: 'John',
|
||||||
@@ -77,8 +77,8 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
testUser2 = await prisma.user.create({
|
testUser2 = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
username: 'sarah_swings',
|
username: 'matches_sarah_swings',
|
||||||
email: 'sarah@example.com',
|
email: 'matches_sarah@example.com',
|
||||||
passwordHash: await hashPassword('password123'),
|
passwordHash: await hashPassword('password123'),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
firstName: 'Sarah',
|
firstName: 'Sarah',
|
||||||
@@ -88,8 +88,8 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
testUser3 = await prisma.user.create({
|
testUser3 = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
username: 'mike_moves',
|
username: 'matches_mike_moves',
|
||||||
email: 'mike@example.com',
|
email: 'matches_mike@example.com',
|
||||||
passwordHash: await hashPassword('password123'),
|
passwordHash: await hashPassword('password123'),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
firstName: 'Mike',
|
firstName: 'Mike',
|
||||||
@@ -106,7 +106,7 @@ beforeAll(async () => {
|
|||||||
testEvent = await prisma.event.create({
|
testEvent = await prisma.event.create({
|
||||||
data: {
|
data: {
|
||||||
name: 'Test Dance Festival',
|
name: 'Test Dance Festival',
|
||||||
slug: 'test-dance-festival',
|
slug: 'matches-test-dance-festival',
|
||||||
location: 'Test City',
|
location: 'Test City',
|
||||||
startDate: new Date('2025-06-01'),
|
startDate: new Date('2025-06-01'),
|
||||||
endDate: new Date('2025-06-03'),
|
endDate: new Date('2025-06-03'),
|
||||||
@@ -127,9 +127,9 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
// Clean up - only delete test data, not all data
|
// Clean up - only delete test data, not all data
|
||||||
const testUsernames = ['john_dancer', 'sarah_swings', 'mike_moves', 'outsider'];
|
const testUsernames = ['matches_john_dancer', 'matches_sarah_swings', 'matches_mike_moves', 'matches_outsider'];
|
||||||
const testEmails = ['john@example.com', 'sarah@example.com', 'mike@example.com', 'outsider@example.com'];
|
const testEmails = ['matches_john@example.com', 'matches_sarah@example.com', 'matches_mike@example.com', 'matches_outsider@example.com'];
|
||||||
const testEventSlugs = ['test-dance-festival'];
|
const testEventSlugs = ['matches-test-dance-festival'];
|
||||||
|
|
||||||
// Find test users
|
// Find test users
|
||||||
const testUsers = await prisma.user.findMany({
|
const testUsers = await prisma.user.findMany({
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ let testToken1, testToken2;
|
|||||||
// Setup test data
|
// Setup test data
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Clean up only specific test data (not all tables)
|
// Clean up only specific test data (not all tables)
|
||||||
const testUsernames = ['john_dancer', 'sarah_swings'];
|
const testUsernames = ['users_john_dancer', 'users_sarah_swings'];
|
||||||
const testEmails = ['john@example.com', 'sarah@example.com'];
|
const testEmails = ['users_john@example.com', 'users_sarah@example.com'];
|
||||||
|
|
||||||
// Find test users
|
// Find test users
|
||||||
const testUsers = await prisma.user.findMany({
|
const testUsers = await prisma.user.findMany({
|
||||||
@@ -53,8 +53,8 @@ beforeAll(async () => {
|
|||||||
// Create test users
|
// Create test users
|
||||||
testUser1 = await prisma.user.create({
|
testUser1 = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
username: 'john_dancer',
|
username: 'users_john_dancer',
|
||||||
email: 'john@example.com',
|
email: 'users_john@example.com',
|
||||||
passwordHash: await hashPassword('password123'),
|
passwordHash: await hashPassword('password123'),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
firstName: 'John',
|
firstName: 'John',
|
||||||
@@ -69,8 +69,8 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
testUser2 = await prisma.user.create({
|
testUser2 = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
username: 'sarah_swings',
|
username: 'users_sarah_swings',
|
||||||
email: 'sarah@example.com',
|
email: 'users_sarah@example.com',
|
||||||
passwordHash: await hashPassword('password123'),
|
passwordHash: await hashPassword('password123'),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
firstName: 'Sarah',
|
firstName: 'Sarah',
|
||||||
@@ -85,8 +85,8 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
// Clean up only specific test data
|
// Clean up only specific test data
|
||||||
const testUsernames = ['john_dancer', 'sarah_swings'];
|
const testUsernames = ['users_john_dancer', 'users_sarah_swings'];
|
||||||
const testEmails = ['john@example.com', 'sarah@example.com'];
|
const testEmails = ['users_john@example.com', 'users_sarah@example.com'];
|
||||||
|
|
||||||
const testUsers = await prisma.user.findMany({
|
const testUsers = await prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in New Issue
Block a user