Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
강동현
2021-06-09 22:29:27 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4283cc0ee3fc19da05b80401708b69b8c99e6dd2
4283cc0e
1 parent
8e444de7
닉네임 로그인 테스트 작성, 기존 테스트 코드 닉네임으로 변경
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
34 deletions
server/test/admin.test.ts
server/test/joinRoom.test.ts
server/test/login.test.ts
server/test/ready.test.ts
server/test/util/SocketTester.ts
server/test/admin.test.ts
View file @
4283cc0
...
...
@@ -24,16 +24,14 @@ describe("방장", () => {
const
response
=
socket2
.
test
(
"joinRoom"
,
{
uuid
:
room
.
uuid
});
expect
(
response
.
ok
).
eq
(
true
);
expect
(
room
.
admin
).
eq
(
user1
);
expect
(
response
.
result
?.
users
[
0
]).
deep
.
eq
({
username
:
user1
.
username
,
admin
:
true
,
ready
:
false
,
});
expect
(
response
.
result
?.
users
[
1
]).
deep
.
eq
({
username
:
user2
.
username
,
admin
:
false
,
ready
:
false
,
});
expect
(
response
.
result
?.
users
[
0
].
nickname
).
eq
(
user1
.
nickname
);
expect
(
response
.
result
?.
users
[
0
].
admin
).
eq
(
true
);
expect
(
response
.
result
?.
users
[
0
].
ready
).
eq
(
false
);
expect
(
response
.
result
?.
users
[
1
].
nickname
).
eq
(
user2
.
nickname
);
expect
(
response
.
result
?.
users
[
1
].
admin
).
eq
(
false
);
expect
(
response
.
result
?.
users
[
1
].
ready
).
eq
(
false
);
});
it
(
"방장이 나가면 방장이 인계됩니다"
,
()
=>
{
const
{
...
...
server/test/joinRoom.test.ts
View file @
4283cc0
...
...
@@ -14,6 +14,7 @@ describe("방 입장", () => {
it
(
"방에 입장합니다"
,
()
=>
{
const
{
sockets
:
[
socket
],
users
:
[
user
],
rooms
:
[
room
],
}
=
prepareUsersEmptyRooms
(
1
,
1
);
...
...
@@ -23,16 +24,17 @@ describe("방 입장", () => {
expect
(
response
.
result
?.
name
).
eq
(
room
.
name
);
expect
(
response
.
result
?.
maxUsers
).
eq
(
room
.
maxUsers
);
expect
(
response
.
result
?.
users
?.
length
).
eq
(
1
);
expect
(
response
.
result
?.
users
[
0
]?.
username
).
eq
(
"guest1"
);
expect
(
response
.
result
?.
users
[
0
]?.
nickname
).
eq
(
user
.
nickname
);
});
it
(
"방에 입장하면 유저 목록이 업데이트 됩니다"
,
()
=>
{
const
{
sockets
:
[
socket1
,
socket2
],
users
:
[
user1
,
user2
],
}
=
prepareJoinedRoom
(
2
);
const
updated
=
socket1
.
socket
.
received
(
"updateRoomUser"
);
expect
(
updated
.
state
).
eq
(
"added"
);
expect
(
updated
.
user
.
username
).
eq
(
"guest2"
);
expect
(
updated
.
user
.
nickname
).
eq
(
user2
.
nickname
);
});
it
(
"방에 이미 입장한 상태에서 다른 방에 입장할 수 없습니다"
,
()
=>
{
const
{
...
...
server/test/login.test.ts
View file @
4283cc0
...
...
@@ -3,10 +3,22 @@ import { RoomManager } from "../room/RoomManager";
import
{
SocketTester
}
from
"./util/SocketTester"
;
describe
(
"로그인"
,
()
=>
{
it
(
"로그인합니다"
,
()
=>
{
it
(
"
닉네임으로
로그인합니다"
,
()
=>
{
const
roomManager
=
new
RoomManager
();
const
socket
=
new
SocketTester
(
roomManager
);
socket
.
testOk
(
"login"
,
{
username
:
"guest"
});
expect
(
socket
.
connection
.
user
?.
username
).
eq
(
"guest"
);
socket
.
testOk
(
"login"
,
{
nickname
:
"guest"
});
expect
(
socket
.
connection
.
user
?.
nickname
).
eq
(
"guest"
);
});
it
(
"빈 닉네임으로 로그인할 수 없습니다"
,
()
=>
{
const
roomManager
=
new
RoomManager
();
const
socket
=
new
SocketTester
(
roomManager
);
socket
.
testNotOk
(
"login"
,
{
nickname
:
""
});
socket
.
testNotOk
(
"login"
,
{
nickname
:
" "
});
});
it
(
"닉네임은 최대 12자입니다"
,
()
=>
{
const
roomManager
=
new
RoomManager
();
const
socket
=
new
SocketTester
(
roomManager
);
socket
.
testNotOk
(
"login"
,
{
nickname
:
"a"
.
repeat
(
13
)
});
socket
.
testNotOk
(
"login"
,
{
nickname
:
"가"
.
repeat
(
13
)
});
});
});
...
...
server/test/ready.test.ts
View file @
4283cc0
...
...
@@ -7,12 +7,13 @@ describe("준비", () => {
it
(
"방에 입장하면 준비되지 않은 상태입니다"
,
()
=>
{
const
{
sockets
:
[
socket
],
users
:
[
user
],
rooms
:
[
room
],
}
=
prepareUsersEmptyRooms
(
1
,
1
);
const
response
=
socket
.
test
(
"joinRoom"
,
{
uuid
:
room
.
uuid
});
expect
(
response
.
ok
).
eq
(
true
);
expect
(
response
.
result
?.
users
[
0
]?.
username
).
eq
(
"guest1"
);
expect
(
response
.
result
?.
users
[
0
]?.
nickname
).
eq
(
user
.
nickname
);
expect
(
response
.
result
?.
users
[
0
]?.
ready
).
eq
(
false
);
});
it
(
"준비 상태를 설정합니다"
,
()
=>
{
...
...
@@ -26,25 +27,19 @@ describe("준비", () => {
socket
.
testOk
(
"ready"
,
{
ready
:
true
});
expect
(
room
.
isReady
(
user
)).
eq
(
true
);
expect
(
socket
.
socket
.
received
(
"updateRoomUser"
)).
deep
.
eq
({
state
:
"updated"
,
user
:
{
username
:
user
.
username
,
admin
:
false
,
ready
:
true
,
},
});
let
response
=
socket
.
socket
.
received
(
"updateRoomUser"
);
expect
(
response
.
state
).
eq
(
"updated"
);
expect
(
response
.
user
.
nickname
).
eq
(
user
.
nickname
);
expect
(
response
.
user
.
ready
).
eq
(
true
);
socket
.
testOk
(
"ready"
,
{
ready
:
false
});
expect
(
room
.
isReady
(
user
)).
eq
(
false
);
expect
(
socket
.
socket
.
received
(
"updateRoomUser"
)).
deep
.
eq
({
state
:
"updated"
,
user
:
{
username
:
user
.
username
,
admin
:
false
,
ready
:
false
,
},
});
response
=
socket
.
socket
.
received
(
"updateRoomUser"
);
expect
(
response
.
state
).
eq
(
"updated"
);
expect
(
response
.
user
.
nickname
).
eq
(
user
.
nickname
);
expect
(
response
.
user
.
ready
).
eq
(
false
);
});
it
(
"방장은 준비할 수 없습니다"
,
()
=>
{
const
{
...
...
server/test/util/SocketTester.ts
View file @
4283cc0
...
...
@@ -49,8 +49,8 @@ export class SocketTester {
return
this
.
connection
.
handleRaw
(
obj
);
}
public
login
(
user
name
:
string
):
void
{
this
.
testOk
(
"login"
,
{
user
name
});
public
login
(
nick
name
:
string
):
void
{
this
.
testOk
(
"login"
,
{
nick
name
});
expect
(
this
.
connection
.
user
!==
undefined
).
eq
(
true
);
}
...
...
Please
register
or
login
to post a comment