Skip to content

Commit

Permalink
fix: 종료미션의 경우 재촉하기 불가능하도록 검증 추가 (#333)
Browse files Browse the repository at this point in the history
* fix: 종료 미션에 재촉하기 불가능 하도록 검증 추가

* test: 종료미션 재촉하기 검증 테스트 코드 추가

* style: spotless
  • Loading branch information
kdomo authored Feb 15, 2024
1 parent bece899 commit f5bc8da
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,13 @@ record ->
.findFirst()
.isPresent();
}

public boolean isFinished() {
if (this.getDurationStatus() == DurationStatus.FINISHED
|| this.archiveStatus == ArchiveStatus.ARCHIVED
|| this.getFinishedAt().isBefore(LocalDateTime.now())) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void sendUrgingPush(PushUrgingSendRequest request) {
final Member targetMember = mission.getMember();

validateSelfSending(currentMember.getId(), targetMember.getId());
validateFinishedMission(mission);
validateMissionNotCompletedToday(mission);

fcmService.sendMessageSync(
Expand All @@ -50,6 +51,12 @@ public void sendUrgingPush(PushUrgingSendRequest request) {
notificationRepository.save(notification);
}

private void validateFinishedMission(Mission mission) {
if (mission.isFinished()) {
throw new CustomException(ErrorCode.FINISHED_MISSION_URGING_NOT_ALLOWED);
}
}

private void validateMissionNotCompletedToday(Mission mission) {
if (mission.isCompletedMissionToday()) {
throw new CustomException(ErrorCode.TODAY_COMPLETED_MISSION_SENDING_NOT_ALLOWED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum ErrorCode {
SELF_SENDING_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "본인에게 메세지를 전송할 수 없습니다."),
TODAY_COMPLETED_MISSION_SENDING_NOT_ALLOWED(
HttpStatus.BAD_REQUEST, "오늘 미션을 완료한 미션에는 메세지를 전송할 수 없습니다."),
FINISHED_MISSION_URGING_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "종료된 미션에는 재촉하기를 할 수 없습니다."),

// Reaction
REACTION_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 리액션을 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class 친구에게_미션을_재촉할_때 {
void 본인에게_재촉할_경우_예외를_발생시킨다() {
// given
PushUrgingSendRequest request = new PushUrgingSendRequest(1L);

// when, then
Member currentMember =
memberRepository.save(
Member.createNormalMember(
Expand All @@ -124,6 +122,38 @@ class 친구에게_미션을_재촉할_때 {
.hasMessage(ErrorCode.SELF_SENDING_NOT_ALLOWED.getMessage());
}

@Test
void 종료된_미션을_재촉할_경우_예외를_발생시킨다() {
// given
PushUrgingSendRequest request = new PushUrgingSendRequest(1L);
Member currentMember =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("testNickname1", "testImageUrl1")));
Member targetMember =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("testNickname2", "testImageUrl2")));
LocalDateTime today = LocalDateTime.now();
LocalDateTime missionStartedAt = today.minusWeeks(3);
LocalDateTime missionFinishedAt = missionStartedAt.plusWeeks(2);
missionRepository.save(
Mission.createMission(
"testMissionName",
"testMissionContent",
1,
MissionCategory.ETC,
MissionVisibility.ALL,
missionStartedAt,
missionFinishedAt,
targetMember));

// when, then
assertThatThrownBy(() -> pushService.sendUrgingPush(request))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.FINISHED_MISSION_URGING_NOT_ALLOWED.getMessage());
}

@Test
void 미션이_당일_완료된_경우_예외를_발생시킨다() {
// given
Expand Down

0 comments on commit f5bc8da

Please sign in to comment.