Skip to content

Commit

Permalink
feat : 그룹 역할 수정 시 OWNER로 수정할 경우 스터디장 위임 로직 추가 (#234)
Browse files Browse the repository at this point in the history
* feat : 그룹 멤버를 OWNER로 수정할 경우, 자신은 PARTICIPANT로 수정

* test : 그룹 멤버를 OWNER로 수정할 경우, 자신은 PARTICIPANT로 수정 테스트 작성
  • Loading branch information
rladmstn authored Dec 8, 2024
1 parent e2d47a4 commit fde5e36
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit fde5e36

Please sign in to comment.