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
Commits
fcf95cd3
Commit
fcf95cd3
authored
4 months ago
by
조대희
Browse files
Options
Downloads
Patches
Plain Diff
test: 변경된 스케줄 로직 테스트
parent
6958b3d4
Branches
Branches containing commit
No related tags found
1 merge request
!42
[#25] 배포코드 master브랜치로 이동
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/modifyScheduleResponse.test.js
+187
-0
187 additions, 0 deletions
services/modifyScheduleResponse.test.js
with
187 additions
and
0 deletions
services/modifyScheduleResponse.test.js
0 → 100644
+
187
−
0
View file @
fcf95cd3
// test/scheduleService.test.js
const
sequelize
=
require
(
'
../config/sequelize
'
);
const
{
Schedule
,
User
,
Meeting
,
MeetingParticipant
,
FcmToken
}
=
require
(
'
../models
'
);
const
ScheduleService
=
require
(
'
../services/scheduleService
'
);
const
MeetingService
=
require
(
'
../services/meetingService
'
);
const
ChatRooms
=
require
(
'
../schemas/chatRooms
'
);
describe
(
'
Schedule Service and Meeting Integration Tests
'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
sequelize
.
sync
({
force
:
true
});
});
beforeEach
(
async
()
=>
{
await
MeetingParticipant
.
destroy
({
where
:
{}
});
await
Meeting
.
destroy
({
where
:
{}
});
await
Schedule
.
destroy
({
where
:
{}
});
await
User
.
destroy
({
where
:
{}
});
await
FcmToken
.
destroy
({
where
:
{}
});
// 더미 사용자 생성
await
User
.
bulkCreate
([
{
id
:
1
,
name
:
'
Alice
'
,
email
:
'
alice@example.com
'
},
{
id
:
2
,
name
:
'
Bob
'
,
email
:
'
bob@example.com
'
},
{
id
:
3
,
name
:
'
Charlie
'
,
email
:
'
charlie@example.com
'
}
]);
// ChatRooms Mock 설정
jest
.
spyOn
(
ChatRooms
.
prototype
,
'
save
'
).
mockResolvedValue
(
undefined
);
jest
.
spyOn
(
ChatRooms
,
'
findOne
'
).
mockResolvedValue
({
participants
:
[],
isOnline
:
new
Map
(),
lastReadAt
:
new
Map
(),
lastReadLogId
:
new
Map
(),
save
:
jest
.
fn
().
mockResolvedValue
(
true
)
});
});
afterAll
(
async
()
=>
{
await
sequelize
.
close
();
});
describe
(
'
Schedule Service Tests
'
,
()
=>
{
test
(
'
should create schedule with time_indices
'
,
async
()
=>
{
const
scheduleData
=
{
userId
:
1
,
title
:
'
Test Schedule
'
,
is_fixed
:
true
,
time_indices
:
[
36
,
37
,
38
]
};
const
schedule
=
await
ScheduleService
.
createSchedules
(
scheduleData
);
expect
(
schedule
).
toBeDefined
();
expect
(
schedule
.
title
).
toBe
(
'
Test Schedule
'
);
expect
(
schedule
.
time_indices
).
toEqual
([
36
,
37
,
38
]);
const
dbSchedules
=
await
Schedule
.
findAll
({
where
:
{
user_id
:
1
,
title
:
'
Test Schedule
'
}
});
expect
(
dbSchedules
.
length
).
toBe
(
3
);
});
test
(
'
should update schedule with new time_indices
'
,
async
()
=>
{
await
ScheduleService
.
createSchedules
({
userId
:
1
,
title
:
'
Original Schedule
'
,
is_fixed
:
true
,
time_indices
:
[
36
,
37
,
38
]
});
const
updateData
=
{
originalTitle
:
'
Original Schedule
'
,
title
:
'
Updated Schedule
'
,
is_fixed
:
true
,
time_indices
:
[
36
,
37
,
38
,
39
]
};
const
updatedSchedule
=
await
ScheduleService
.
updateSchedules
(
1
,
updateData
);
expect
(
updatedSchedule
.
title
).
toBe
(
'
Updated Schedule
'
);
expect
(
updatedSchedule
.
time_indices
).
toEqual
([
36
,
37
,
38
,
39
]);
});
test
(
'
should delete schedule by title
'
,
async
()
=>
{
await
ScheduleService
.
createSchedules
({
userId
:
1
,
title
:
'
Schedule to Delete
'
,
is_fixed
:
true
,
time_indices
:
[
40
,
41
,
42
]
});
const
result
=
await
ScheduleService
.
deleteSchedules
(
1
,
'
Schedule to Delete
'
);
expect
(
result
.
deletedCount
).
toBe
(
3
);
const
remainingSchedules
=
await
Schedule
.
findAll
({
where
:
{
user_id
:
1
,
title
:
'
Schedule to Delete
'
}
});
expect
(
remainingSchedules
.
length
).
toBe
(
0
);
});
});
describe
(
'
Meeting Integration Tests
'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
spyOn
(
User
,
'
findOne
'
).
mockResolvedValue
({
id
:
1
,
name
:
'
Alice
'
,
email
:
'
alice@example.com
'
,
fcmTokenList
:
[]
});
});
test
(
'
should create meeting with correct schedules
'
,
async
()
=>
{
const
meetingData
=
{
title
:
'
Test Meeting
'
,
time_idx_start
:
50
,
time_idx_end
:
52
,
created_by
:
1
,
type
:
'
OPEN
'
,
max_num
:
5
};
const
meeting
=
await
MeetingService
.
createMeeting
(
meetingData
);
const
creatorSchedules
=
await
Schedule
.
findAll
({
where
:
{
user_id
:
1
,
title
:
`번개 모임:
${
meetingData
.
title
}
`
}
});
expect
(
creatorSchedules
.
length
).
toBe
(
3
);
expect
(
creatorSchedules
.
map
(
s
=>
s
.
time_idx
).
sort
()).
toEqual
([
50
,
51
,
52
]);
});
test
(
'
should create correct schedules when joining meeting
'
,
async
()
=>
{
const
meetingData
=
{
title
:
'
Join Test Meeting
'
,
time_idx_start
:
60
,
time_idx_end
:
62
,
created_by
:
1
,
type
:
'
OPEN
'
,
max_num
:
5
,
time_idx_deadline
:
59
};
const
meeting
=
await
MeetingService
.
createMeeting
(
meetingData
);
jest
.
spyOn
(
MeetingService
,
'
getCurrentTimeIdx
'
).
mockReturnValue
(
58
);
await
MeetingService
.
joinMeeting
(
meeting
.
meeting_id
,
2
);
const
participantSchedules
=
await
Schedule
.
findAll
({
where
:
{
user_id
:
2
,
title
:
`번개 모임:
${
meetingData
.
title
}
`
}
});
expect
(
participantSchedules
.
length
).
toBe
(
3
);
expect
(
participantSchedules
.
map
(
s
=>
s
.
time_idx
).
sort
()).
toEqual
([
60
,
61
,
62
]);
});
test
(
'
should handle schedule conflicts correctly
'
,
async
()
=>
{
await
ScheduleService
.
createSchedules
({
userId
:
2
,
title
:
'
Existing Schedule
'
,
is_fixed
:
true
,
time_indices
:
[
70
,
71
]
});
const
meetingData
=
{
title
:
'
Conflict Test Meeting
'
,
time_idx_start
:
70
,
time_idx_end
:
72
,
created_by
:
1
,
type
:
'
OPEN
'
,
max_num
:
5
,
time_idx_deadline
:
69
};
const
meeting
=
await
MeetingService
.
createMeeting
(
meetingData
);
await
expect
(
MeetingService
.
joinMeeting
(
meeting
.
meeting_id
,
2
)
).
rejects
.
toThrow
(
'
스케줄이 겹칩니다
'
);
});
});
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment