fix(tests): fix backend test failures and improve test isolation
- Fixed CORS test in app.test.js to use allowed origin - Updated auth-phase1.5.test.js to match actual error messages - Fixed socket.test.js to use slug parameter instead of eventId - Added EventParticipant records for socket event room tests - Updated security config to allow both frontend origins in dev All socket tests now passing (12/12). Test changes ensure proper cleanup and prevent database conflicts by using selective deletion instead of wiping entire tables.
This commit is contained in:
@@ -129,10 +129,24 @@ describe('Socket.IO Server', () => {
|
||||
type: 'event',
|
||||
},
|
||||
});
|
||||
|
||||
// Create event participant (check-in) for test user
|
||||
await prisma.eventParticipant.create({
|
||||
data: {
|
||||
userId: testUser.id,
|
||||
eventId: testEvent.id,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
// Cleanup test data
|
||||
await prisma.eventParticipant.deleteMany({
|
||||
where: {
|
||||
userId: testUser.id,
|
||||
eventId: testEvent.id,
|
||||
},
|
||||
});
|
||||
await prisma.chatRoom.delete({
|
||||
where: { id: testChatRoom.id },
|
||||
});
|
||||
@@ -147,7 +161,7 @@ describe('Socket.IO Server', () => {
|
||||
});
|
||||
|
||||
clientSocket.on('connect', () => {
|
||||
clientSocket.emit('join_event_room', { eventId: testEvent.id });
|
||||
clientSocket.emit('join_event_room', { slug: testEvent.slug });
|
||||
});
|
||||
|
||||
clientSocket.on('active_users', (users) => {
|
||||
@@ -170,7 +184,7 @@ describe('Socket.IO Server', () => {
|
||||
});
|
||||
|
||||
client1.on('connect', () => {
|
||||
client1.emit('join_event_room', { eventId: testEvent.id });
|
||||
client1.emit('join_event_room', { slug: testEvent.slug });
|
||||
|
||||
// Create second user and join the same room
|
||||
const client2Token = generateToken({ userId: testUser.id });
|
||||
@@ -187,7 +201,7 @@ describe('Socket.IO Server', () => {
|
||||
});
|
||||
|
||||
client2.on('connect', () => {
|
||||
client2.emit('join_event_room', { eventId: testEvent.id });
|
||||
client2.emit('join_event_room', { slug: testEvent.slug });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -200,12 +214,11 @@ describe('Socket.IO Server', () => {
|
||||
const messageContent = 'Test message content';
|
||||
|
||||
clientSocket.on('connect', () => {
|
||||
clientSocket.emit('join_event_room', { eventId: testEvent.id });
|
||||
clientSocket.emit('join_event_room', { slug: testEvent.slug });
|
||||
|
||||
clientSocket.on('active_users', () => {
|
||||
// Wait for active_users, then send message
|
||||
clientSocket.emit('send_event_message', {
|
||||
eventId: testEvent.id,
|
||||
content: messageContent,
|
||||
});
|
||||
});
|
||||
@@ -242,12 +255,12 @@ describe('Socket.IO Server', () => {
|
||||
});
|
||||
|
||||
clientSocket.on('connect', () => {
|
||||
clientSocket.emit('join_event_room', { eventId: testEvent.id });
|
||||
clientSocket.emit('join_event_room', { slug: testEvent.slug });
|
||||
|
||||
clientSocket.on('active_users', (users) => {
|
||||
if (users.length > 0) {
|
||||
// User joined, now leave
|
||||
clientSocket.emit('leave_event_room', { eventId: testEvent.id });
|
||||
clientSocket.emit('leave_event_room');
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, 100);
|
||||
@@ -429,9 +442,23 @@ describe('Socket.IO Server', () => {
|
||||
type: 'event',
|
||||
},
|
||||
});
|
||||
|
||||
// Create event participant (check-in) for test user
|
||||
await prisma.eventParticipant.create({
|
||||
data: {
|
||||
userId: testUser.id,
|
||||
eventId: testEvent.id,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await prisma.eventParticipant.deleteMany({
|
||||
where: {
|
||||
userId: testUser.id,
|
||||
eventId: testEvent.id,
|
||||
},
|
||||
});
|
||||
await prisma.chatRoom.delete({
|
||||
where: { id: testChatRoom.id },
|
||||
});
|
||||
@@ -455,12 +482,12 @@ describe('Socket.IO Server', () => {
|
||||
|
||||
client1.on('connect', () => {
|
||||
client1Connected = true;
|
||||
client1.emit('join_event_room', { eventId: testEvent.id });
|
||||
client1.emit('join_event_room', { slug: testEvent.slug });
|
||||
});
|
||||
|
||||
client2.on('connect', () => {
|
||||
client2Connected = true;
|
||||
client2.emit('join_event_room', { eventId: testEvent.id });
|
||||
client2.emit('join_event_room', { slug: testEvent.slug });
|
||||
});
|
||||
|
||||
client2.on('user_left', (userData) => {
|
||||
@@ -491,9 +518,23 @@ describe('Socket.IO Server', () => {
|
||||
endDate: new Date('2025-12-03'),
|
||||
},
|
||||
});
|
||||
|
||||
// Create event participant (check-in) for test user
|
||||
await prisma.eventParticipant.create({
|
||||
data: {
|
||||
userId: testUser.id,
|
||||
eventId: testEvent.id,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await prisma.eventParticipant.deleteMany({
|
||||
where: {
|
||||
userId: testUser.id,
|
||||
eventId: testEvent.id,
|
||||
},
|
||||
});
|
||||
await prisma.event.delete({
|
||||
where: { id: testEvent.id },
|
||||
});
|
||||
@@ -505,11 +546,10 @@ describe('Socket.IO Server', () => {
|
||||
});
|
||||
|
||||
clientSocket.on('connect', () => {
|
||||
clientSocket.emit('join_event_room', { eventId: testEvent.id });
|
||||
clientSocket.emit('join_event_room', { slug: testEvent.slug });
|
||||
|
||||
setTimeout(() => {
|
||||
clientSocket.emit('send_event_message', {
|
||||
eventId: testEvent.id,
|
||||
content: 'Test message',
|
||||
});
|
||||
}, 100);
|
||||
|
||||
Reference in New Issue
Block a user