Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : 그룹 역할 수정 시 OWNER로 수정할 경우 스터디장 위임 로직 추가 #234

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.time.LocalDate;

import org.hibernate.annotations.DynamicUpdate;

import com.gamzabat.algohub.feature.group.studygroup.etc.RoleOfGroupMember;
import com.gamzabat.algohub.feature.user.domain.User;

Expand All @@ -22,6 +24,7 @@
@Entity
@Getter
@NoArgsConstructor
@DynamicUpdate
public class GroupMember {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ public void updateGroupMemberRole(User user, Long groupId, UpdateGroupMemberRole
() -> new GroupMemberValidationException(HttpStatus.BAD_REQUEST.value(), "해당 스터디 그룹에 참여하지 않은 회원입니다."));

member.updateRole(RoleOfGroupMember.fromValue(request.role()));

if (RoleOfGroupMember.isOwner(member)) {
owner.updateRole(RoleOfGroupMember.PARTICIPANT);
}
log.info("success to update group member role");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ void updateBookmarkedStudyGroupFailed_2() {

@Test
@DisplayName("스터디 그룹 멤버 역할 수정 성공")
void updateGroupMemberRole() {
void updateGroupMemberRole_1() {
// given
UpdateGroupMemberRoleRequest request = new UpdateGroupMemberRoleRequest(2L, "ADMIN");
when(groupMemberRepository.findByUserAndStudyGroup(user, group)).thenReturn(Optional.ofNullable(groupMember1));
Expand All @@ -619,6 +619,24 @@ void updateGroupMemberRole() {
assertThat(groupMember2.getRole()).isEqualTo(RoleOfGroupMember.ADMIN);
}

@Test
@DisplayName("스터디 그룹 멤버 역할 수정 성공 : OWNER로 수정")
void updateGroupMemberRole_2() {
// given
UpdateGroupMemberRoleRequest request = new UpdateGroupMemberRoleRequest(2L, "OWNER");
when(groupMemberRepository.findByUserAndStudyGroup(user, group)).thenReturn(Optional.ofNullable(groupMember1));
when(groupMemberRepository.findByUserAndStudyGroup(user2, group)).thenReturn(Optional.ofNullable(groupMember2));
when(studyGroupRepository.findById(groupId)).thenReturn(Optional.ofNullable(group));
when(userRepository.findById(anyLong())).thenReturn(Optional.ofNullable(user2));
// when
studyGroupService.updateGroupMemberRole(user, groupId, request);
// then
assertThat(groupMember2.getUser()).isEqualTo(user2);
assertThat(groupMember2.getStudyGroup()).isEqualTo(group);
assertThat(groupMember2.getRole()).isEqualTo(RoleOfGroupMember.OWNER);
assertThat(groupMember1.getRole()).isEqualTo(RoleOfGroupMember.PARTICIPANT);
}

@Test
@DisplayName("스터디 그룹 멤버 역할 수정 실패 : 존재하지 않는 그룹")
void updateGroupMemberRoleFailed_1() {
Expand Down
Loading