Skip to content

Commit 0c433ba

Browse files
committed
Stabilize schedule lifecycle CI tests
1 parent 53e2ee2 commit 0c433ba

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

ontime-back/src/main/java/devkor/ontime_back/service/ScheduleService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.time.Instant;
1313
import java.time.Duration;
1414
import java.time.LocalDateTime;
15+
import java.time.temporal.ChronoUnit;
1516
import java.util.HashMap;
1617
import java.util.List;
1718
import java.util.Map;
@@ -184,7 +185,7 @@ public StartScheduleResponseDto startSchedule(Long userId, UUID scheduleId) {
184185
assertScheduleNotFinished(schedule);
185186

186187
if (schedule.getStartedAt() == null) {
187-
schedule.startSchedule(Instant.now());
188+
schedule.startSchedule(nowForPersistence());
188189
freezePreparationSnapshotIfNeeded(schedule);
189190
scheduleRepository.save(schedule);
190191
}
@@ -277,7 +278,7 @@ public List<LatenessHistoryResponse> getLatenessHistory(Long userId) {
277278
// 지각 시간 업데이트
278279
@Transactional
279280
public void updateLatenessTime(Schedule schedule, Integer latenessTime) {
280-
schedule.finish(latenessTime, Instant.now());
281+
schedule.finish(latenessTime, nowForPersistence());
281282
scheduleRepository.save(schedule);
282283
}
283284

@@ -300,7 +301,7 @@ public void finishSchedule(Long userId, UUID scheduleId, FinishPreparationDto fi
300301
throw new GeneralException(SCHEDULE_NOT_STARTED);
301302
}
302303

303-
schedule.finish(finishPreparationDto.getLatenessTime(), Instant.now());
304+
schedule.finish(finishPreparationDto.getLatenessTime(), nowForPersistence());
304305
scheduleRepository.save(schedule);
305306
userService.updatePunctualityScore(userId, schedule.getDoneStatus());
306307
}
@@ -437,4 +438,8 @@ private Integer defaultNonNegative(Integer value) {
437438
return value == null ? 0 : Math.max(value, 0);
438439
}
439440

441+
private Instant nowForPersistence() {
442+
return Instant.now().truncatedTo(ChronoUnit.SECONDS);
443+
}
444+
440445
}

ontime-back/src/test/java/devkor/ontime_back/service/UserServiceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
2121
import static org.assertj.core.api.Assertions.assertThatThrownBy;
22+
import static org.assertj.core.data.Offset.offset;
2223
import static org.junit.jupiter.api.Assertions.*;
2324
import static org.mockito.ArgumentMatchers.any;
2425
import static org.mockito.Mockito.when;
@@ -265,9 +266,10 @@ void updatePunctualityWithAbnormalDoesNotCount(){
265266

266267
User updatedUser = userService.updatePunctualityScore(addedUser.getId(), DoneStatus.ABNORMAL);
267268

269+
assertThat(updatedUser.getPunctualityScore()).isCloseTo(calculatePunctualityScore(3, 1), offset(0.0001f));
268270
assertThat(updatedUser)
269-
.extracting("punctualityScore", "scheduleCountAfterReset", "latenessCountAfterReset")
270-
.contains(calculatePunctualityScore(3, 1), 3, 1);
271+
.extracting("scheduleCountAfterReset", "latenessCountAfterReset")
272+
.contains(3, 1);
271273
}
272274

273275
@DisplayName("성실도 점수 업데이트할 때 존재하지 않는 유저id를 인자로 넘기는 경우 예외가 발생한다.")

0 commit comments

Comments
 (0)