Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebBack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem
WebBack
Merge requests
!22
[
#13
] 서비스로직에 인덱스 도입하여 로직 최적화 안료
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
[
#13
] 서비스로직에 인덱스 도입하여 로직 최적화 안료
test/#13
into
develop
Overview
0
Commits
2
Pipelines
0
Changes
2
Merged
세현 임
requested to merge
test/#13
into
develop
5 months ago
Overview
0
Commits
2
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Viewing commit
1abb4eea
Prev
Next
Show latest version
2 files
+
261
−
133
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
1abb4eea
test: 바뀐 스케쥴 서비스로직 테스트 완료(
#13
)
· 1abb4eea
tpgus2603
authored
5 months ago
services/schedule.test.js
+
260
−
130
Options
// test/schedule.test.js
// test/scheduleService.test.js
const
sequelize
=
require
(
'
../config/sequelize
'
);
const
sequelize
=
require
(
'
../config/sequelize
'
);
// 실제 경로에 맞게 수정
const
{
User
,
Friend
,
Schedule
,}
=
require
(
'
../models
'
);
const
{
Schedule
,
User
}
=
require
(
'
../models
'
);
const
scheduleService
=
require
(
'
../services/scheduleService
'
);
// 경로 수정
const
ScheduleService
=
require
(
'
../services/scheduleService
'
);
// Uppercase 'S'로 가져오기
const
ScheduleResponseDTO
=
require
(
'
../dtos/ScheduleResponseDTO
'
);
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
// 테스트 스위트가 시작되기 전에 데이터베이스를 동기화합니다.
await
sequelize
.
sync
({
force
:
true
});
await
sequelize
.
sync
({
force
:
true
});
});
beforeEach
(
async
()
=>
{
// 각 테스트가 시작되기 전에 기존 데이터를 삭제합니다.
await
Schedule
.
destroy
({
where
:
{}
});
await
User
.
destroy
({
where
:
{}
});
// 더미 사용자 생성
// 더미 사용자 생성
await
User
.
bulkCreate
([
await
User
.
bulkCreate
([
{
id
:
1
,
name
:
'
Alice
'
,
email
:
'
alice@example.com
'
},
{
id
:
1
,
name
:
'
Alice
'
,
email
:
'
alice@example.com
'
},
{
id
:
2
,
name
:
'
Bob
'
,
email
:
'
bob@example.com
'
},
{
id
:
2
,
name
:
'
Bob
'
,
email
:
'
bob@example.com
'
},
{
id
:
3
,
name
:
'
Charlie
'
,
email
:
'
charlie@example.com
'
},
]);
]);
// 더미 친구 관계 생성
// 더미 스케줄 생성
await
Friend
.
create
({
await
Schedule
.
bulkCreate
([
id
:
1
,
{
id
:
1
,
user_id
:
1
,
title
:
'
Alice Fixed Schedule 1
'
,
time_idx
:
36
,
is_fixed
:
true
},
requester_id
:
1
,
{
id
:
2
,
user_id
:
1
,
title
:
'
Alice Flexible Schedule 1
'
,
time_idx
:
44
,
is_fixed
:
false
},
receiver_id
:
2
,
{
id
:
3
,
user_id
:
2
,
title
:
'
Bob Fixed Schedule 1
'
,
time_idx
:
60
,
is_fixed
:
true
},
status
:
'
ACCEPTED
'
,
{
id
:
4
,
user_id
:
2
,
title
:
'
Bob Flexible Schedule 1
'
,
time_idx
:
61
,
is_fixed
:
false
},
});
{
id
:
5
,
user_id
:
3
,
title
:
'
Charlie Fixed Schedule 1
'
,
time_idx
:
100
,
is_fixed
:
true
},
]);
// 더미 스케줄 생성 (day_of_week과 TIME 형식 사용)
await
Schedule
.
create
({
id
:
1
,
user_id
:
1
,
title
:
'
Alice
\'
s Fixed Schedule
'
,
day_of_week
:
'
Monday
'
,
start_time
:
'
09:00:00
'
,
// 'HH:MM:SS' 형식
end_time
:
'
10:00:00
'
,
is_fixed
:
true
,
});
await
Schedule
.
create
({
id
:
2
,
user_id
:
1
,
title
:
'
Alice
\'
s Flexible Schedule
'
,
day_of_week
:
'
Tuesday
'
,
start_time
:
'
11:00:00
'
,
end_time
:
'
12:00:00
'
,
is_fixed
:
false
,
});
});
});
afterAll
(
async
()
=>
{
afterAll
(
async
()
=>
{
// 데이터베이스 연결 종료
//
모든 테스트가 끝난 후
데이터베이스 연결
을
종료
합니다.
await
sequelize
.
close
();
await
sequelize
.
close
();
});
});
describe
(
'
Schedule
Service
'
,
()
=>
{
describe
(
'
ScheduleService
'
,
()
=>
{
describe
(
'
createSchedules
'
,
()
=>
{
describe
(
'
createSchedules
'
,
()
=>
{
test
(
'
should create new fixed schedules successfully
'
,
async
()
=>
{
test
(
'
should create
multiple
new fixed schedules successfully
'
,
async
()
=>
{
const
scheduleData
=
{
const
scheduleData
=
{
userId
:
2
,
userId
:
1
,
title
:
'
Bob
\'
s
Fixed Schedule
'
,
title
:
'
Alice
Fixed Schedule
Bulk
'
,
is_fixed
:
true
,
is_fixed
:
true
,
events
:
[
events
:
[
{
{
time_idx
:
50
},
// Valid time_idx
day_of_week
:
'
Wednesday
'
,
{
time_idx
:
51
},
start_time
:
'
14:00:00
'
,
end_time
:
'
15:00:00
'
,
},
],
],
};
};
const
schedules
=
await
s
cheduleService
.
createSchedules
(
scheduleData
);
const
schedules
=
await
S
cheduleService
.
createSchedules
(
scheduleData
);
expect
(
schedules
).
toBeDefined
();
expect
(
schedules
).
toBeDefined
();
expect
(
Array
.
isArray
(
schedules
)).
toBe
(
true
);
expect
(
Array
.
isArray
(
schedules
)).
toBe
(
true
);
expect
(
schedules
.
length
).
toBe
(
1
);
expect
(
schedules
.
length
).
toBe
(
2
);
const
schedule
=
schedules
[
0
];
schedules
.
forEach
((
schedule
,
index
)
=>
{
expect
(
schedule
.
user_id
).
toBe
(
2
);
expect
(
schedule
.
user_id
).
toBe
(
1
);
expect
(
schedule
.
title
).
toBe
(
'
Bob
\'
s Fixed Schedule
'
);
expect
(
schedule
.
title
).
toBe
(
'
Alice Fixed Schedule Bulk
'
);
expect
(
schedule
.
is_fixed
).
toBe
(
true
);
expect
(
schedule
.
is_fixed
).
toBe
(
true
);
expect
(
schedule
.
day_of_week
).
toBe
(
'
Wednesday
'
);
expect
(
schedule
.
time_idx
).
toBe
(
scheduleData
.
events
[
index
].
time_idx
);
expect
(
schedule
.
start_time
).
toBe
(
'
14:00
'
);
});
expect
(
schedule
.
end_time
).
toBe
(
'
15:00
'
);
// 데이터베이스에 실제로 추가되었는지 확인
const
dbSchedules
=
await
Schedule
.
findAll
({
where
:
{
user_id
:
1
,
title
:
'
Alice Fixed Schedule Bulk
'
},
});
expect
(
dbSchedules
.
length
).
toBe
(
2
);
});
});
test
(
'
should create new flexible schedules successfully
'
,
async
()
=>
{
test
(
'
should create
multiple
new flexible schedules successfully
'
,
async
()
=>
{
const
scheduleData
=
{
const
scheduleData
=
{
userId
:
2
,
userId
:
2
,
title
:
'
Bob
\'
s
Flexible Schedule
'
,
title
:
'
Bob Flexible Schedule
Bulk
'
,
is_fixed
:
false
,
is_fixed
:
false
,
events
:
[
events
:
[
{
{
time_idx
:
62
},
day_of_week
:
'
Thursday
'
,
{
time_idx
:
63
},
start_time
:
'
16:00:00
'
,
end_time
:
'
17:00:00
'
,
},
],
],
};
};
const
schedules
=
await
s
cheduleService
.
createSchedules
(
scheduleData
);
const
schedules
=
await
S
cheduleService
.
createSchedules
(
scheduleData
);
expect
(
schedules
).
toBeDefined
();
expect
(
schedules
).
toBeDefined
();
expect
(
Array
.
isArray
(
schedules
)).
toBe
(
true
);
expect
(
Array
.
isArray
(
schedules
)).
toBe
(
true
);
expect
(
schedules
.
length
).
toBe
(
1
);
expect
(
schedules
.
length
).
toBe
(
2
);
const
schedule
=
schedules
[
0
];
schedules
.
forEach
((
schedule
,
index
)
=>
{
expect
(
schedule
.
user_id
).
toBe
(
2
);
expect
(
schedule
.
user_id
).
toBe
(
2
);
expect
(
schedule
.
title
).
toBe
(
'
Bob
\'
s Flexible Schedule
'
);
expect
(
schedule
.
title
).
toBe
(
'
Bob Flexible Schedule Bulk
'
);
expect
(
schedule
.
is_fixed
).
toBe
(
false
);
expect
(
schedule
.
is_fixed
).
toBe
(
false
);
expect
(
schedule
.
day_of_week
).
toBe
(
'
Thursday
'
);
expect
(
schedule
.
time_idx
).
toBe
(
scheduleData
.
events
[
index
].
time_idx
);
expect
(
schedule
.
start_time
).
toBe
(
'
16:00
'
);
});
expect
(
schedule
.
end_time
).
toBe
(
'
17:00
'
);
// 데이터베이스에 실제로 추가되었는지 확인
const
dbSchedules
=
await
Schedule
.
findAll
({
where
:
{
user_id
:
2
,
title
:
'
Bob Flexible Schedule Bulk
'
},
});
expect
(
dbSchedules
.
length
).
toBe
(
2
);
});
});
test
(
'
should throw error when schedule
times
overlap
with existing schedule
'
,
async
()
=>
{
test
(
'
should throw error when
creating
schedule
s with
overlap
ping time_idx
'
,
async
()
=>
{
const
scheduleData
=
{
const
scheduleData
=
{
userId
:
1
,
userId
:
1
,
title
:
'
Alice
\'
s
Overlapping Schedule
'
,
title
:
'
Alice Overlapping Schedule
'
,
is_fixed
:
false
,
is_fixed
:
false
,
events
:
[
events
:
[
{
{
time_idx
:
36
},
// Existing schedule for Alice
day_of_week
:
'
Monday
'
,
// 기존 스케줄과 동일한 요일
start_time
:
'
09:30:00
'
,
// 기존 스케줄과 겹치는 시간
end_time
:
'
10:30:00
'
,
},
],
],
};
};
await
expect
(
s
cheduleService
.
createSchedules
(
scheduleData
))
await
expect
(
S
cheduleService
.
createSchedules
(
scheduleData
))
.
rejects
.
rejects
.
toThrow
(
'
Schedule overlaps with existing schedule
on Monday
'
);
.
toThrow
(
'
Schedule overlaps with existing schedule
at time_idx 36
'
);
});
});
test
(
'
should throw error when
start_time is after end_time
'
,
async
()
=>
{
test
(
'
should throw error when
creating schedules with invalid time_idx
'
,
async
()
=>
{
const
scheduleData
=
{
const
scheduleData
=
{
userId
:
1
,
userId
:
1
,
title
:
'
Invalid Schedule
'
,
title
:
'
Alice
Invalid Schedule
'
,
is_fixed
:
false
,
is_fixed
:
false
,
events
:
[
events
:
[
{
{
time_idx
:
700
},
// Invalid time_idx
day_of_week
:
'
Friday
'
,
start_time
:
'
18:00:00
'
,
end_time
:
'
17:00:00
'
,
// start_time이 더 늦음
},
],
],
};
};
await
expect
(
s
cheduleService
.
createSchedules
(
scheduleData
))
await
expect
(
S
cheduleService
.
createSchedules
(
scheduleData
))
.
rejects
.
rejects
.
toThrow
(
'
Start time must be before end time
'
);
.
toThrow
(
'
Validation error: Validation max on time_idx failed
'
);
});
});
});
});
describe
(
'
updateSchedule
'
,
()
=>
{
describe
(
'
updateSchedule
s
'
,
()
=>
{
test
(
'
should update
an
existing schedule successfully
'
,
async
()
=>
{
test
(
'
should update
multiple
existing schedule
s
successfully
'
,
async
()
=>
{
const
updateData
=
{
const
updateData
=
{
title
:
'
Alice
\'
s Updated Flexible Schedule
'
,
updates
:
[
start_time
:
'
11:30:00
'
,
{
time_idx
:
36
,
title
:
'
Alice Updated Fixed Schedule
'
,
is_fixed
:
true
},
end_time
:
'
12:30:00
'
,
{
time_idx
:
44
,
title
:
'
Alice Updated Flexible Schedule
'
,
is_fixed
:
false
},
],
};
};
const
updatedSchedule
=
await
scheduleService
.
updateSchedule
(
2
,
1
,
updateData
);
const
updatedSchedules
=
await
ScheduleService
.
updateSchedules
(
1
,
updateData
.
updates
);
expect
(
updatedSchedules
).
toBeDefined
();
expect
(
Array
.
isArray
(
updatedSchedules
)).
toBe
(
true
);
expect
(
updatedSchedules
.
length
).
toBe
(
2
);
updatedSchedules
.
forEach
((
schedule
,
index
)
=>
{
expect
(
schedule
.
title
).
toBe
(
updateData
.
updates
[
index
].
title
);
expect
(
schedule
.
is_fixed
).
toBe
(
updateData
.
updates
[
index
].
is_fixed
);
expect
(
schedule
.
time_idx
).
toBe
(
updateData
.
updates
[
index
].
time_idx
);
});
expect
(
updatedSchedule
).
toBeDefined
();
// 데이터베이스에서 업데이트 확인
expect
(
updatedSchedule
.
title
).
toBe
(
'
Alice
\'
s Updated Flexible Schedule
'
);
const
dbSchedule1
=
await
Schedule
.
findOne
({
where
:
{
user_id
:
1
,
time_idx
:
36
}
});
expect
(
updatedSchedule
.
start_time
).
toBe
(
'
11:30
'
);
const
dbSchedule2
=
await
Schedule
.
findOne
({
where
:
{
user_id
:
1
,
time_idx
:
44
}
});
expect
(
updatedSchedule
.
end_time
).
toBe
(
'
12:30
'
);
expect
(
dbSchedule1
.
title
).
toBe
(
'
Alice Updated Fixed Schedule
'
);
expect
(
dbSchedule2
.
title
).
toBe
(
'
Alice Updated Flexible Schedule
'
);
});
});
test
(
'
should throw error when updating a non-existing schedule
'
,
async
()
=>
{
test
(
'
should throw error when updating a non-existing schedule
'
,
async
()
=>
{
const
updateData
=
{
const
updateData
=
{
title
:
'
Non-existing Schedule
'
,
updates
:
[
start_time
:
'
10:00:00
'
,
{
time_idx
:
999
,
title
:
'
Non-existing Schedule
'
}
,
end_time
:
'
11:00:00
'
,
]
,
};
};
await
expect
(
s
cheduleService
.
updateSchedule
(
999
,
1
,
updateData
))
await
expect
(
S
cheduleService
.
updateSchedule
s
(
1
,
updateData
.
updates
))
.
rejects
.
rejects
.
to
Throw
(
'
Schedule not found
'
);
.
to
MatchObject
({
message
:
'
Schedule not found at time_idx 999
'
}
);
});
});
test
(
'
should throw error when updated schedule overlaps with existing schedule
'
,
async
()
=>
{
test
(
'
should throw error when creating schedules with overlapping time_idx
'
,
async
()
=>
{
const
updateData
=
{
// 먼저, 새로운 스케줄을 생성하여 time_idx 50을 사용
title
:
'
Alice
\'
s Overlapping Update
'
,
await
ScheduleService
.
createSchedules
({
start_time
:
'
09:30:00
'
,
// 기존 스케줄과 겹침
userId
:
1
,
end_time
:
'
10:30:00
'
,
title
:
'
Alice Another Schedule
'
,
is_fixed
:
false
,
events
:
[
{
time_idx
:
50
},
],
});
// 동일한 time_idx로 스케줄을 생성하려 할 때 오류가 발생하는지 테스트
const
scheduleData
=
{
userId
:
1
,
title
:
'
Alice Overlapping Schedule
'
,
is_fixed
:
false
,
events
:
[
{
time_idx
:
50
},
// 이미 존재하는 time_idx
],
};
};
await
expect
(
s
cheduleService
.
upd
ateSchedule
(
2
,
1
,
updat
eData
))
await
expect
(
S
cheduleService
.
cre
ateSchedule
s
(
schedul
eData
))
.
rejects
.
rejects
.
toThrow
(
'
Schedule overlaps with existing schedule
'
);
.
toThrow
(
'
Schedule overlaps with existing schedule
at time_idx 50
'
);
});
});
});
});
describe
(
'
deleteSchedule
'
,
()
=>
{
describe
(
'
deleteSchedules
'
,
()
=>
{
test
(
'
should delete an existing schedule successfully
'
,
async
()
=>
{
test
(
'
should delete multiple existing schedules successfully
'
,
async
()
=>
{
const
result
=
await
scheduleService
.
deleteSchedule
(
2
,
1
);
// 먼저, 스케줄 생성
await
ScheduleService
.
createSchedules
({
userId
:
1
,
title
:
'
Alice Bulk Delete Schedule 1
'
,
is_fixed
:
false
,
events
:
[
{
time_idx
:
70
},
{
time_idx
:
71
},
],
});
const
deleteData
=
{
time_idxs
:
[
70
,
71
],
};
const
result
=
await
ScheduleService
.
deleteSchedules
(
1
,
deleteData
.
time_idxs
);
expect
(
result
).
toEqual
({
message
:
'
Schedule successfully deleted
'
});
expect
(
result
).
toBeDefined
();
expect
(
result
.
deleted_time_idxs
).
toContain
(
70
);
expect
(
result
.
deleted_time_idxs
).
toContain
(
71
);
// 삭제된 스케줄이 실제로 삭제되었는지 확인
// 데이터베이스에서 삭제 확인
const
schedule
=
await
Schedule
.
findByPk
(
2
);
const
dbSchedule1
=
await
Schedule
.
findOne
({
where
:
{
user_id
:
1
,
time_idx
:
70
}
});
expect
(
schedule
).
toBeNull
();
const
dbSchedule2
=
await
Schedule
.
findOne
({
where
:
{
user_id
:
1
,
time_idx
:
71
}
});
expect
(
dbSchedule1
).
toBeNull
();
expect
(
dbSchedule2
).
toBeNull
();
});
});
test
(
'
should throw error when deleting a non-existing schedule
'
,
async
()
=>
{
test
(
'
should throw error when deleting a non-existing schedule
'
,
async
()
=>
{
await
expect
(
scheduleService
.
deleteSchedule
(
999
,
1
))
const
deleteData
=
{
time_idxs
:
[
999
],
};
await
expect
(
ScheduleService
.
deleteSchedules
(
1
,
deleteData
.
time_idxs
))
.
rejects
.
rejects
.
toThrow
(
'
Schedule not found
'
);
.
toThrow
(
'
Schedule not found
at time_idx 999
'
);
});
});
});
});
describe
(
'
getAllSchedules
'
,
()
=>
{
describe
(
'
getAllSchedules
'
,
()
=>
{
test
(
'
should retrieve all valid schedules for a user
'
,
async
()
=>
{
test
(
'
should retrieve all schedules for a user
'
,
async
()
=>
{
// 사용자 Alice의 모든 스케줄 조회 (user_id: 1)
// Update schedules first
const
schedules
=
await
scheduleService
.
getAllSchedules
(
1
);
const
updateData
=
{
updates
:
[
{
time_idx
:
36
,
title
:
'
Alice Updated Fixed Schedule
'
,
is_fixed
:
true
},
{
time_idx
:
44
,
title
:
'
Alice Updated Flexible Schedule
'
,
is_fixed
:
false
},
],
};
await
ScheduleService
.
updateSchedules
(
1
,
updateData
.
updates
);
const
schedules
=
await
ScheduleService
.
getAllSchedules
(
1
);
expect
(
schedules
).
toBeDefined
();
expect
(
schedules
).
toBeDefined
();
expect
(
Array
.
isArray
(
schedules
)).
toBe
(
true
);
expect
(
Array
.
isArray
(
schedules
)).
toBe
(
true
);
expect
(
schedules
.
length
).
toBe
(
1
);
// id=1 스케줄은 is_fixed=true
expect
(
schedules
[
0
].
title
).
toBe
(
'
Alice
\'
s Fixed Schedule
'
);
// 현재 Alice는 id=1, time_idx=36 (fixed), time_idx=44 (flexible)이 존재
expect
(
schedules
[
0
].
day_of_week
).
toBe
(
'
Monday
'
);
expect
(
schedules
.
length
).
toBe
(
2
);
const
schedule1
=
schedules
.
find
(
s
=>
s
.
time_idx
===
36
);
const
schedule2
=
schedules
.
find
(
s
=>
s
.
time_idx
===
44
);
expect
(
schedule1
).
toBeDefined
();
expect
(
schedule1
.
title
).
toBe
(
'
Alice Updated Fixed Schedule
'
);
expect
(
schedule2
).
toBeDefined
();
expect
(
schedule2
.
title
).
toBe
(
'
Alice Updated Flexible Schedule
'
);
});
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
expect
(
schedules
).
toBeDefined
();
expect
(
Array
.
isArray
(
schedules
)).
toBe
(
true
);
expect
(
schedules
.
length
).
toBe
(
1
);
expect
(
schedules
[
0
].
title
).
toBe
(
'
Charlie Fixed Schedule 1
'
);
});
});
});
});
describe
(
'
getScheduleById
'
,
()
=>
{
describe
(
'
getScheduleByTimeIdx
'
,
()
=>
{
test
(
'
should retrieve a specific schedule by ID
'
,
async
()
=>
{
test
(
'
should retrieve a specific schedule by time_idx
'
,
async
()
=>
{
const
schedule
=
await
scheduleService
.
getScheduleById
(
1
,
1
);
// Update schedule first
const
updateData
=
{
updates
:
[
{
time_idx
:
36
,
title
:
'
Alice Updated Fixed Schedule
'
,
is_fixed
:
true
},
],
};
await
ScheduleService
.
updateSchedules
(
1
,
updateData
.
updates
);
const
schedule
=
await
ScheduleService
.
getScheduleByTimeIdx
(
1
,
36
);
expect
(
schedule
).
toBeDefined
();
expect
(
schedule
).
toBeDefined
();
expect
(
schedule
.
title
).
toBe
(
'
Alice
\'
s
Fixed Schedule
'
);
expect
(
schedule
.
title
).
toBe
(
'
Alice
Updated
Fixed Schedule
'
);
expect
(
schedule
.
day_of_week
).
toBe
(
'
Monday
'
);
expect
(
schedule
.
time_idx
).
toBe
(
36
);
});
});
test
(
'
should throw error when retrieving a non-existing schedule
'
,
async
()
=>
{
test
(
'
should throw error when retrieving a non-existing schedule
'
,
async
()
=>
{
await
expect
(
s
cheduleService
.
getScheduleBy
Id
(
999
,
1
))
await
expect
(
S
cheduleService
.
getScheduleBy
TimeIdx
(
1
,
999
))
.
rejects
.
rejects
.
toThrow
(
'
Schedule not found
'
);
.
toThrow
(
'
Schedule not found
'
);
});
});
});
});
describe
(
'
cleanExpiredSchedules
'
,
()
=>
{
test
(
'
should delete all flexible schedules
'
,
async
()
=>
{
// 먼저, 여러 유동 스케줄을 생성
await
ScheduleService
.
createSchedules
({
userId
:
1
,
title
:
'
Alice Flexible Schedule 2
'
,
is_fixed
:
false
,
events
:
[
{
time_idx
:
80
},
{
time_idx
:
81
},
],
});
await
ScheduleService
.
createSchedules
({
userId
:
2
,
title
:
'
Bob Flexible Schedule 2
'
,
is_fixed
:
false
,
events
:
[
{
time_idx
:
90
},
{
time_idx
:
91
},
],
});
// 유동 스케줄 삭제
await
ScheduleService
.
cleanExpiredSchedules
();
// 데이터베이스에서 유동 스케줄이 모두 삭제되었는지 확인
const
remainingFlexibleSchedules
=
await
Schedule
.
findAll
({
where
:
{
is_fixed
:
false
},
});
expect
(
remainingFlexibleSchedules
.
length
).
toBe
(
0
);
});
test
(
'
should not delete fixed schedules
'
,
async
()
=>
{
// 먼저, 여러 고정 스케줄을 생성
await
ScheduleService
.
createSchedules
({
userId
:
3
,
title
:
'
Charlie Fixed Schedule 2
'
,
is_fixed
:
true
,
events
:
[
{
time_idx
:
120
},
{
time_idx
:
121
},
],
});
// 유동 스케줄 삭제
await
ScheduleService
.
cleanExpiredSchedules
();
// 데이터베이스에서 고정 스케줄이 유지되었는지 확인
const
remainingFixedSchedules
=
await
Schedule
.
findAll
({
where
:
{
user_id
:
3
,
is_fixed
:
true
},
});
expect
(
remainingFixedSchedules
.
length
).
toBe
(
3
);
// 기존 1개 + 2개 추가
});
});
});
});
Loading