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
a0e5e827
Commit
a0e5e827
authored
4 months ago
by
조대희
Browse files
Options
Downloads
Patches
Plain Diff
refactor: friend pagination 변경에 따른 테스트 코드 수정 (
#19
)
parent
8eda3e9c
Branches
Branches containing commit
No related tags found
2 merge requests
!31
Develop
,
!26
[#19] 통합 테스트 제작 및 서비스 로직 추가/수정
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/friendService.test.js
+54
-27
54 additions, 27 deletions
services/friendService.test.js
with
54 additions
and
27 deletions
services/friendService.test.js
+
54
−
27
View file @
a0e5e827
...
...
@@ -143,50 +143,77 @@ describe('Friend Service', () => {
});
describe
(
'
getFriendList
'
,
()
=>
{
test
(
'
should retrieve friend list with correct pagination
'
,
async
()
=>
{
beforeEach
(
async
()
=>
{
await
friendService
.
sendFriendRequest
(
1
,
2
);
await
friendService
.
acceptFriendRequest
(
2
,
1
);
await
friendService
.
sendFriendRequest
(
1
,
3
);
await
friendService
.
acceptFriendRequest
(
3
,
1
);
// 추가 더미데이터 생성
for
(
let
i
=
4
;
i
<=
23
;
i
++
)
{
// Create dummy users
await
User
.
create
({
id
:
i
,
name
:
`User
${
i
}
`
,
email
:
`user
${
i
}
@example.com`
,
});
// Alice랑 친구맺기
await
friendService
.
sendFriendRequest
(
1
,
i
);
await
friendService
.
acceptFriendRequest
(
i
,
1
);
}
// Alice 친구: Bob (2), Charlie (3), User4부터 User23까지 (총 22명)
const
limit
=
5
;
const
offset
=
0
;
const
friendsPage1
=
await
friendService
.
getFriendList
(
1
,
limit
,
offset
);
expect
(
friendsPage1
.
length
).
toBe
(
limit
);
const
expectedNamesPage1
=
[
'
Bob
'
,
'
Charlie
'
,
'
User4
'
,
'
User5
'
,
'
User6
'
];
const
receivedNamesPage1
=
friendsPage1
.
map
(
friend
=>
friend
.
friendInfo
.
name
);
expectedNamesPage1
.
forEach
(
name
=>
{
expect
(
receivedNamesPage1
).
toContain
(
name
);
});
test
(
'
작은 size로 여러 페이지 조회
'
,
async
()
=>
{
const
size
=
10
;
// 첫 페이지
const
page1
=
await
friendService
.
getFriendList
(
1
,
{
limit
:
size
,
offset
:
0
});
const
friendsPage2
=
await
friendService
.
getFriendList
(
1
,
limit
,
limit
);
expect
(
friendsPage2
.
length
).
toBe
(
limit
);
const
expectedNamesPage2
=
[
'
User7
'
,
'
User8
'
,
'
User9
'
,
'
User10
'
,
'
User11
'
];
const
receivedNamesPage2
=
friendsPage2
.
map
(
friend
=>
friend
.
friendInfo
.
name
);
expectedNamesPage2
.
forEach
(
name
=>
{
expect
(
receivedNamesPage2
).
toContain
(
name
);
expect
(
page1
.
content
.
length
).
toBe
(
size
);
expect
(
page1
.
hasNext
).
toBe
(
true
);
// 두 번째 페이지
const
page2
=
await
friendService
.
getFriendList
(
1
,
{
limit
:
size
,
offset
:
size
});
expect
(
page2
.
content
.
length
).
toBe
(
size
);
expect
(
page2
.
hasNext
).
toBe
(
true
);
// 마지막 페이지
const
page3
=
await
friendService
.
getFriendList
(
1
,
{
limit
:
size
,
offset
:
size
*
2
});
expect
(
page3
.
content
.
length
).
toBe
(
2
);
expect
(
page3
.
hasNext
).
toBe
(
false
);
});
test
(
'
should return empty array when user has no friends
'
,
async
()
=>
{
const
friends
=
await
friendService
.
getFriendList
(
999
);
// Non-existing user
expect
(
friends
.
length
).
toBe
(
0
);
test
(
'
페이지 순서 검증
'
,
async
()
=>
{
const
size
=
5
;
const
page1
=
await
friendService
.
getFriendList
(
1
,
{
limit
:
size
,
offset
:
0
});
const
page2
=
await
friendService
.
getFriendList
(
1
,
{
limit
:
size
,
offset
:
size
});
const
names1
=
page1
.
content
.
map
(
friend
=>
friend
.
friendInfo
.
name
);
const
names2
=
page2
.
content
.
map
(
friend
=>
friend
.
friendInfo
.
name
);
expect
(
names1
).
toEqual
([
'
Bob
'
,
'
Charlie
'
,
'
User4
'
,
'
User5
'
,
'
User6
'
]);
expect
(
names2
).
toEqual
([
'
User7
'
,
'
User8
'
,
'
User9
'
,
'
User10
'
,
'
User11
'
]);
});
test
(
'
존재하지 않는 페이지 조회
'
,
async
()
=>
{
const
response
=
await
friendService
.
getFriendList
(
1
,
{
limit
:
20
,
offset
:
100
});
expect
(
response
.
content
).
toHaveLength
(
0
);
expect
(
response
.
hasNext
).
toBe
(
false
);
});
});
...
...
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