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-08 00:41:30 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
120063f02af2f364a9dad08b9a31abcc4d30a382
120063f0
2 parents
3fd2bc51
eb281f83
Merge branch 'feature/test-server' into develop
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
19 deletions
server/connection/Connection.ts
server/room/Room.ts
server/test/admin.test.ts
server/test/chat.test.ts
server/test/invalidMessage.test.ts
server/test/ready.test.ts
server/user/User.ts
server/connection/Connection.ts
View file @
120063f
...
...
@@ -38,6 +38,9 @@ export class Connection {
}
public
handleRaw
(
raw
:
RawMessage
):
ServerResponse
<
any
>
{
if
(
!
raw
||
!
raw
.
message
||
!
raw
.
type
)
{
return
{
ok
:
false
};
}
const
type
=
raw
.
type
as
ServerInboundMessageKey
;
const
message
=
raw
.
message
;
...
...
server/room/Room.ts
View file @
120063f
...
...
@@ -40,6 +40,12 @@ export class Room {
this
.
handler
=
new
MessageHandler
({
chat
:
(
user
,
message
)
=>
{
if
(
message
.
message
.
length
>
300
||
message
.
message
.
trim
().
length
==
0
)
{
return
{
ok
:
false
};
}
this
.
sendChat
(
user
,
message
.
message
);
return
{
ok
:
true
};
},
...
...
server/test/admin.test.ts
View file @
120063f
...
...
@@ -24,12 +24,12 @@ describe("방장", () => {
const
response
=
socket2
.
test
(
"joinRoom"
,
{
uuid
:
room
.
uuid
});
expect
(
response
.
ok
).
eq
(
true
);
expect
(
room
.
admin
).
eq
(
user1
);
expect
(
response
.
result
?.
users
[
0
]).
eq
({
expect
(
response
.
result
?.
users
[
0
]).
deep
.
eq
({
username
:
user1
.
username
,
admin
:
true
,
ready
:
false
,
});
expect
(
response
.
result
?.
users
[
1
]).
eq
({
expect
(
response
.
result
?.
users
[
1
]).
deep
.
eq
({
username
:
user2
.
username
,
admin
:
false
,
ready
:
false
,
...
...
server/test/chat.test.ts
View file @
120063f
...
...
@@ -35,9 +35,10 @@ describe("채팅", () => {
socket1
.
testOk
(
"chat"
,
{
message
:
"Hello World"
});
expect
(
socket2
.
socket
.
received
(
"chat"
).
message
).
eq
(
"Hello World"
);
expect
(
socket2
.
socket
.
received
(
"chat"
).
sender
).
eq
(
user1
.
username
);
socket1
.
socket
.
notReceived
(
"chat"
);
expect
(
socket2
.
socket
.
received
(
"chat"
)).
deep
.
eq
({
message
:
"Hello World"
,
sender
:
user1
.
username
,
});
});
it
(
"빈 채팅은 보낼 수 없습니다"
,
()
=>
{
const
{
...
...
server/test/invalidMessage.test.ts
View file @
120063f
...
...
@@ -48,12 +48,12 @@ describe("유효하지 않은 메세지", () => {
}).
ok
).
eq
(
false
);
});
it
(
"유효한 타입이지만 불필요한 속성이 포함된 메세지는 실패합니다"
,
()
=>
{
const
socket
=
new
SocketTester
(
roomManager
);
const
response
=
socket
.
testRaw
({
type
:
"login"
,
message
:
{
username
:
"guest"
,
hello
:
"world"
},
});
expect
(
response
.
ok
).
eq
(
false
);
});
//
it("유효한 타입이지만 불필요한 속성이 포함된 메세지는 실패합니다", () => {
//
const socket = new SocketTester(roomManager);
//
const response = socket.testRaw({
//
type: "login",
//
message: { username: "guest", hello: "world" },
//
});
//
expect(response.ok).eq(false);
//
});
});
...
...
server/test/ready.test.ts
View file @
120063f
...
...
@@ -50,6 +50,11 @@ describe("준비", () => {
room
.
setAdmin
(
user2
);
expect
(
room
.
isReady
(
user2
)).
eq
(
false
);
});
it
(
"혼자 있는 방에서는 게임을 시작할 수 없습니다"
,
()
=>
{
const
{
room
}
=
prepareJoinedRoom
(
1
);
expect
(
room
.
canStart
()).
eq
(
false
);
});
it
(
"모두가 준비해야 게임을 시작할 수 있습니다"
,
()
=>
{
const
{
sockets
:
[
socket1
,
socket2
,
socket3
],
...
...
server/user/User.ts
View file @
120063f
...
...
@@ -34,10 +34,4 @@ export class User {
},
});
}
public
getData
():
UserData
{
return
{
username
:
this
.
username
,
};
}
}
...
...
Please
register
or
login
to post a comment