Skip to content
Snippets Groups Projects
Commit 799bdae6 authored by tpgus2603's avatar tpgus2603
Browse files

test: 미팅서비스 테스트완료(#13)

parent e0c7ec1c
No related branches found
No related tags found
2 merge requests!31Develop,!23[#13] 스케쥴 서비스 코드 로직 대폭 수정 및 미팅서비스 테스트 완료
// models/MeetingParticipant.js
const { DataTypes } = require('sequelize'); const { DataTypes } = require('sequelize');
const sequelize = require('../config/sequelize'); const sequelize = require('../config/sequelize');
const Meeting =require('./Meeting');
const User = require('./user');
const MeetingParticipant = sequelize.define('MeetingParticipant', {
tableName: 'MeetingParticipants',
timestamps: false,
});
const MeetingParticipant = sequelize.define(
'MeetingParticipant',
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
meeting_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
},
{
tableName: 'MeetingParticipants', // 테이블 이름 설정
timestamps: false, // createdAt, updatedAt 필드 비활성화
}
);
module.exports = MeetingParticipant; module.exports = MeetingParticipant;
...@@ -182,6 +182,7 @@ class MeetingService { ...@@ -182,6 +182,7 @@ class MeetingService {
*/ */
async joinMeeting(meetingId, userId) { async joinMeeting(meetingId, userId) {
const meeting = await Meeting.findByPk(meetingId); const meeting = await Meeting.findByPk(meetingId);
console.log(`참여하려는 모임: ${JSON.stringify(meeting)}`);
if (!meeting) { if (!meeting) {
throw new Error('모임을 찾을 수 없습니다.'); throw new Error('모임을 찾을 수 없습니다.');
} }
...@@ -214,6 +215,7 @@ class MeetingService { ...@@ -214,6 +215,7 @@ class MeetingService {
meeting.time_idx_end, meeting.time_idx_end,
transaction transaction
); );
console.log(`스케줄 충돌 결과: ${hasConflict}`);
if (hasConflict) { if (hasConflict) {
throw new Error('스케줄이 겹칩니다. 다른 모임에 참가하세요.'); throw new Error('스케줄이 겹칩니다. 다른 모임에 참가하세요.');
} }
......
This diff is collapsed.
...@@ -32,7 +32,6 @@ beforeEach(async () => { ...@@ -32,7 +32,6 @@ beforeEach(async () => {
}); });
afterAll(async () => { afterAll(async () => {
// 모든 테스트가 끝난 후 데이터베이스 연결을 종료합니다.
await sequelize.close(); await sequelize.close();
}); });
...@@ -272,7 +271,7 @@ describe('ScheduleService', () => { ...@@ -272,7 +271,7 @@ describe('ScheduleService', () => {
}); });
test('should retrieve one schedule when user has only one', async () => { test('should retrieve one schedule when user has only one', async () => {
const schedules = await ScheduleService.getAllSchedules(3); // Charlie has id=3 and only one fixed schedule const schedules = await ScheduleService.getAllSchedules(3);
expect(schedules).toBeDefined(); expect(schedules).toBeDefined();
expect(Array.isArray(schedules)).toBe(true); expect(Array.isArray(schedules)).toBe(true);
...@@ -309,7 +308,7 @@ describe('ScheduleService', () => { ...@@ -309,7 +308,7 @@ describe('ScheduleService', () => {
describe('cleanExpiredSchedules', () => { describe('cleanExpiredSchedules', () => {
test('should delete all flexible schedules', async () => { test('should delete all flexible schedules', async () => {
// 먼저, 여러 유동 스케줄을 생성 // 여러 유동 스케줄을 생성
await ScheduleService.createSchedules({ await ScheduleService.createSchedules({
userId: 1, userId: 1,
title: 'Alice Flexible Schedule 2', title: 'Alice Flexible Schedule 2',
...@@ -342,7 +341,7 @@ describe('ScheduleService', () => { ...@@ -342,7 +341,7 @@ describe('ScheduleService', () => {
}); });
test('should not delete fixed schedules', async () => { test('should not delete fixed schedules', async () => {
// 먼저, 여러 고정 스케줄을 생성 // 여러 고정 스케줄을 생성
await ScheduleService.createSchedules({ await ScheduleService.createSchedules({
userId: 3, userId: 3,
title: 'Charlie Fixed Schedule 2', title: 'Charlie Fixed Schedule 2',
...@@ -361,7 +360,7 @@ describe('ScheduleService', () => { ...@@ -361,7 +360,7 @@ describe('ScheduleService', () => {
where: { user_id: 3, is_fixed: true }, where: { user_id: 3, is_fixed: true },
}); });
expect(remainingFixedSchedules.length).toBe(3); // 기존 1개 + 2개 추가 expect(remainingFixedSchedules.length).toBe(3);
}); });
}); });
}); });
...@@ -133,6 +133,9 @@ class ScheduleService { ...@@ -133,6 +133,9 @@ class ScheduleService {
} }
async checkScheduleOverlapByTime(userId, time_idx_start, time_idx_end, transaction = null) { async checkScheduleOverlapByTime(userId, time_idx_start, time_idx_end, transaction = null) {
console.log(
`checkScheduleOverlapByTime 호출: userId=${userId}, time_idx_start=${time_idx_start}, time_idx_end=${time_idx_end}`
);
const overlappingSchedule = await Schedule.findOne({ const overlappingSchedule = await Schedule.findOne({
where: { where: {
user_id: userId, user_id: userId,
...@@ -142,8 +145,10 @@ class ScheduleService { ...@@ -142,8 +145,10 @@ class ScheduleService {
}, },
transaction, transaction,
}); });
console.log(`중복 스케줄: ${JSON.stringify(overlappingSchedule)}`);
return !!overlappingSchedule; const result = !!overlappingSchedule;
console.log(`스케줄 충돌 결과: ${result}`);
return result;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment