Skip to content

Commit

Permalink
Merge pull request #106 from Cafegory/feature-105
Browse files Browse the repository at this point in the history
[BUILD SUCCESS] 카공 생성, 수정할때 최대인원 0명이 가능한 오류 수정
  • Loading branch information
donghyun0304 authored May 18, 2024
2 parents 78d8bba + 5131d17 commit 253d47d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/example/demo/domain/study/StudyOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
public class StudyOnce {

private static final int LIMIT_MEMBER_CAPACITY = 5;
private static final int MIN_LIMIT_MEMBER_CAPACITY = 1;

@Id
@GeneratedValue
Expand Down Expand Up @@ -110,7 +111,7 @@ private static void validateStudyOnceTime(LocalDateTime startDateTime, LocalDate
}

private void validateMaxMemberCount(int maxMemberCount) {
if (maxMemberCount > LIMIT_MEMBER_CAPACITY) {
if (maxMemberCount > LIMIT_MEMBER_CAPACITY || maxMemberCount < MIN_LIMIT_MEMBER_CAPACITY) {
throw new CafegoryException(STUDY_ONCE_LIMIT_MEMBER_CAPACITY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum ExceptionType {
STUDY_ONCE_SHORT_DURATION(BAD_REQUEST, "카공 시간은 1시간 이상이어야 합니다."),
STUDY_ONCE_LONG_DURATION(BAD_REQUEST, "카공 시간은 5시간 미만이어야 합니다."),
STUDY_ONCE_TOO_MUCH_STUDY_IN_CAFE(BAD_REQUEST, "이 카페에 이 인원의 카공을 더이상 생성할 수 없습니다."),
STUDY_ONCE_LIMIT_MEMBER_CAPACITY(BAD_REQUEST, "카공 최대 참여 인원 수는 5명 입니다."),
STUDY_ONCE_LIMIT_MEMBER_CAPACITY(BAD_REQUEST, "카공 최대 참여 인원 수는 1명 이상 5명 이하 입니다."),
STUDY_ONCE_CANNOT_REDUCE_BELOW_CURRENT(BAD_REQUEST, "카공 최대 참여 인원 수는 현재 참여 신청중인 인원보다 적을 수 없습니다."),
STUDY_ONCE_CONFLICT_TIME(CONFLICT, "해당 시간에 참여중인 카공이 이미 있습니다."),
STUDY_ONCE_DUPLICATE(CONFLICT, "이미 참여중인 카공입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private StudyOnce makeStudyOnce(String name, LocalDateTime start, LocalDateTime
.endDateTime(end)
.leader(new TestMemberBuilder().build())
.openChatUrl(openChatUrl)
.maxMemberCount(5)
.build();
}

Expand Down
24 changes: 23 additions & 1 deletion src/test/java/com/example/demo/domain/study/StudyOnceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void canJoin(LocalDateTime base, LocalDateTime start, boolean expected) {
.endDateTime(start.plusHours(4))
.leader(Member.builder().build())
.openChatUrl("오픈채팅방 링크")
.maxMemberCount(5)
.build();

boolean canJoin = studyOnce.canJoin(base);
Expand All @@ -109,6 +110,7 @@ void create() {
.endDateTime(start.plusHours(4))
.leader(leader)
.openChatUrl("오픈채팅방 링크")
.maxMemberCount(5)
.build();

StudyOnce study = studyOnce.getStudyMembers().get(0).getStudy();
Expand Down Expand Up @@ -309,10 +311,29 @@ void validate_maxMemberCount_by_changeMaxMemberCount() {
.hasMessage(STUDY_ONCE_LIMIT_MEMBER_CAPACITY.getErrorMessage());
}

@Test
@DisplayName("최소 참여인원은 1명이다. 0명이면 예외가 터진다.")
void validate_MemberCount_by_changeMaxMemberCount_then_exception() {
Member leader = Member.builder().id(LEADER_ID).build();
StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크");
assertThatThrownBy(() -> studyOnce.changeMaxMemberCount(0))
.isInstanceOf(CafegoryException.class)
.hasMessage(STUDY_ONCE_LIMIT_MEMBER_CAPACITY.getErrorMessage());
}

@Test
@DisplayName("최소 참여인원은 1명이다.")
void changeMaxMemberCount_by_one() {
Member leader = Member.builder().id(LEADER_ID).build();
StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크");
assertDoesNotThrow(() -> studyOnce.changeMaxMemberCount(1));
}

@Test
@DisplayName("최대 참여 인원보다 현재 참석예정인 인원이 크다면 예외가 터진다.")
void validate_maxOrNowMemberCount_by_changeMaxMemberCount() {
Member leader = Member.builder().id(LEADER_ID).build();
Member member = Member.builder().id(MEMBER_ID).build();
StudyOnce studyOnce = StudyOnce.builder()
.name("스터디 이름")
.startDateTime(NOW.plusHours(4))
Expand All @@ -322,8 +343,9 @@ void validate_maxOrNowMemberCount_by_changeMaxMemberCount() {
.leader(leader)
.openChatUrl("오픈채팅방 링크")
.build();
studyOnce.tryJoin(member, NOW);

assertThatThrownBy(() -> studyOnce.changeMaxMemberCount(0))
assertThatThrownBy(() -> studyOnce.changeMaxMemberCount(1))
.isInstanceOf(CafegoryException.class)
.hasMessage(STUDY_ONCE_CANNOT_REDUCE_BELOW_CURRENT.getErrorMessage());
}
Expand Down

0 comments on commit 253d47d

Please sign in to comment.