diff --git a/backend/src/__tests__/cli.test.js b/backend/src/__tests__/cli.test.js index e5d1949..2f66ef2 100644 --- a/backend/src/__tests__/cli.test.js +++ b/backend/src/__tests__/cli.test.js @@ -7,8 +7,10 @@ const { cmdEventsParticipants, cmdMatchesList, } = require('../cli/index'); +const { MATCH_STATUS } = require('../constants'); jest.mock('../utils/db', () => { + const { MATCH_STATUS } = require('../constants'); const mock = { user: { findMany: jest.fn().mockResolvedValue([ @@ -64,7 +66,7 @@ jest.mock('../utils/db', () => { }, match: { findMany: jest.fn().mockResolvedValue([ - { id: 301, slug: 'm1', status: 'pending', createdAt: new Date('2025-05-01'), event: { id: 200, slug: 'warsaw-dance-2025', name: 'Warsaw Dance 2025' }, user1: { id: 10, username: 'john_doe' }, user2: { id: 11, username: 'sarah' } }, + { id: 301, slug: 'm1', status: MATCH_STATUS.PENDING, createdAt: new Date('2025-05-01'), event: { id: 200, slug: 'warsaw-dance-2025', name: 'Warsaw Dance 2025' }, user1: { id: 10, username: 'john_doe' }, user2: { id: 11, username: 'sarah' } }, ]), }, }; diff --git a/backend/src/__tests__/dashboard.test.js b/backend/src/__tests__/dashboard.test.js index d6f3a43..28f30a9 100644 --- a/backend/src/__tests__/dashboard.test.js +++ b/backend/src/__tests__/dashboard.test.js @@ -9,6 +9,7 @@ const request = require('supertest'); const app = require('../app'); const { PrismaClient } = require('@prisma/client'); const { generateToken } = require('../utils/auth'); +const { MATCH_STATUS } = require('../constants'); const prisma = new PrismaClient(); @@ -238,7 +239,7 @@ describe('Dashboard API', () => { user2Id: testUser2.id, eventId: testEvent.id, roomId: matchRoom.id, - status: 'accepted', + status: MATCH_STATUS.ACCEPTED, }, }); @@ -262,7 +263,7 @@ describe('Dashboard API', () => { id: testEvent.id, name: testEvent.name, }, - status: 'accepted', + status: MATCH_STATUS.ACCEPTED, }); }); @@ -344,7 +345,7 @@ describe('Dashboard API', () => { user1Id: testUser2.id, user2Id: testUser.id, eventId: testEvent.id, - status: 'pending', + status: MATCH_STATUS.PENDING, }, }); @@ -388,7 +389,7 @@ describe('Dashboard API', () => { user1Id: testUser.id, user2Id: testUser3.id, eventId: testEvent.id, - status: 'pending', + status: MATCH_STATUS.PENDING, }, }); @@ -473,7 +474,7 @@ describe('Dashboard API', () => { where: { user1Id: testUser.id, user2Id: testUser2.id, - status: 'accepted', + status: MATCH_STATUS.ACCEPTED, }, include: { room: true }, }); diff --git a/backend/src/__tests__/socket-webrtc.test.js b/backend/src/__tests__/socket-webrtc.test.js index 19a65a1..b133eaf 100644 --- a/backend/src/__tests__/socket-webrtc.test.js +++ b/backend/src/__tests__/socket-webrtc.test.js @@ -4,6 +4,7 @@ const { Server } = require('socket.io'); const Client = require('socket.io-client'); const { generateToken } = require('../utils/auth'); const { prisma } = require('../utils/db'); +const { MATCH_STATUS } = require('../constants'); describe('Socket.IO WebRTC Signaling', () => { let httpServer; @@ -71,7 +72,7 @@ describe('Socket.IO WebRTC Signaling', () => { user2Id: testUser2.id, eventId: testEvent.id, roomId: chatRoom.id, - status: 'accepted', + status: MATCH_STATUS.ACCEPTED, }, }); @@ -209,7 +210,7 @@ describe('Socket.IO WebRTC Signaling', () => { user2Id: testUser2.id, // Both same user eventId: testEvent.id, roomId: unauthorizedRoom.id, - status: 'accepted', + status: MATCH_STATUS.ACCEPTED, }, }); diff --git a/backend/src/constants/index.js b/backend/src/constants/index.js new file mode 100644 index 0000000..7d106fc --- /dev/null +++ b/backend/src/constants/index.js @@ -0,0 +1,6 @@ +const { MATCH_STATUS, SUGGESTION_STATUS } = require('./statuses'); + +module.exports = { + MATCH_STATUS, + SUGGESTION_STATUS, +}; diff --git a/backend/src/constants/statuses.js b/backend/src/constants/statuses.js new file mode 100644 index 0000000..429bb0c --- /dev/null +++ b/backend/src/constants/statuses.js @@ -0,0 +1,24 @@ +/** + * Match status constants + */ +const MATCH_STATUS = { + PENDING: 'pending', + ACCEPTED: 'accepted', + REJECTED: 'rejected', + COMPLETED: 'completed', +}; + +/** + * Suggestion status constants (for auto-matching) + */ +const SUGGESTION_STATUS = { + PENDING: 'pending', + ACCEPTED: 'accepted', + REJECTED: 'rejected', + NOT_FOUND: 'not_found', +}; + +module.exports = { + MATCH_STATUS, + SUGGESTION_STATUS, +}; diff --git a/backend/src/routes/dashboard.js b/backend/src/routes/dashboard.js index 45cad1a..b2e4078 100644 --- a/backend/src/routes/dashboard.js +++ b/backend/src/routes/dashboard.js @@ -8,6 +8,7 @@ const router = express.Router(); const { authenticate } = require('../middleware/auth'); const { PrismaClient } = require('@prisma/client'); const { getEventsOnlineCounts } = require('../socket'); +const { MATCH_STATUS } = require('../constants'); const prisma = new PrismaClient(); @@ -101,7 +102,7 @@ router.get('/', authenticate, async (req, res, next) => { { user1Id: userId }, { user2Id: userId }, ], - status: 'accepted', + status: MATCH_STATUS.ACCEPTED, }, include: { user1: { @@ -219,7 +220,7 @@ router.get('/', authenticate, async (req, res, next) => { const incomingRequests = await prisma.match.findMany({ where: { user2Id: userId, - status: 'pending', + status: MATCH_STATUS.PENDING, }, include: { user1: { @@ -298,7 +299,7 @@ router.get('/', authenticate, async (req, res, next) => { const outgoingRequests = await prisma.match.findMany({ where: { user1Id: userId, - status: 'pending', + status: MATCH_STATUS.PENDING, }, include: { user2: { diff --git a/backend/src/routes/events.js b/backend/src/routes/events.js index 08b4703..1acc4b2 100644 --- a/backend/src/routes/events.js +++ b/backend/src/routes/events.js @@ -3,6 +3,7 @@ const { prisma } = require('../utils/db'); const { authenticate } = require('../middleware/auth'); const { getIO } = require('../socket'); const matchingService = require('../services/matching'); +const { SUGGESTION_STATUS } = require('../constants'); const router = express.Router(); @@ -1122,8 +1123,8 @@ router.post('/:slug/run-matching', authenticate, async (req, res, next) => { const count = await matchingService.saveMatchingResults(event.id, suggestions); // Get statistics - const notFoundCount = suggestions.filter(s => s.status === 'not_found').length; - const matchedCount = suggestions.filter(s => s.status === 'pending').length; + const notFoundCount = suggestions.filter(s => s.status === SUGGESTION_STATUS.NOT_FOUND).length; + const matchedCount = suggestions.filter(s => s.status === SUGGESTION_STATUS.PENDING).length; res.json({ success: true, diff --git a/backend/src/routes/matches.js b/backend/src/routes/matches.js index 60510e7..85b2af6 100644 --- a/backend/src/routes/matches.js +++ b/backend/src/routes/matches.js @@ -2,6 +2,7 @@ const express = require('express'); const { prisma } = require('../utils/db'); const { authenticate } = require('../middleware/auth'); const { getIO } = require('../socket'); +const { MATCH_STATUS } = require('../constants'); const router = express.Router(); @@ -98,7 +99,7 @@ router.post('/', authenticate, async (req, res, next) => { user1Id: requesterId, user2Id: targetUserId, eventId: event.id, - status: 'pending', + status: MATCH_STATUS.PENDING, }, include: { user1: { @@ -534,7 +535,7 @@ router.put('/:slug/accept', authenticate, async (req, res, next) => { const updated = await tx.match.update({ where: { slug }, data: { - status: 'accepted', + status: MATCH_STATUS.ACCEPTED, roomId: chatRoom.id, }, include: { @@ -828,7 +829,7 @@ router.post('/:slug/ratings', authenticate, async (req, res, next) => { // Both users have rated - mark match as completed await prisma.match.update({ where: { id: match.id }, - data: { status: 'completed' }, + data: { status: MATCH_STATUS.COMPLETED }, }); } diff --git a/backend/src/services/matching.js b/backend/src/services/matching.js index 0358a47..e7f0fa2 100644 --- a/backend/src/services/matching.js +++ b/backend/src/services/matching.js @@ -10,6 +10,7 @@ */ const { prisma } = require('../utils/db'); +const { SUGGESTION_STATUS } = require('../constants'); // Constants const MAX_RECORDINGS_PER_PERSON = 3; @@ -267,7 +268,7 @@ async function runMatching(eventId) { eventId, heatId: heat.id, recorderId: null, - status: 'not_found', + status: SUGGESTION_STATUS.NOT_FOUND, }); continue; } @@ -285,7 +286,7 @@ async function runMatching(eventId) { eventId, heatId: heat.id, recorderId: best.recorder.userId, - status: 'pending', + status: SUGGESTION_STATUS.PENDING, }); // Update assignment count