Skip to content

Commit

Permalink
test: 미션 도메인 메서드 단위 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyu0218 committed Nov 11, 2024
1 parent abb1a66 commit f94282a
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ public boolean isReadyTime() {
// 1. 인증 시간이 오전인 경우, 09시에 푸시
// 2. 인증 시간이 오후이거나 종일인 경우, 15시에 푸시
public boolean isPushTime(final int hour) {
if (this.uploadStartTime.equals(TimeOfDay.MORNING.getStartTime())) {
if (this.uploadStartTime.equals(TimeOfDay.MORNING.getStartTime()) && this.uploadEndTime.equals(TimeOfDay.MORNING.getEndTime())) {
return hour == PushTime.MORNING.getHour();
}
if (this.uploadStartTime.equals(TimeOfDay.AFTERNOON.getStartTime())) {
if (this.uploadStartTime.equals(TimeOfDay.AFTERNOON.getStartTime()) && this.uploadEndTime.equals(TimeOfDay.AFTERNOON.getEndTime())) {
return hour == PushTime.AFTERNOON.getHour();
}
return hour == PushTime.EVERYDAY.getHour();
Expand Down
114 changes: 112 additions & 2 deletions src/test/java/com/nexters/goalpanzi/domain/mission/MissionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import static com.nexters.goalpanzi.fixture.MemberFixture.MEMBER_ID;
import static com.nexters.goalpanzi.fixture.MissionFixture.BOARD_COUNT;
import static com.nexters.goalpanzi.fixture.MissionFixture.DESCRIPTION;
import static com.nexters.goalpanzi.fixture.MissionFixture.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -76,4 +76,114 @@ class MissionTest {
);
assertThat(mission.isExpired()).isTrue();
}

@Test
void 오늘이_미션_인증_요일이면_true를_반환한다() {
Mission mission = Mission.create(
MEMBER_ID,
DESCRIPTION,
LocalDateTime.now(),
LocalDateTime.now().plusDays(30),
TimeOfDay.EVERYDAY,
WEEK,
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isMissionDay()).isTrue();
}

@Test
void 오늘이_미션_인증_요일이_아니면_false를_반환한다() {
List<DayOfWeek> missionDays = WEEK.stream()
.filter(d -> d != DayOfWeek.valueOf(LocalDate.now().getDayOfWeek().name())).toList();

Mission mission = Mission.create(
MEMBER_ID,
DESCRIPTION,
LocalDateTime.now(),
LocalDateTime.now().plusDays(30),
TimeOfDay.EVERYDAY,
missionDays,
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isMissionDay()).isFalse();
}

@Test
void 현재_시간이_미션_인증_시간이면_true를_반환한다() {
Mission mission = Mission.create(
MEMBER_ID,
DESCRIPTION,
LocalDateTime.now(),
LocalDateTime.now().plusDays(30),
TimeOfDay.EVERYDAY,
List.of(DayOfWeek.FRIDAY),
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isMissionTime()).isTrue();
}

@Test
void 현재_시간이_미션_인증_시간이_아니면_false를_반환한다() {
TimeOfDay timeOfDay = (LocalDateTime.now().getHour() < 12) ? TimeOfDay.AFTERNOON : TimeOfDay.MORNING;

Mission mission = Mission.create(
MEMBER_ID,
DESCRIPTION,
LocalDateTime.now(),
LocalDateTime.now().plusDays(30),
timeOfDay,
List.of(DayOfWeek.FRIDAY),
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isMissionTime()).isFalse();
}

@Test
void 인증_시간이_오전인_미션은_푸시_알림_시간이_09시이다() {
Mission mission = Mission.create(
MEMBER_ID,
DESCRIPTION,
LocalDateTime.now(),
LocalDateTime.now().plusDays(30),
TimeOfDay.MORNING,
List.of(DayOfWeek.FRIDAY),
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isPushTime(9)).isTrue();
}

@Test
void 인증_시간이_오후인_미션은_푸시_알림_시간이_15시이다() {
Mission mission = Mission.create(
MEMBER_ID,
DESCRIPTION,
LocalDateTime.now(),
LocalDateTime.now().plusDays(30),
TimeOfDay.AFTERNOON,
List.of(DayOfWeek.FRIDAY),
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isPushTime(15)).isTrue();
}

@Test
void 인증_시간이_종일인_미션은_푸시_알림_시간이_15시이다() {
Mission mission = Mission.create(
MEMBER_ID,
DESCRIPTION,
LocalDateTime.now(),
LocalDateTime.now().plusDays(30),
TimeOfDay.EVERYDAY,
List.of(DayOfWeek.FRIDAY),
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isPushTime(15)).isTrue();
}
}

0 comments on commit f94282a

Please sign in to comment.