From bf48c691fa428adb3667a8115faf4cfc1d402e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=85=B8=EA=B2=BD=EB=AF=BC?= Date: Wed, 15 Feb 2023 21:37:43 +0900 Subject: [PATCH] =?UTF-8?q?test=20:=20=ED=98=B8=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=20(#356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test : 호스트 테스트 최적화 * test : 호스트 유저 테스트 작성 * test : HostRole 테스트 작성 * test : Host vo 테스트 수정 --- .../gosrock/domain/common/vo/HostInfoVo.java | 4 +- .../domain/common/vo/HostProfileVo.java | 2 + .../domain/domains/host/domain/Host.java | 28 +++------- .../domain/domains/host/domain/HostUser.java | 6 ++- .../domains/host/domain/HostProfileTest.java | 42 +++++++++++++++ .../domains/host/domain/HostRoleTest.java | 24 +++++++++ .../domain/domains/host/domain/HostTest.java | 13 +++++ .../domains/host/domain/HostUserTest.java | 54 +++++++++++++++++++ 8 files changed, 150 insertions(+), 23 deletions(-) create mode 100644 DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostProfileTest.java create mode 100644 DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostRoleTest.java create mode 100644 DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostUserTest.java diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostInfoVo.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostInfoVo.java index 949efb09..053a64bf 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostInfoVo.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostInfoVo.java @@ -3,9 +3,11 @@ import band.gosrock.domain.domains.host.domain.Host; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; @Getter +@EqualsAndHashCode @Builder public class HostInfoVo { private final Long hostId; @@ -20,7 +22,7 @@ public class HostInfoVo { private final String contactNumber; - private final boolean partner; + private final Boolean partner; public static HostInfoVo from(Host host) { return HostInfoVo.builder() diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostProfileVo.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostProfileVo.java index 36eacd46..6b09f0e5 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostProfileVo.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostProfileVo.java @@ -3,9 +3,11 @@ import band.gosrock.domain.domains.host.domain.Host; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; @Getter +@EqualsAndHashCode @Builder public class HostProfileVo { private final Long hostId; diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/Host.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/Host.java index f8a74be3..74c441cd 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/Host.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/Host.java @@ -1,5 +1,7 @@ package band.gosrock.domain.domains.host.domain; +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; import band.gosrock.domain.common.aop.domainEvent.Events; import band.gosrock.domain.common.events.host.HostRegisterSlackEvent; @@ -33,7 +35,7 @@ public class Host extends BaseTimeEntity { // 파트너 여부 // 정책상 초기값 false 로 고정입니다 - private final Boolean partner = false; + private final Boolean partner = FALSE; // 슬랙 웹훅 url private String slackUrl; @@ -68,11 +70,6 @@ public HostUser getHostUserByUserId(Long userId) { .orElseThrow(() -> HostUserNotFoundException.EXCEPTION); } - public String getSlackToken() { - if (this.slackUrl == null) return null; - return this.slackUrl.substring(this.slackUrl.indexOf("https://hooks.slack.com/services/")); - } - public void updateProfile(HostProfile hostProfile) { this.profile.updateProfile(hostProfile); } @@ -100,9 +97,8 @@ public Boolean isActiveHostUserId(Long userId) { public void setHostUserRole(Long userId, HostRole role) { // 마스터의 역할은 수정할 수 없음 - if (this.getMasterUserId().equals(userId)) { + if (this.getMasterUserId().equals(userId)) throw CannotModifyMasterHostRoleException.EXCEPTION; - } this.hostUsers.stream() .filter(hostUser -> hostUser.getUserId().equals(userId)) .findFirst() @@ -125,17 +121,13 @@ public void validateHostUserExistence(HostUser hostUser) { /** 해당 유저가 호스트에 속하는지 확인하는 검증 로직입니다 */ public void validateHostUser(Long userId) { - if (!this.hasHostUserId(userId)) { - throw ForbiddenHostException.EXCEPTION; - } + if (!this.hasHostUserId(userId)) throw ForbiddenHostException.EXCEPTION; } /** 해당 유저가 호스트에 속하며 가입 승인을 완료했는지 (활성상태) 확인하는 검증 로직입니다 */ public void validateActiveHostUser(Long userId) { this.validateHostUser(userId); - if (!this.isActiveHostUserId(userId)) { - throw NotAcceptedHostException.EXCEPTION; - } + if (!this.isActiveHostUserId(userId)) throw NotAcceptedHostException.EXCEPTION; } /** 해당 유저가 매니저 이상인지 확인하는 검증 로직입니다 */ @@ -149,16 +141,12 @@ public void validateManagerHostUser(Long userId) { /** 해당 유저가 호스트의 마스터(담당자, 방장)인지 확인하는 검증 로직입니다 */ public void validateMasterHostUser(Long userId) { this.validateActiveHostUser(userId); - if (!this.getMasterUserId().equals(userId)) { - throw NotMasterHostException.EXCEPTION; - } + if (!this.getMasterUserId().equals(userId)) throw NotMasterHostException.EXCEPTION; } /** 해당 호스트가 파트너 인지 검증합니다. */ public void validatePartnerHost() { - if (!partner) { - throw NotPartnerHostException.EXCEPTION; - } + if (partner != TRUE) throw NotPartnerHostException.EXCEPTION; } public HostInfoVo toHostInfoVo() { diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/HostUser.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/HostUser.java index eae71b81..81c4736f 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/HostUser.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/HostUser.java @@ -1,5 +1,7 @@ package band.gosrock.domain.domains.host.domain; +import static band.gosrock.domain.domains.host.domain.HostRole.GUEST; +import static java.lang.Boolean.FALSE; import band.gosrock.domain.common.aop.domainEvent.Events; import band.gosrock.domain.common.events.host.HostUserJoinEvent; @@ -32,11 +34,11 @@ public class HostUser extends BaseTimeEntity { private Long userId; // 초대 승락 여부 - private Boolean active = false; + private Boolean active = FALSE; // 유저의 권한 @Enumerated(EnumType.STRING) - private HostRole role = HostRole.GUEST; + private HostRole role = GUEST; public void setHostRole(HostRole role) { this.role = role; diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostProfileTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostProfileTest.java new file mode 100644 index 00000000..9068b625 --- /dev/null +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostProfileTest.java @@ -0,0 +1,42 @@ +package band.gosrock.domain.domains.host.domain; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class HostProfileTest { + + @Mock Host host; + + HostProfile hostProfile; + + @BeforeEach + void setup() { + hostProfile = HostProfile.builder().build(); + } + + @Test + void 호스트_프로필_업데이트_테스트() { + // given + final HostProfile newHostProfile = + HostProfile.builder() + .name("테스트") + .contactEmail("22@cc.com") + .contactNumber("010-0000-0000") + .introduce("123") + .profileImageKey("key") + .build(); + // when + hostProfile.updateProfile(newHostProfile); + // then + assertEquals(hostProfile.getProfileImage(), newHostProfile.getProfileImage()); + assertEquals(hostProfile.getContactEmail(), newHostProfile.getContactEmail()); + assertEquals(hostProfile.getContactNumber(), newHostProfile.getContactNumber()); + assertEquals(hostProfile.getIntroduce(), newHostProfile.getIntroduce()); + } +} diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostRoleTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostRoleTest.java new file mode 100644 index 00000000..16fd575d --- /dev/null +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostRoleTest.java @@ -0,0 +1,24 @@ +package band.gosrock.domain.domains.host.domain; + +import static band.gosrock.domain.domains.host.domain.HostRole.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class HostRoleTest { + + @Test + void ENUM_값에_해당하지_않으면_NULL_반환해야한다() { + // given + // when + // then + assertEquals(HostRole.fromHostRole("MASTER"), MASTER); + assertEquals(HostRole.fromHostRole("MANAGER"), MANAGER); + assertEquals(HostRole.fromHostRole("GUEST"), GUEST); + assertNull(HostRole.fromHostRole("NOT_PROVIDED")); + } +} diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostTest.java index 82b1c7fb..d481000d 100644 --- a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostTest.java +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostTest.java @@ -4,6 +4,8 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; +import band.gosrock.domain.common.vo.HostInfoVo; +import band.gosrock.domain.common.vo.HostProfileVo; import band.gosrock.domain.domains.host.exception.*; import java.util.Set; import org.junit.jupiter.api.BeforeEach; @@ -19,6 +21,8 @@ public class HostTest { @Mock HostUser managerHostUser; @Mock HostUser guestHostUser; @Mock HostProfile hostProfile; + @Mock HostInfoVo hostInfoVo; + @Mock HostProfileVo hostProfileVo; Host host; final Long masterUserId = 1L; @@ -302,4 +306,13 @@ void setup() { assertThrows(NotPartnerHostException.class, () -> host.validatePartnerHost()); assertDoesNotThrow(partnerHost::validatePartnerHost); } + + @Test + public void 호스트_vo_변환_테스트() { + // given + // when + // then + assertEquals(host.toHostInfoVo(), HostInfoVo.from(host)); + assertEquals(host.toHostProfileVo(), HostProfileVo.from(host)); + } } diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostUserTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostUserTest.java new file mode 100644 index 00000000..e98382b2 --- /dev/null +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/host/domain/HostUserTest.java @@ -0,0 +1,54 @@ +package band.gosrock.domain.domains.host.domain; + +import static band.gosrock.domain.domains.host.domain.HostRole.MANAGER; +import static band.gosrock.domain.domains.host.domain.HostRole.MASTER; +import static java.lang.Boolean.TRUE; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import band.gosrock.domain.domains.host.exception.AlreadyJoinedHostException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class HostUserTest { + + @Mock Host host; + HostUser hostUser; + + @BeforeEach + void setup() { + hostUser = HostUser.builder().host(host).role(MASTER).build(); + } + + @Test + void 호스트유저_권한변경_테스트() { + // given + final HostRole role = MANAGER; + // when + hostUser.setHostRole(role); + // then + assertEquals(hostUser.getRole(), role); + } + + @Test + void 호스트유저_초대수락으로_활성화_테스트() { + // given + // when + hostUser.activate(); + // then + assertEquals(hostUser.getActive(), TRUE); + } + + @Test + void 호스트유저_초대_중복수락은_불가능하다() { + // given + // when + hostUser.activate(); + // then + assertThrows(AlreadyJoinedHostException.class, () -> hostUser.activate()); + } +}