-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
4 changed files
with
77 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package site.youtogether.user; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import site.youtogether.exception.user.HigherOrEqualRoleUserChangeException; | ||
|
||
class UserTest { | ||
|
||
@Test | ||
@DisplayName("자신보다 낮은 역할의 유저를 자신과 같은 역할까지 올릴 수 있다") | ||
void changeRole() { | ||
// given | ||
String roomCode = "room code"; | ||
|
||
User host = User.builder() | ||
.id(1L) | ||
.currentRoomCode(roomCode) | ||
.build(); | ||
host.getHistory().put(roomCode, Role.HOST); | ||
User targetUser = User.builder() | ||
.id(2L) | ||
.currentRoomCode(roomCode) | ||
.build(); | ||
targetUser.getHistory().put(roomCode, Role.VIEWER); | ||
|
||
// when | ||
host.changeOtherUserRole(roomCode, targetUser, Role.HOST); | ||
|
||
// then | ||
assertThat(targetUser.getRoleInCurrentRoom()).isEqualTo(Role.HOST); | ||
} | ||
|
||
@Test | ||
@DisplayName("자신과 동일하거나 높은 유저의 역할은 변경할 수 없다") | ||
void changeRoleFail() { | ||
// given | ||
String roomCode = "room code"; | ||
|
||
User manager = User.builder() | ||
.id(1L) | ||
.currentRoomCode(roomCode) | ||
.build(); | ||
manager.getHistory().put(roomCode, Role.MANAGER); | ||
User targetUser = User.builder() | ||
.id(2L) | ||
.currentRoomCode(roomCode) | ||
.build(); | ||
targetUser.getHistory().put(roomCode, Role.MANAGER); | ||
|
||
// when / then | ||
assertThatThrownBy(() -> manager.changeOtherUserRole(roomCode, targetUser, Role.GUEST)) | ||
.isInstanceOf(HigherOrEqualRoleUserChangeException.class); | ||
} | ||
|
||
} |