Skip to content

Commit

Permalink
fix: 인증 마감 경고 시간 검증 추가 (#105)
Browse files Browse the repository at this point in the history
* fix: 인증 마감 경고 시간 검증

* test: isVerificationWarningTime 검증
  • Loading branch information
kimyu0218 authored Dec 3, 2024
1 parent 3be2804 commit 1fda708
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

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

Expand Down Expand Up @@ -109,7 +110,7 @@ public void sendVerificationPushMessage() {
List<Mission> missions = missionRepository.getInProgressMissions();

missions.forEach(mission -> {
if (mission.isMissionDay() && mission.isPushTime(hour)) {
if (mission.isMissionDay() && mission.isVerificationStatusPushTime(hour)) {
List<MissionVerification> verifications = missionVerificationRepository.findAllByMissionIdAndDate(mission.getId(), today);
int verificationCount = verifications.size();

Expand Down Expand Up @@ -145,11 +146,11 @@ private void sendNoOneVerifiedPushMessage(final PushMessage message, final Long
@Transactional
public void sendVerificationWarningPushMessage() {
LocalDate today = LocalDate.now();
int hour = LocalDateTime.now().getHour();
LocalTime time = LocalTime.now();
List<Mission> missions = missionRepository.getInProgressMissions();

missions.forEach(mission -> {
if (mission.isMissionDay()) {
if (mission.isMissionDay() && mission.isVerificationWarningPushTime(time)) {
List<MissionMember> missionMembers = missionMemberRepository.findAllByMissionId(mission.getId());

missionMembers.forEach(missionMember -> {
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/nexters/goalpanzi/domain/mission/Mission.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,27 @@ public boolean isReadyTime(final LocalDateTime now) {
}

/**
* <b>현재 시간이 푸시 시간인지 검증</b> <br>
* <b>현재 시간이 미션 인증 경고 시간인지 검증</b> <br>
* 미션 인증 경고 시간 == 미션 인증 마감 1시간 전
*
* @param now 현재 시각
* @return 미션 인증 경고 시간 여부
*/
public boolean isVerificationWarningPushTime(final LocalTime now) {
Duration duration = Duration.between(now, TimeUtil.of(uploadEndTime));

return duration.isPositive() && duration.toHours() <= 1;
}

/**
* <b>현재 시간이 인증 현황 안내 시간인지 검증</b> <br>
* 1. 인증 시간이 오전인 경우, 09시에 푸시 <br>
* 2. 인증 시간이 오후이거나 종일인 경우, 15시에 푸시
*
* @param hour 현재 시각의 시간
* @return 미션 인증 푸시 시간 여부
* @return 미션 인증 현황 안내 시간 여부
*/
public boolean isPushTime(final int hour) {
public boolean isVerificationStatusPushTime(final int hour) {
if (uploadStartTime.equals(TimeOfDay.MORNING.getStartTime()) && uploadEndTime.equals(TimeOfDay.MORNING.getEndTime())) {
return hour == PushTime.MORNING.getHour();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.test.context.ContextConfiguration;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -73,7 +74,7 @@ class MissionVerificationServiceTest {

when(mockMission.getId()).thenReturn(MISSION_ID);
when(mockMission.isMissionDay()).thenReturn(true);
when(mockMission.isPushTime(anyInt())).thenReturn(true);
when(mockMission.isVerificationStatusPushTime(anyInt())).thenReturn(true);

when(missionRepository.getInProgressMissions()).thenReturn(List.of(mockMission));
when(missionVerificationRepository.findAllByMissionIdAndDate(MISSION_ID, LocalDate.now())).thenReturn(verifications);
Expand All @@ -94,7 +95,7 @@ class MissionVerificationServiceTest {

when(mockMission.getId()).thenReturn(MISSION_ID);
when(mockMission.isMissionDay()).thenReturn(true);
when(mockMission.isPushTime(anyInt())).thenReturn(true);
when(mockMission.isVerificationStatusPushTime(anyInt())).thenReturn(true);

when(missionRepository.getInProgressMissions()).thenReturn(List.of(mockMission));
when(missionVerificationRepository.findAllByMissionIdAndDate(MISSION_ID, LocalDate.now())).thenReturn(List.of());
Expand All @@ -110,7 +111,7 @@ class MissionVerificationServiceTest {
}

@Test
void 미션을_인증하지_않은_경우_MISSION_VERIFICATION_WARNING_푸시_알림을_보낸다() {
void 미션을_인증하지_않았고_인증_마감_경고_시간인_경우_MISSION_VERIFICATION_WARNING_푸시_알림을_보낸다() {
Long MEMBER_ID = 2L;
Mission mockMission = mock(Mission.class);
MissionMember mockMissionMember = mock(MissionMember.class);
Expand All @@ -119,6 +120,7 @@ class MissionVerificationServiceTest {

when(mockMission.getId()).thenReturn(MISSION_ID);
when(mockMission.isMissionDay()).thenReturn(true);
when(mockMission.isVerificationWarningPushTime(any(LocalTime.class))).thenReturn(true);

when(mockMissionMember.getMember()).thenReturn(mockMember);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.nexters.goalpanzi.domain.mission;

import com.nexters.goalpanzi.common.time.TimeUtil;
import org.junit.jupiter.api.Test;

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

import static com.nexters.goalpanzi.fixture.MemberFixture.MEMBER_ID;
Expand Down Expand Up @@ -154,7 +156,7 @@ class MissionTest {
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isPushTime(9)).isTrue();
assertThat(mission.isVerificationStatusPushTime(9)).isTrue();
}

@Test
Expand All @@ -169,7 +171,7 @@ class MissionTest {
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isPushTime(15)).isTrue();
assertThat(mission.isVerificationStatusPushTime(15)).isTrue();
}

@Test
Expand All @@ -184,7 +186,7 @@ class MissionTest {
BOARD_COUNT,
InvitationCode.generate()
);
assertThat(mission.isPushTime(15)).isTrue();
assertThat(mission.isVerificationStatusPushTime(15)).isTrue();
}

@Test
Expand All @@ -206,4 +208,25 @@ class MissionTest {
() -> assertThat(mission.isReadyTime(mission.getMissionUploadStartDateTime().minusMinutes(30))).isTrue()
);
}

@Test
void 미션_인증_마감까지_1시간_덜_남은_경우_미션_인증_경고_시간이다() {
LocalDateTime now = LocalDateTime.now();
Mission mission = Mission.create(
MEMBER_ID,
DESCRIPTION,
now,
now.plusDays(30),
TimeOfDay.EVERYDAY,
List.of(DayOfWeek.FRIDAY),
BOARD_COUNT,
InvitationCode.generate()
);
LocalTime uploadEndTime = TimeUtil.of(mission.getUploadEndTime());

assertAll(
() -> assertThat(mission.isVerificationWarningPushTime(uploadEndTime.minusHours(1))).isTrue(),
() -> assertThat(mission.isVerificationWarningPushTime(uploadEndTime.minusMinutes(30))).isTrue()
);
}
}

0 comments on commit 1fda708

Please sign in to comment.