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

다락방 멤버 조회 권한 삭제 #586

Merged
merged 3 commits into from
Oct 4, 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 @@ -13,20 +13,17 @@
import mouda.backend.darakbangmember.presentation.response.DarakbangMemberResponses;
import mouda.backend.darakbangmember.presentation.response.DarakbangMemberRoleResponse;
import mouda.backend.member.domain.Member;
import mouda.backend.member.implement.MemberValidator;

@Service
@Transactional
@RequiredArgsConstructor
public class DarakbangMemberService {

private final MemberValidator memberValidator;
private final DarakbangMemberFinder darakbangMemberFinder;
private final DarakbangFinder darakbangFinder;

@Transactional(readOnly = true)
public DarakbangMemberResponses findAllDarakbangMembers(Long darakbangId, DarakbangMember member) {
memberValidator.validateNotManager(member);
DarakbangMembers darakbangMembers = darakbangMemberFinder.findAllDarakbangMembers(darakbangId);

return DarakbangMemberResponses.toResponse(darakbangMembers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

Expand All @@ -13,9 +15,10 @@
import mouda.backend.common.fixture.MemberFixture;
import mouda.backend.darakbang.domain.Darakbang;
import mouda.backend.darakbang.infrastructure.DarakbangRepository;
import mouda.backend.darakbangmember.domain.DarakBangMemberRole;
import mouda.backend.darakbangmember.domain.DarakbangMember;
import mouda.backend.darakbangmember.exception.DarakbangMemberException;
import mouda.backend.darakbangmember.infrastructure.DarakbangMemberRepository;
import mouda.backend.darakbangmember.presentation.response.DarakbangMemberResponses;
import mouda.backend.darakbangmember.presentation.response.DarakbangMemberRoleResponse;
import mouda.backend.member.domain.Member;
import mouda.backend.member.infrastructure.MemberRepository;
Expand All @@ -35,23 +38,6 @@ class DarakbangMemberServiceTest {
@Autowired
private DarakbangMemberService darakbangMemberService;

@DisplayName("다락방 멤버 조회 테스트")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

당연하게 이루어지는거긴 하지만~ 관리자가 아니면 실패하는 테스트를 지웠다면 관리자가 아니어도 조회할 수 있는 테스트를 추가할 수도 있겠네요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호랏~ 좋네요 추가했습니당

@Nested
class DarakbangMemberReadTest {

@DisplayName("다락방 관리자가 아니라면 멤버 조회에 실패한다.")
@Test
void failToReadWithoutDarakbangManager() {
Member hogee = memberRepository.save(MemberFixture.getHogee());
Darakbang darakbang = darakbangRepository.save(DarakbangFixture.getDarakbangWithWooteco());
DarakbangMember darakbangHogee = darakbangMemberRepository.save(
DarakbangMemberFixture.getDarakbangMemberWithWooteco(darakbang, hogee));

assertThatThrownBy(() -> darakbangMemberService.findAllDarakbangMembers(darakbang.getId(), darakbangHogee))
.isInstanceOf(DarakbangMemberException.class);
}
}

@DisplayName("다락방 멤버 권한 조회 테스트")
@Nested
class DarakbangMemberRoleReadTest {
Expand All @@ -70,4 +56,29 @@ void success() {
assertThat(response.role()).isEqualTo("OUTSIDER");
}
}

@DisplayName("다락방 멤버 조회 테스트")
@Nested
class DarakbangMemberReadTest {

@DisplayName("모든 다락방 멤버는 다락방 멤버 목록을 조회할 수 있다.")
@EnumSource(mode = EnumSource.Mode.INCLUDE, names = {"MANAGER", "MEMBER"})
@ParameterizedTest
void failToReadWithoutDarakbangManager(DarakBangMemberRole darakBangMemberRole) {
Member hogee = memberRepository.save(MemberFixture.getHogee());
Darakbang darakbang = darakbangRepository.save(DarakbangFixture.getDarakbangWithWooteco());
DarakbangMember darakbangMember = DarakbangMember.builder()
.darakbang(darakbang)
.memberId(hogee.getId())
.nickname("소소파파")
.role(darakBangMemberRole)
.build();
DarakbangMember darakbangHogee = darakbangMemberRepository.save(darakbangMember);

DarakbangMemberResponses responses = darakbangMemberService.findAllDarakbangMembers(
darakbang.getId(), darakbangHogee);

assertThat(responses.responses()).hasSize(1);
}
}
}