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
a761f6de
Commit
a761f6de
authored
6 months ago
by
tpgus2603
Browse files
Options
Downloads
Patches
Plain Diff
bugfix/
#11
parent
5f0d6b6d
No related branches found
No related tags found
2 merge requests
!31
Develop
,
!14
[#11] dto설정, 프렌드,서비스로직 테스트 및 로직변경
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/friendService.test.js
+177
-175
177 additions, 175 deletions
test/friendService.test.js
test/friendrelation.test.js
+0
-11
0 additions, 11 deletions
test/friendrelation.test.js
with
177 additions
and
186 deletions
test/friendService.test.js
+
177
−
175
View file @
a761f6de
...
...
@@ -9,12 +9,10 @@ const friendService = require('../services/friendService'); // FriendService 임
const
{
Op
}
=
require
(
'
sequelize
'
);
beforeAll
(
async
()
=>
{
// 테스트 전에 데이터베이스를 동기화하고 테이블을 생성합니다.
await
sequelize
.
sync
({
force
:
true
});
});
beforeEach
(
async
()
=>
{
// 각 테스트 전에 데이터베이스를 초기화하여 독립성을 보장합니다.
await
sequelize
.
sync
({
force
:
true
});
// 더미 사용자 생성
...
...
@@ -45,11 +43,12 @@ describe('Friend Service', () => {
describe
(
'
sendFriendRequest
'
,
()
=>
{
test
(
'
should send a friend request successfully
'
,
async
()
=>
{
const
friendRequest
=
await
friendService
.
sendFriendRequest
(
1
,
3
);
// Alice sends request to Charlie
expect
(
friendRequest
).
toBeDefined
();
expect
(
friendRequest
.
requester_id
).
toBe
(
1
);
expect
(
friendRequest
.
receiver_id
).
toBe
(
3
);
expect
(
friendRequest
.
status
).
toBe
(
'
PENDING
'
);
const
friendRequestDTO
=
await
friendService
.
sendFriendRequest
(
1
,
3
);
// Alice sends request to Charlie
console
.
log
(
'
sendFriendRequest DTO:
'
,
friendRequestDTO
);
// 디버깅을 위한 로그 추가
expect
(
friendRequestDTO
).
toBeDefined
();
expect
(
friendRequestDTO
.
requester
.
id
).
toBe
(
1
);
expect
(
friendRequestDTO
.
receiver
.
id
).
toBe
(
3
);
expect
(
friendRequestDTO
.
status
).
toBe
(
'
PENDING
'
);
});
test
(
'
should throw error when sending friend request to self
'
,
async
()
=>
{
...
...
@@ -57,12 +56,12 @@ describe('Friend Service', () => {
});
test
(
'
should throw error when sending duplicate friend request
'
,
async
()
=>
{
// Alice sends a friend request to Bob
await
friendService
.
sendFriendRequest
(
1
,
2
);
// Bob accepts Alice's request
await
friendService
.
acceptFriendRequest
(
2
,
1
);
// Alice tries to send another friend request to Bob
await
expect
(
friendService
.
sendFriendRequest
(
1
,
2
)).
rejects
.
toThrow
(
'
Friend request already exists
'
);
});
...
...
@@ -82,14 +81,13 @@ describe('Friend Service', () => {
});
test
(
'
not send request
'
,
async
()
=>
{
const
receivedRequests
=
await
friendService
.
getReceivedRequests
(
2
);
const
receivedRequests
=
await
friendService
.
getReceivedRequests
(
2
);
// Bob has no pending requests
expect
(
receivedRequests
.
length
).
toBe
(
0
);
});
});
describe
(
'
getSentRequests
'
,
()
=>
{
test
(
'
should retrieve sent friend requests
'
,
async
()
=>
{
await
friendService
.
sendFriendRequest
(
1
,
3
);
const
sentRequests
=
await
friendService
.
getSentRequests
(
1
);
...
...
@@ -105,12 +103,11 @@ describe('Friend Service', () => {
describe
(
'
acceptFriendRequest
'
,
()
=>
{
test
(
'
should accept a pending friend request successfully
'
,
async
()
=>
{
await
friendService
.
sendFriendRequest
(
3
,
1
);
const
updatedRequest
=
await
friendService
.
acceptFriendRequest
(
1
,
3
);
expect
(
updatedRequest
).
toBeDefined
();
expect
(
updatedRequest
.
status
).
toBe
(
'
ACCEPTED
'
);
const
updatedRequest
DTO
=
await
friendService
.
acceptFriendRequest
(
1
,
3
);
expect
(
updatedRequest
DTO
).
toBeDefined
();
expect
(
updatedRequest
DTO
.
status
).
toBe
(
'
ACCEPTED
'
);
// Db상태 확인
const
request
=
await
Friend
.
findOne
({
...
...
@@ -122,17 +119,15 @@ describe('Friend Service', () => {
expect
(
request
.
status
).
toBe
(
'
ACCEPTED
'
);
});
test
(
'
없는 요청수락
'
,
async
()
=>
{
test
(
'
should throw error when accepting non-existing friend request
'
,
async
()
=>
{
await
expect
(
friendService
.
acceptFriendRequest
(
1
,
999
)).
rejects
.
toThrow
(
'
Friend request not found
'
);
});
});
describe
(
'
rejectFriendRequest
'
,
()
=>
{
test
(
'
should reject a pending friend request successfully
'
,
async
()
=>
{
await
friendService
.
sendFriendRequest
(
2
,
3
);
const
result
=
await
friendService
.
rejectFriendRequest
(
3
,
2
);
expect
(
result
).
toBe
(
1
);
...
...
@@ -172,16 +167,26 @@ describe('Friend Service', () => {
await
friendService
.
acceptFriendRequest
(
i
,
1
);
}
// Alice 친구: Bob (2), Charlie (3),User4
to
User23
(20 friends
)
// Alice 친구: Bob (2), Charlie (3),
User4
부터
User23
까지 (총 22명
)
const
limit
=
5
;
const
offset
=
0
;
const
friendsPage1
=
await
friendService
.
getFriendList
(
1
,
limit
,
offset
);
//console.log('getFriendList Page 1:', friendsPage1); // 디버깅을 위한 로그 추가
expect
(
friendsPage1
.
length
).
toBe
(
limit
);
expect
([
'
Bob
'
,
'
Charlie
'
,
'
User4
'
,
'
User5
'
,
'
User6
'
]).
toContain
(
friendsPage1
[
0
].
friendInfo
.
name
);
const
expectedNamesPage1
=
[
'
Bob
'
,
'
Charlie
'
,
'
User4
'
,
'
User5
'
,
'
User6
'
];
const
receivedNamesPage1
=
friendsPage1
.
map
(
friend
=>
friend
.
friendInfo
.
name
);
expectedNamesPage1
.
forEach
(
name
=>
{
expect
(
receivedNamesPage1
).
toContain
(
name
);
});
const
friendsPage2
=
await
friendService
.
getFriendList
(
1
,
limit
,
limit
);
//console.log('getFriendList Page 2:', friendsPage2); // 디버깅을 위한 로그 추가
expect
(
friendsPage2
.
length
).
toBe
(
limit
);
expect
([
'
User7
'
,
'
User8
'
,
'
User9
'
,
'
User10
'
,
'
User11
'
]).
toContain
(
friendsPage2
[
0
].
friendInfo
.
name
);
const
expectedNamesPage2
=
[
'
User7
'
,
'
User8
'
,
'
User9
'
,
'
User10
'
,
'
User11
'
];
const
receivedNamesPage2
=
friendsPage2
.
map
(
friend
=>
friend
.
friendInfo
.
name
);
expectedNamesPage2
.
forEach
(
name
=>
{
expect
(
receivedNamesPage2
).
toContain
(
name
);
});
});
test
(
'
should return empty array when user has no friends
'
,
async
()
=>
{
...
...
@@ -192,15 +197,12 @@ describe('Friend Service', () => {
describe
(
'
deleteFriend
'
,
()
=>
{
test
(
'
should delete an existing friend relationship successfully
'
,
async
()
=>
{
await
friendService
.
sendFriendRequest
(
1
,
2
);
await
friendService
.
acceptFriendRequest
(
2
,
1
);
const
result
=
await
friendService
.
deleteFriend
(
1
,
2
);
expect
(
result
).
toBe
(
1
);
const
relationship
=
await
Friend
.
findOne
({
where
:
{
[
Op
.
or
]:
[
...
...
This diff is collapsed.
Click to expand it.
test/friendrelation.test.js
+
0
−
11
View file @
a761f6de
...
...
@@ -94,17 +94,6 @@ describe('User and Friend Relationships', () => {
expect
(
bob
.
sentRequests
[
0
].
receiver
.
name
).
toBe
(
'
Alice
'
);
});
test
(
'
self friend reqeust
'
,
async
()
=>
{
await
expect
(
Friend
.
create
({
id
:
3
,
requester_id
:
1
,
receiver_id
:
1
,
// 자신에게 요청
status
:
'
PENDING
'
,
})
).
rejects
.
toThrow
();
});
test
(
'
already request test
'
,
async
()
=>
{
// Alice가 Bob에게 이미 친구 요청을 보냈으므로, 다시 보내면 에러 발생
await
expect
(
...
...
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