-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ted
committed
Jul 16, 2023
1 parent
3fde082
commit 588ac54
Showing
5 changed files
with
21 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
domain/src/main/kotlin/tw/waterballsa/gaas/exceptions/ForbiddenException.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ import tw.waterballsa.gaas.spring.models.TestGetRoomsRequest | |
import tw.waterballsa.gaas.spring.models.TestJoinRoomRequest | ||
import java.util.UUID.* | ||
import kotlin.reflect.KClass | ||
import tw.waterballsa.gaas.exceptions.ForbiddenException.Companion.Message | ||
|
||
|
||
class RoomControllerTest @Autowired constructor( | ||
|
@@ -277,7 +276,7 @@ class RoomControllerTest @Autowired constructor( | |
val playerB = createUser("2", "[email protected]", "winner1122").toRoomPlayer() | ||
val playerC = createUser("3", "[email protected]", "winner0033").toRoomPlayer() | ||
|
||
givenHostAndPlayersAreInTheRoom(host, playerB, playerC) | ||
givenHostAndPlayersJoinedTheRoom(host, playerB, playerC) | ||
.whenUserLeaveTheRoom(userA) | ||
.thenPlayerShouldBeNotInRoomAndHostIsChanged(host) | ||
} | ||
|
@@ -305,22 +304,22 @@ class RoomControllerTest @Autowired constructor( | |
} | ||
|
||
@Test | ||
fun giveHostAndPlayerBAreInRoomC_WhenHostGetRoomCInfo_ThenShouldReturnRoomCInfoSuccessfully() { | ||
fun giveHostAndPlayerBJoinedRoomC_WhenHostGetRoomC_ThenShouldGetRoomCSuccessfully() { | ||
val userA = testUser | ||
val host = userA.toRoomPlayer() | ||
val playerB = createUser("2", "[email protected]", "winner1122").toRoomPlayer() | ||
givenHostAndPlayersAreInTheRoom(host, playerB) | ||
givenHostAndPlayersJoinedTheRoom(host, playerB) | ||
.whenUserGetTheRoom(userA) | ||
.thenReturnRoomInfo() | ||
.thenGetRoomSuccessfully() | ||
} | ||
|
||
@Test | ||
fun giveUserANotInRoomB_WhenUserAGetRoomBInfo_ThenShouldNotReceiveRoomBInfo(){ | ||
fun giveUserANotJoinedRoomB_WhenUserAGetRoomB_ThenShouldFail() { | ||
val userA = testUser | ||
val host = createUser("2", "[email protected]", "winner1122").toRoomPlayer() | ||
givenHostAndPlayersAreInTheRoom(host) | ||
givenHostAndPlayersJoinedTheRoom(host) | ||
.whenUserGetTheRoom(userA) | ||
.thenShouldNotReceiveRoomInfo(Message.NOT_IN_ROOM.toString()) | ||
.thenShouldFail("Player(" + userA.id!!.value + ") is not in the room(" + testRoom.roomId!!.value + ").") | ||
} | ||
|
||
private fun TestGetRoomsRequest.whenUserAVisitLobby(joinUser: User): ResultActions = | ||
|
@@ -382,10 +381,10 @@ class RoomControllerTest @Autowired constructor( | |
.withJwt(leaveUser) | ||
) | ||
|
||
private fun getRoom(user: Jwt): ResultActions = | ||
private fun getRoom(user: User): ResultActions = | ||
mockMvc.perform( | ||
get("/rooms/${testRoom.roomId!!.value}") | ||
.withJwt(user) | ||
.withJwt(mockUserJwt(user)) | ||
) | ||
|
||
private fun givenTheHostCreatePublicRoom(host: User): Room { | ||
|
@@ -398,7 +397,7 @@ class RoomControllerTest @Autowired constructor( | |
return testRoom | ||
} | ||
|
||
private fun givenHostAndPlayersAreInTheRoom(host: Player, vararg players: Player): Room { | ||
private fun givenHostAndPlayersJoinedTheRoom(host: Player, vararg players: Player): Room { | ||
val combinedPlayers = (listOf(host) + players).toMutableList() | ||
testRoom = createRoom(host, combinedPlayers) | ||
return testRoom | ||
|
@@ -420,7 +419,7 @@ class RoomControllerTest @Autowired constructor( | |
return leaveRoom(leaveUser) | ||
} | ||
|
||
private fun Room.whenUserGetTheRoom(user: User) = getRoom(user.id!!.value.toJwt()) | ||
private fun Room.whenUserGetTheRoom(user: User) = getRoom(user) | ||
|
||
private fun ResultActions.thenCreateRoomSuccessfully(request: TestCreateRoomRequest) { | ||
request.let { | ||
|
@@ -460,7 +459,7 @@ class RoomControllerTest @Autowired constructor( | |
assertFalse(room.isHost(player.id)) | ||
} | ||
|
||
private fun ResultActions.thenReturnRoomInfo() { | ||
private fun ResultActions.thenGetRoomSuccessfully() { | ||
val room = roomRepository.findById(testRoom.roomId!!)!! | ||
room.let { | ||
andExpect(status().isOk) | ||
|
@@ -487,11 +486,6 @@ class RoomControllerTest @Autowired constructor( | |
} | ||
} | ||
|
||
private fun ResultActions.thenShouldNotReceiveRoomInfo(message: String): ResultActions { | ||
return andExpect(status().isForbidden) | ||
.andExpect(jsonPath("$.message").value(message)) | ||
} | ||
|
||
private fun createUser(id: String, email: String, nickname: String): User = | ||
userRepository.createUser(User(User.Id(id), email, nickname)) | ||
|
||
|
@@ -588,9 +582,6 @@ class RoomControllerTest @Autowired constructor( | |
private fun User.toRoomPlayer(): Player = | ||
Player(Player.Id(id!!.value), nickname) | ||
|
||
private fun Room.hasPlayer(playerId: Player.Id): Boolean = | ||
players.any { it.id == playerId } | ||
|
||
private fun Room.isHost(playerId: Player.Id): Boolean = | ||
host.id == playerId | ||
} |